public Pet EditPet(Pet pet) { if (pet.PetType != null) { int index = _petRepository.GetPets().List.FindLastIndex(c => c.PetId == pet.PetId); if (index == -1) { return(null); } var petType = _petTypeRepository.GetPetTypes().List.FirstOrDefault(p => p.Id == pet.PetType.Id); if (petType == null) { throw new InvalidDataException("PetType must exist in the database"); } if (pet.Owner != null) { var owner = _ownerRepository.GetOwners().List.FirstOrDefault(o => o.Id == pet.Owner.Id); if (owner == null) { throw new InvalidDataException("Owner must exist in the database"); } } return(_petRepository.EditPet(pet, index)); } throw new InvalidDataException("PetType must exist in the database"); }
public Pet EditPet(int idOfPetToEdit, Pet editedPet) { if (!_petRepository.GetAllPets().Exists(x => x.ID == idOfPetToEdit)) { throw new KeyNotFoundException("A pet with this ID does not exist"); } else { return(_petRepository.EditPet(idOfPetToEdit, editedPet)); } }
public void EditPet(PetDetailsDto pd, int petId) { PetDetails pett = new PetDetails { Age = pd.Age, PetId = petId, ImagePath = pd.ImagePath, BreedType = pd.BreedType, PetName = pd.PetName, Price = pd.Price, TypeId = Convert.ToInt32(pd.PetType) }; transRepos.EditPet(pett); }
//should be changed public Pet EditPet(Pet editedPet) { var index = GetAllPets().FindIndex(pet => pet.PetId == editedPet.PetId); return(_petRepository.EditPet(index, editedPet)); //Pet petToChange = GetPetById(editedPet.PetId); //petToChange.Name = editedPet.Name; //petToChange.Type = editedPet.Type; //petToChange.BirthDate = editedPet.BirthDate; //petToChange.SoldDate = editedPet.SoldDate; //petToChange.Color = editedPet.Color; //petToChange.PreviousOwner = editedPet.PreviousOwner; //petToChange.Price = editedPet.Price; //return petToChange; }
public Pet EditPet(int id, string name, PetType type, DateTime birthdate, DateTime soldDate, string color, string previousOwner, double price) { if (!_petRepository.ReadPets().Exists(x => x.ID == id)) { throw new InvalidDataException("A pet with this ID does not exist"); } else { Pet petToEdit = new Pet { Name = name, Type = type, BirthDate = birthdate, SoldDate = soldDate, Color = color, PreviousOwner = previousOwner, Price = price }; return(_petRepository.EditPet(id, petToEdit)); } }
public Pet EditPet(int id, Pet editedPet) { //if (!_petRepository.GetAllPets().Exists(x => x.OwnerId == id)) //{ // throw new KeyNotFoundException("A pet with this ID does not exist"); //} if (editedPet.Equals(null)) { throw new InvalidDataException("Pet cannot be null"); } if (editedPet.Name.Length < 1) { throw new InvalidDataException("Pet name has to be longer than one"); } if (editedPet.PetId == 0) { throw new InvalidDataException("A new pet cannot have an id, that is only for already existing pets"); } if (editedPet.PetId != 0) { if (_petRepository.SearchById(editedPet.PetId) == null) { throw new InvalidDataException("edited pet has to be an existing pet"); } } if (editedPet.PetType == null) { throw new InvalidDataException("A pet has to have a petType"); } if (editedPet.PetType != null) { if (_petTypeRepository.SearchById(editedPet.PetType.PetTypeId) == null) { throw new InvalidDataException("The petType has to be an existing petType in the database"); } } //if (editedPet.PetType != null) //{ // var petType = _petTypeRepository.SearchByIdWithoutRelations(editedPet.PetType.OwnerId); // if (petType == null) // { // throw new InvalidDataException("The petType has to be an existing petType in the database"); // } // editedPet.PetType = petType; //} //else //{ // throw new InvalidDataException("Pet has to have a petType"); //} if (editedPet.Owner != null) { var owner = _ownerRepository.SearchByIdWithoutRelations(editedPet.Owner.OwnerId); if (owner == null) { throw new InvalidDataException("The owner has to be an existing owner in the database"); } } //Pet petToBeEdited = _petRepository.SearchByIdWithoutRelations(id); //petToBeEdited.Owner = editedPet.Owner; //petToBeEdited.PetType = editedPet.PetType; //petToBeEdited.BirthDate = editedPet.BirthDate; //petToBeEdited.SoldDate = editedPet.SoldDate; //petToBeEdited.Name = editedPet.Name; //petToBeEdited.Color = editedPet.Color; //petToBeEdited.Price = editedPet.Price; var successfullyEditedPet = _petRepository.EditPet(id, editedPet); if (successfullyEditedPet == null) { throw new DataBaseException("Something went wrong in the database"); } return(successfullyEditedPet); }
//should be changed public Pet EditPet(Pet petToEdite) { var validatedPet = ValidatePet(petToEdite, true); return(_petRepository.EditPet(validatedPet)); }
public void EditPet(Pet petForEditing) { _PetRepo.EditPet(petForEditing); }
public Pet EditPet(Pet updatedPet) { return(_petRepository.EditPet(updatedPet)); }