|
@@ -9,8 +9,97 @@ namespace AvaloniaApplicationBase.ViewModels
|
|
|
{
|
|
|
public class ShowCatsPageViewModel : ReactiveObject
|
|
|
{
|
|
|
+ CatBaseContext myConnection;
|
|
|
+ private List<CatTable> ct;
|
|
|
+
|
|
|
+ public ShowCatsPageViewModel(CatBaseContext myConnection)
|
|
|
+ {
|
|
|
+ this.myConnection = myConnection;
|
|
|
+ CT = myConnection.CatTables.Include(x => x.GenderNavigation).Include(x => x.TraitCatTables).ThenInclude(x => x.IdTraitNavigation).ToList();
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
// Include - äëÿ òàáëèö, íåïîñðåäñòâåííî ñâÿçàííûõ ñâÿçàííûõ äðóã ñ äðóãîì
|
|
|
// ThenInclude - äëÿ ïîñëåäîâàòëåüíîãî ñîåäèíåíèÿ òàáëèö, èçíà÷àëüíî äðóã ñ äðóãîì íå ñâÿçàííûìè (ïîäðîáíåå â ôàéëå â moodle)
|
|
|
- public List<CatTable> CT => MainWindowViewModel.myConnection.CatTables.Include(x => x.GenderNavigation).Include(x => x.TraitCatTables).ThenInclude(x => x.IdTraitNavigation).ToList();
|
|
|
+
|
|
|
+ public List<CatTable> CT { get => ct; set => this.RaiseAndSetIfChanged(ref ct,value); }
|
|
|
+
|
|
|
+ // ñîðòèðîâêà ïî èìåíè êîòà
|
|
|
+ public List<string> OrdersName => new List<string>() { "Ïî âîçðàñòàíèþ", "Ïî óáûâàíèþ" };
|
|
|
+
|
|
|
+ public string OrderByName
|
|
|
+ {
|
|
|
+ get => orderByName;
|
|
|
+ set
|
|
|
+ {
|
|
|
+ orderByName = value;
|
|
|
+ AllFilters();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ string orderByName = "Ïî âîçðàñòàíèþ";
|
|
|
+
|
|
|
+
|
|
|
+ // ôèëüòðàöèÿ ïî ïîëó
|
|
|
+ public List<string> GenderList
|
|
|
+ {
|
|
|
+ get
|
|
|
+ {
|
|
|
+ List<string> genders = new List<string>() { "ëþáîé" };
|
|
|
+ genders.AddRange(myConnection.GenderTables.Select(x => x.Gender).ToList());
|
|
|
+ return genders;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public string SelectedGender
|
|
|
+ {
|
|
|
+ get => selectedGender;
|
|
|
+ set
|
|
|
+ {
|
|
|
+ selectedGender = value;
|
|
|
+ AllFilters();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ string selectedGender = "ëþáîé";
|
|
|
+
|
|
|
+ // ïîèñê ïî èìåíè
|
|
|
+ string nameFind;
|
|
|
+ public string NameFind
|
|
|
+ {
|
|
|
+ get => nameFind;
|
|
|
+ set
|
|
|
+ {
|
|
|
+ nameFind = value;
|
|
|
+ AllFilters();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ void AllFilters()
|
|
|
+ {
|
|
|
+ CT = myConnection.CatTables.Include(x => x.GenderNavigation).Include(x => x.TraitCatTables).ThenInclude(x => x.IdTraitNavigation).ToList();
|
|
|
+ switch (orderByName)
|
|
|
+ {
|
|
|
+ case "Ïî âîçðàñòàíèþ":
|
|
|
+ CT = CT.OrderBy(x=>x.Name).ToList();
|
|
|
+ break;
|
|
|
+ case "Ïî óáûâàíèþ":
|
|
|
+ CT = CT.OrderByDescending(x=>x.Name).ToList();
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (selectedGender!="ëþáîé")
|
|
|
+ {
|
|
|
+ CT = CT.Where(x=>x.GenderNavigation.Gender==selectedGender).ToList();
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!string.IsNullOrWhiteSpace(nameFind))
|
|
|
+ {
|
|
|
+ CT = CT.Where(x=>x.Name.ToLower().Contains(nameFind.ToLower())).ToList();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
}
|