public ActionResult CreatePet(int memberID, int specieID, string petName) { if (specieID == 0) { return(Json(new { Result = "Fail, pet specie is required " })); } if (String.IsNullOrEmpty(petName)) { return(Json(new { Result = "Fail, name is required" })); } Pet Checkname = _PetRepo.GetByMemberIDAndNameAndSpecie(memberID, petName, specieID); if (Checkname != null) { return(Json(new { Result = "Fail, The member already have " + (_SpecieRepo.GetById(specieID)).name + " name " + petName })); } Pet pet = new Pet(); pet.memberId = memberID; pet.specieId = specieID; pet.name = petName; _PetRepo.Add(pet); return(Json(new { Result = "Success" })); }
[ProducesResponseType(StatusCodes.Status500InternalServerError)] // if something unexpectedly went wrong with the database or http request/response public async Task <ActionResult <Furs2Feathers.Domain.Models.Pet> > PostPet(Furs2Feathers.Domain.Models.Pet pet) { petRepo.Add(pet); await petRepo.SaveChangesAsync(); return(CreatedAtAction("GetPet", new { id = pet.PetId }, pet)); }
public Pet Add(string name, DateTime birthDate, DateTime soldDate, Colour colour, PetType type, Person previousOwner, double price) { try { return(_prep.Add(name, birthDate, soldDate, colour, type, previousOwner, price)); } catch (Exception e) { throw new ServiceException("Error adding pet: " + e.Message, e); } }
public PetDisplayDto CreatePet(PetRegisterDto pet) { if (!petRepository.Records.Any(x => x.OwnerId == pet.OwnerId && x.Name == pet.Name)) { throw new CustomDbConflictException("Pet name exsisted."); } //add var newPet = mapper.Map <PetRegisterDto, Pet>(pet); newPet = petRepository.Add(newPet); var displayPet = mapper.Map <Pet, PetDisplayDto>(newPet); return(displayPet); }
public override void Execute(Pet pet) { var validation = new RegisterNewPetValidation().Validate(pet); if (!validation.IsValid) { AddErros(validation.Errors.Select(x => x.ErrorMessage).ToList()); return; } pet.CreateNewId(); _petRepository.Add(pet); Commit(); }
public async Task <Response <Pet> > SaveAsync(Pet payload) { try { _petRepository.Add(payload); await _unitOfWork.CompleteAsync(); return(new Response <Pet>(payload)); } catch (Exception ex) { _logger.LogError($"{nameof(PetService)} {nameof(SaveAsync)} {ex.Message}"); return(new Response <Pet>(ex.Message)); } }
//TODO: "Get food for pet" method public async Task <tblPet> Add(tblPet entity) { if (entity == null) { throw new ArgumentNullException("Cannot add blank pet"); } if (await _petRepository.GetByIdAsync(entity.Id).ConfigureAwait(false) != null) { throw new ArgumentException("Pet already exists."); } if (entity.FKOwnerId.HasValue && await _ownerRepository.GetByIdAsync(entity.FKOwnerId.Value) == null) { throw new InvalidOperationException("Unable to add pet for owner that doesn't exist."); } var createdEntity = await _petRepository.Add(entity); return(await _petRepository.GetByIdAsync(createdEntity.Id)); }
public Pet AddPet(Pet newPet) { _iPetRepository.Add(newPet); return(newPet); }
public Pet Add(Pet pet) { return(_petRepository.Add(pet)); }
public void CreatePet(Pet pet) { petRepository.Add(pet); }
public bool Add(Pet pet) { _repository.Add(pet); return(_repository.SaveChanges()); }