public void UpdateDogIds(Dog selectedDog) { if (DogIds.Contains(selectedDog.ID)) { RemoveDog(selectedDog); } else { AddDog(selectedDog); } }
public void AddDog(Dog selectedDog) { if (!DogIds.Contains(selectedDog.ID)) { DogIds = App.Database.AddDogToJakt(JaktId, selectedDog.ID); } if (CurrentLogg != null) { CurrentLogg.DogId = selectedDog.ID; App.Database.SaveLogg(CurrentLogg); } }
public void RemoveDog(Dog selectedDog) { selectedDog.Selected = false; if (CurrentLogg != null) { CurrentLogg.Dog = new Dog(); App.Database.SaveLogg(CurrentLogg); } if (DogIds.Contains(selectedDog.ID)) { DogIds = App.Database.RemoveDogFromJakt(JaktId, selectedDog.ID); } }
public void BindData() { GroupedItems.Clear(); Dogs = App.Database.GetDogs().ToList(); foreach (var dog in Dogs) { if (CurrentLogg != null) { dog.Selected = dog.ID == CurrentLogg.DogId; } else { dog.Selected = DogIds.Contains(dog.ID); } } var currentDogsHeader = "Dogs fra denne jakta"; var otherDogsHeader = "Flere dogs"; var allDogsHeader = "Velg dog"; var dogsInJakt = Dogs.Where(j => DogIds.Contains(j.ID)); if (dogsInJakt.Any()) { var dogsInJaktGroup = new DogSelectorGroup(currentDogsHeader, ""); dogsInJaktGroup.AddRange(dogsInJakt); GroupedItems.Add(dogsInJaktGroup); } var otherDogList = Dogs.Where(j => !DogIds.Contains(j.ID)); if (otherDogList.Any()) { var otherDogs = new DogSelectorGroup(dogsInJakt.Any() ? otherDogsHeader : allDogsHeader, ""); otherDogs.AddRange(otherDogList); GroupedItems.Add(otherDogs); } }