public ActionResult UpdatePet(Guid id, PetUpdateDto petUpdateDto) { if (!Request.Headers.ContainsKey("token")) { return(Unauthorized()); } var auth = Request.Headers["token"]; var accountModel = _validate.GetAccountByToken(auth); if (accountModel == null) { return(Unauthorized()); } var petModelFromRepo = _repository.GetPetById(id, accountModel.Id); if (petModelFromRepo == null) { return(NotFound()); } _mapper.Map(petUpdateDto, petModelFromRepo); _repository.UpdatePet(petModelFromRepo); _repository.SaveChanges(); return(NoContent()); }
public Pet PartialUpdate(Pet pet, PetUpdateDto updatedpet) { //update var entry = context.Entry(pet); entry.CurrentValues.SetValues(updatedpet); entry.State = EntityState.Modified; return(pet); }
public ActionResult <PetUpdateDto> UpdatePet(PetUpdateDto model) { var updatedPet = _mapper.Map <Pet>(model); var result = _pet.UpdatePet(updatedPet); var readPet = _mapper.Map <PetDto>(result.Data); //return Ok(createdPet); //return CreatedAtRoute(nameof(GetPetById), new { Id = readPet.Id }, readPet); return(RedirectToAction("GetPetById", "Pet", readPet)); // 뭔가 이상하지만 일단 진행 }
public PetDisplayDto UpdatePet(int petId, int ownerId, PetUpdateDto pet) { if (!petRepository.Records.Any(x => x.PetId == petId && x.OwnerId == ownerId)) { throw new CustomDbConflictException("Pet not found."); } var oldPet = petRepository.Records.Where(x => x.PetId == petId).FirstOrDefault(); var updatedPet = petRepository.PartialUpdate(oldPet, pet); var displayPet = mapper.Map <Pet, PetDisplayDto>(updatedPet); return(displayPet); }
public ActionResult <PetUpdateDto> UpdateLocation(PetUpdateDto model) { var petDto = _pet.GetPetById(model.Id).Data; var updatedPet = _mapper.Map <Pet>(petDto); updatedPet.Location = model.Location; updatedPet.Location.Pet = petDto; var result = _pet.UpdateLocation(updatedPet.Location); var readPet = _mapper.Map <PetDto>(result.Data.Pet); //return Ok(createdPet); //return CreatedAtRoute(nameof(GetPetById), new { Id = readPet.Id }, readPet); return(RedirectToAction("GetPetById", "Pet", readPet)); // 뭔가 이상하지만 일단 진행 }
public IActionResult UpdatePetPage(PetUpdateDto model) { var dto = _pet.GetPetById(model.Id).Data; var updateDto = new PetUpdateDto() { Id = dto.Id, Age = dto.Age, Breed = dto.Breed, IsNeutralized = dto.IsNeutralized, SerialNumber = dto.SerialNumber, Weight = dto.Weight, Location = dto.Location }; return(View(updateDto)); }
public IActionResult Put(int id, PetUpdateDto pet) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } //authentication var userId = Int32.Parse(User.FindFirst("UserId").Value); try { var newPet = petManager.UpdatePet(id, userId, pet); return(Ok(newPet)); } catch (CustomDbConflictException e) { return(BadRequest(e.Message)); } }