public PetType EditPetType(PetType petType) { /* if (owner == null) * { * throw new ArgumentException("The sent data is null"); * } * * int index = _ownerRepository.GetOwners(new Filter()).List.FindLastIndex(c => c.ColourId == owner.ColourId); * * if (index == -1) * { * throw new KeyNotFoundException("owner needs to exist in database"); */ if (petType == null) { throw new ArgumentException("The sent data is null"); } if (_petTypeRepository.GetPetTypeById(petType.Id) == null) { throw new KeyNotFoundException("petType needs to exist in database"); } return(_petTypeRepository.EditPetType(petType, 1)); }
public PetType EditPetType(int idOfPetTypeToEdit, PetType editedPetType) { if (!_petTypeRepository.GetAllPetTypes().Exists(x => x.ID == idOfPetTypeToEdit)) { throw new KeyNotFoundException("A pet with this ID does not exist"); } else { return(_petTypeRepository.EditPetType(idOfPetTypeToEdit, editedPetType)); } }
public PetType EditPetType(int idOfPetTypeToEdit, PetType editedPetType) { if (_petTypeRepository.SearchById(editedPetType.PetTypeId) == null) { throw new KeyNotFoundException("An petType with this ID does not exist"); } if (editedPetType.Pets != null) { if (editedPetType.Pets.Count > 0) { throw new InvalidDataException("You cant add pets to a petType like this, go ad an owner id to a pet instead"); } } return(_petTypeRepository.EditPetType(idOfPetTypeToEdit, editedPetType)); }
public PetType EditPetType(PetType petTypeToEdit) { var validatedPetType = ValidatePetType(petTypeToEdit, true); return _petTypeRepository.EditPetType(validatedPetType); }