public async Task UpdateAnimalAsync(Guid animalId, AnimalCreate animalDto) { var animal = await _animalRepository.GetAsync(animalId); _mapper.Map(animalDto, animal); _animalRepository.Update(animal); await _unitOfWork.SaveChangesAsync(); }
public async Task <Guid> AddAnimalAsync(Guid ownerId, AnimalCreate animalModel) { var animal = _mapper.Map <Animal>(animalModel); animal.OwnerId = ownerId; var id = _animalRepository.Create(animal); await _unitOfWork.SaveChangesAsync(); return(id); }
public bool CreateAnimal(AnimalCreate model) { using (var ctx = new ApplicationDbContext()) { var entity = new Animal() { Name = model.Name }; ctx.Animals.Add(entity); return(ctx.SaveChanges() == 1); } }
public IHttpActionResult Post(AnimalCreate model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var service = new AnimalService(); if (!service.CreateAnimal(model)) { return(InternalServerError()); } return(Ok(model)); }
public bool CreateAnimal(AnimalCreate model) { var entity = new Animal() { AnimalName = model.AnimalName, AnimalType = model.AnimalType, DateJoinedAnimal = model.DateJoinedAnimal, FosterBoolAnimal = model.FosterBoolAnimal, AdoptedBoolAnimal = model.AdoptedBoolAnimal }; using (var ctx = new ApplicationDbContext()) { ctx.Animals.Add(entity); return(ctx.SaveChanges() == 1); } }
public ActionResult Create(AnimalCreate model) { if (!ModelState.IsValid) { return(View(model)); } var service = new AnimalService(); if (service.CreateAnimal(model)) { TempData["SaveResult"] = "Your Animal Entry was created."; return(RedirectToAction("Index")); } ModelState.AddModelError("", "Animal Entry could not be created."); return(View(model)); }
public bool CreateAnimal(AnimalCreate animal) { var entity = new Animal() { Name = animal.Name, Species = animal.Species, Breed = animal.Breed, Sex = animal.Sex, Fixed = animal.Fixed, Vaccines = animal.Vaccines, Age = animal.Age, Description = animal.Description, AdoptionPrice = animal.AdoptionPrice, IsHouseTrained = animal.IsHouseTrained, IsDeclawed = animal.IsDeclawed, IsEdible = animal.IsEdible }; using (var db = new ApplicationDbContext()) { db.Animals.Add(entity); return(db.SaveChanges() == 1); } }
public async Task <IActionResult> UpdateAnimal(Guid animalId, [FromBody] AnimalCreate animal) { await _animalManager.UpdateAnimalAsync(animalId, animal); return(Ok()); }
public async Task <IActionResult> AddAnimal(Guid ownerId, [FromBody] AnimalCreate animal) { var animalId = await _animalManager.AddAnimalAsync(ownerId, animal); return(Ok(animalId)); }