Skip to content

Commit e43db5c

Browse files
committed
finished stucturing codes for db implementation
1 parent 3a2e5e6 commit e43db5c

7 files changed

Lines changed: 136 additions & 73 deletions

File tree

CutCode/Controllers/CustomTextEditor.cs

Lines changed: 0 additions & 56 deletions
This file was deleted.

CutCode/DataBase/DBManager.cs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,48 @@ namespace CutCode
88
{
99
public class DBManager
1010
{
11+
public List<CodeBoxModel> AllCodes { get; set; }
12+
public DBManager()
13+
{
1114

15+
}
16+
17+
public static CodeBoxModel AddCode(string _title, string _desc, string _lang, string _code)
18+
{
19+
var _id = 0; // will be set later ...
20+
return new CodeBoxModel(_title, _desc, false, _lang);
21+
}
22+
23+
public static bool DelCode(CodeBoxModel code)
24+
{
25+
try
26+
{
27+
// delete the code from db here
28+
}
29+
catch
30+
{
31+
return false;
32+
}
33+
return true;
34+
}
35+
36+
public static List<CodeBoxModel> SearchCode(string searchText)
37+
{
38+
return new List<CodeBoxModel>();
39+
}
40+
41+
public static bool EditCode(CodeBoxModel newCode)
42+
{
43+
try
44+
{
45+
// edit it here
46+
}
47+
catch
48+
{
49+
return false;
50+
}
51+
52+
return true;
53+
}
1254
}
1355
}

CutCode/Models/CodeBoxModel.cs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,20 @@ namespace CutCode
99
{
1010
public class CodeBoxModel
1111
{
12-
public CodeBoxModel(string __title, string __desc, bool __isFav, string __langType, IThemeService _themeService)
12+
public CodeBoxModel(string __title, string __desc, bool __isFav, string __langType)
1313
{
1414
title = __title;
1515
desc = __desc;
1616
isFav = __isFav;
1717
langType = __langType;
18-
themeService = _themeService;
18+
// there are something to be changed in the initializer ...
1919
}
20-
20+
public int id { get; set; }
2121
public string title { get; set; }
22-
2322
public string desc { get; set; }
24-
2523
public bool isFav { get; set; }
26-
2724
public string langType { get; set; }
28-
public IThemeService themeService { get; set; }
25+
public string code { get; set; }
26+
public long created { get; set; }
2927
}
3028
}

CutCode/ViewModels/AddViewModel.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ public AddViewModel(IThemeService _themeService, IPageService _pageService)
2323

2424
AllLangs = new ObservableCollection<string>()
2525
{
26-
"Any languages", "Python", "C++", "C#", "CSS", "Dart", "Golang", "Html", "Java",
27-
"Javascript", "Kotlin", "Php", "C", "Ruby", "Rust","Sql", "Swift"
26+
"Any languages", "Python", "C++", "C#", "CSS", "Dart", "Golang", "Html", "Java",
27+
"Javascript", "Kotlin", "Php", "C", "Ruby", "Rust","Sql", "Swift"
2828
};
2929
leftText = "";
3030
CurrentLang = AllLangs[0];

CutCode/ViewModels/CodeViewModel.cs

Lines changed: 80 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,88 @@ namespace CutCode
1010
public class CodeViewModel : Screen
1111
{
1212
private readonly IThemeService themeService;
13-
public CodeViewModel(IThemeService _themeService)
13+
private readonly IPageService pageService;
14+
public CodeViewModel(IThemeService _themeService, IPageService _pageService, CodeBoxModel code)
1415
{
1516
themeService = _themeService;
17+
themeService.ThemeChanged += ThemeChanged;
18+
pageService = _pageService;
19+
20+
SetAppearance();
21+
22+
title = code.title;
23+
desc = code.desc;
24+
this.code = code.code;
25+
langType = code.langType;
26+
createdDate = "Will be changed later";
27+
}
28+
private void ThemeChanged(object sender, EventArgs e)
29+
{
30+
SetAppearance();
31+
}
32+
private void SetAppearance()
33+
{
34+
35+
}
36+
37+
private string _title;
38+
public string title
39+
{
40+
get => _title;
41+
set
42+
{
43+
SetAndNotify(ref _title, value);
44+
}
45+
}
46+
47+
private string _desc;
48+
public string desc
49+
{
50+
get => _desc;
51+
set
52+
{
53+
SetAndNotify(ref _desc, value);
54+
}
55+
}
56+
57+
private string _code;
58+
public string code
59+
{
60+
get => _code;
61+
set
62+
{
63+
SetAndNotify(ref _code, value);
64+
}
65+
}
66+
67+
private string _langType;
68+
public string langType
69+
{
70+
get => _langType;
71+
set
72+
{
73+
SetAndNotify(ref _langType, value);
74+
}
75+
}
76+
77+
private bool _isFav;
78+
public bool isFav
79+
{
80+
get => _isFav;
81+
set
82+
{
83+
SetAndNotify(ref _isFav, value);
84+
}
85+
}
86+
87+
private string _createdDate;
88+
public string createdDate
89+
{
90+
get => _createdDate;
91+
set
92+
{
93+
SetAndNotify(ref _createdDate, value);
94+
}
1695
}
1796
}
1897
}

CutCode/ViewModels/HomeViewModel.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,13 @@ public HomeViewModel(IThemeService _themeService, IPageService _pageService)
2424
SetAppearance();
2525
IsSearched = false;
2626

27+
var db = new DBManager();
28+
//AllCodes = db.AllCodes;
29+
2730
AllCodes = new ObservableCollection<CodeBoxModel>();
28-
var code1 = new CodeBoxModel("Pyqt5 scroll bar", "pyqt5 custom scroll bar made in python ok??", true, "python", themeService);
29-
var code2 = new CodeBoxModel("C++ binary search", "blah blah binary blah ... ye and ok \n so what??", false, "cpp", themeService);
30-
var code3 = new CodeBoxModel("wpf sample combo box", "combo box style that is responseive to the ui and also \n and ok ?? blah ... ", true, "csharp", themeService);
31+
var code1 = new CodeBoxModel("Pyqt5 scroll bar", "pyqt5 custom scroll bar made in python ok??", true, "python");
32+
var code2 = new CodeBoxModel("C++ binary search", "blah blah binary blah ... ye and ok \n so what??", false, "cpp");
33+
var code3 = new CodeBoxModel("wpf sample combo box", "combo box style that is responseive to the ui and also \n and ok ?? blah ... ", true, "csharp");
3134
AllCodes.Add(code1);
3235
AllCodes.Add(code2);
3336
AllCodes.Add(code3);

CutCode/ViewModels/MainViewModel.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,7 @@ private void ThemeChanged(object sender, EventArgs e)
6767
titlebarBtnsHoverColor = _themeService.IsLightTheme ? ColorCon.Convert("#D0D1D2") : ColorCon.Convert("#373737");
6868
}
6969

70-
private void PageChanged(object sender, EventArgs e)
71-
{
72-
currentPage = pageService.Page;
73-
}
70+
private void PageChanged(object sender, EventArgs e) => currentPage = pageService.Page;
7471

7572
private void PageRemoteChanged(object sender, EventArgs e)
7673
{

0 commit comments

Comments
 (0)