/// <summary> /// Adding new adoptive to database /// </summary> /// <param name="name">Adoptive's name</param> /// <param name="surname">Adoptive's surname</param> /// <param name="email">Adoptive's email</param> /// <param name="telephone">Adoptive's telephone</param> /// <param name="city">Adoptive's city</param> /// <param name="street">Adoptive's street</param> /// <param name="postalCode">Adoptive's postal code</param> /// <param name="houseNumber">Adoptive's house number</param> /// <param name="adoptedAnimals">Adoptive's adopted animals</param> /// <param name="flatNumber">Adoptive's flat number</param> /// <returns></returns> public Adoptive AddNewAdoptive(string name, string surname, string email, int telephone, string city, string street, string postalCode, int houseNumber, ICollection <Animal> adoptedAnimals, int?flatNumber = null) { if (Pet.Adoptives.Any(adoptive => adoptive.Email == email)) { throw new Exception("Ten email już jest wykorzystany!"); } Adoptive adoptive = new Adoptive() { Name = name, Surname = surname, Email = email, Telephone = telephone, City = city, Street = street, PostalCode = postalCode, HouseNumber = houseNumber, AdoptedAnimals = adoptedAnimals, FlatNumber = flatNumber }; return(Pet.Adoptives.Add(adoptive).Entity); }
/// <summary> /// Removing adoptive /// </summary> /// <param name="adoptive">Adoptive's object</param> public void RemoveAdoptive(Adoptive adoptive) { if (!Pet.Adoptives.Any(dbAdoptive => dbAdoptive.ID == adoptive.ID)) { throw new Exception("Taka osoba nie istnieje!"); } Pet.Adoptives.Remove(adoptive); }
/// <summary> /// Discard adoptive button click event - discards adoptive /// </summary> /// <param name="sender">Clicked button object</param> /// <param name="e">Event arguments</param> private void DiscardChoosenAdoptive_Click(object sender, RoutedEventArgs e) { IsAdoptedCheckbox.IsChecked = false; DiscardChoosenAdoptive.IsEnabled = false; Adoptive adoptive = new Adoptive(); Animal.Adoptive = adoptive; AdoptiveTab.DataContext = adoptive; AdoptivesComboBox.SelectedItem = null; }
/// <summary> /// Updating certain adoptive /// </summary> /// <param name="adoptive">Adoptive's object</param> public void UpdateAdoptive(Adoptive adoptive) { if (!Pet.Adoptives.Any(dbAdoptive => dbAdoptive.ID == adoptive.ID)) { throw new Exception("Taka osoba nie istnieje!"); } if (Pet.Adoptives.Any(dbAdoptive => dbAdoptive.Email == adoptive.Email)) { throw new Exception("Ten email już jest wykorzystany!"); } Pet.Adoptives.Update(adoptive); }
/// <summary> /// Returing adoptive's adopted animals collection /// </summary> /// <param name="adoptive">Adoptive's object</param> /// <returns>Collection of animals</returns> public IQueryable <Animal> GetAdoptiveAnimals(Adoptive adoptive) { return(Pet.Animals.Where(animal => animal.Adoptive.ID == adoptive.ID)); }
/// <summary> /// Adding new animal to database /// </summary> /// <param name="name">Animal's name</param> /// <param name="type">Animal's type (dog, cat, other)</param> /// <param name="birthDate">Animal's birth date</param> /// <param name="joinDate">Animal's join date</param> /// <param name="vaccinations">Animal's vaccinations</param> /// <param name="chip">Animal's chip</param> /// <param name="description">Animal's description</param> /// <param name="state">Animal's state description</param> /// <param name="treatments">Animal's treatments description</param> /// <param name="adoptive">Adoptive's object associated with animal (default null)</param> /// <param name="deathInfo">Death's object associated with animal (default null)</param> /// <param name="lostInfo">Lost information object's associated with animal (default null)</param> /// <returns></returns> public Animal AddNewAnimal(string name, AnimalType type, DateTime birthDate, DateTime joinDate, ICollection <Vaccination> vaccinations, string chip, string description, string state, string treatments, Adoptive adoptive = null, Death deathInfo = null, Lost lostInfo = null) { var now = DateTime.Now; if (birthDate > now) { throw new Exception("Data urodzenia jest z przyszłości!"); } if (joinDate > now) { throw new Exception("Data dołączenia jest z przyszłości!"); } if (chip.ToString().Length != 15) { throw new Exception("Numer chip nie składa się z 15 cyfr!"); } if (Pet.Animals.Any(animal => animal.Chip == chip)) { throw new Exception("Taki numer chip już istnieje w bazie!"); } if (deathInfo != null && deathInfo.Date > now) { throw new Exception("Data śmierci jest z przyszłości!"); } if (lostInfo != null && lostInfo.Date > now) { throw new Exception("Data utraty jest z przyszłości!"); } Animal animal = new Animal() { Name = name, Type = type, BirthDate = birthDate, JoinDate = joinDate, Vaccinations = vaccinations, Chip = chip, Description = description, State = state, Treatments = treatments, Adoptive = adoptive, DeathInfo = deathInfo, LostInfo = lostInfo }; Animal addedAnimal; using (var transaction = Pet.Database.BeginTransaction()) { try { addedAnimal = Pet.Animals.Add(animal).Entity; Pet.SaveChanges(); transaction.Commit(); } catch (Exception) { transaction.Rollback(); throw; } } return(addedAnimal); }