public async Task <ActionResult <PetVM> > PostPet(PetCoreVM petModel) { //Validate model if (petModel == null) { return(BadRequest("No data provided.")); } if (!ModelState.IsValid) { return(ValidationProblem(ModelState)); } var createdPet = await _petService .Add(new tblPet { Name = petModel.Name, FKAnimalTypeId = petModel.AnimalTypeId.Value, FKOwnerId = petModel.OwnerId }); var result = new PetVM { PetId = createdPet.Id, Name = createdPet.Name, AnimalTypeId = createdPet.FKAnimalTypeId, AnimalType = createdPet.AnimalType.AnimalType, OwnerId = createdPet.FKOwnerId, OwnersName = createdPet.Owner?.FullName }; return(Ok(result)); }
public async Task <ResponseVM> CreatePet(PetVM model, string email) { bool res = false; var account = await _accountRepository.FindByNameAccount(email); if (account != null) { _petRepository.Create(new Pet { PetName = model.PetName, PetAge = model.PetAge, PetSex = model.PetSex, PetWeight = model.PetWeight, AccountId = account.Id }); _commitProvider.Save(); return(new ResponseVM() { Result = true, Message = "Pet Createed" }); } else { return(new ResponseVM() { Result = res, Message = "Account not Found!" }); } }
public PetVM Add(PetVM petVm) { var pet = Mapper.Map <PetVM, Pet>(petVm); ObjectUtils.CheckNullObj(pet); _uow.BeginTransaction(); _petService.Add(pet); _uow.Commit(); return(petVm); }
public async Task <IActionResult> Create([FromForm] PetVM model) { ResponseVM response = new ResponseVM(); var email = User.Identity.Name; if (ModelState.IsValid) { response = await _petService.CreatePet(model, email); if (response.Result) { return(Ok(response)); } } return(BadRequest(response)); }