public IActionResult UpdatePublisher(int publisherId, [FromBody] PublisherUpdateDto updatedPublisher) { if (updatedPublisher == null) { return(BadRequest(ModelState)); } if (publisherId != updatedPublisher.Id) { return(BadRequest(ModelState)); } if (!_unitOfWork.PublisherRepository.PublisherExists(publisherId)) { ModelState.AddModelError("", "Publisher doesn't exist!"); } if (!ModelState.IsValid) { return(StatusCode(404, ModelState)); } if (!_unitOfWork.PublisherRepository.UpdatePublisher(updatedPublisher)) { ModelState.AddModelError("", $"Something went wrong updating the publisher " + $"{updatedPublisher.PublisherName}"); } _unitOfWork.Commit(); return(NoContent()); }
public bool UpdatePublisher(PublisherUpdateDto publisherToUpdateDto) { var publisherToUpdate = MapConfig.Mapper.Map <Publisher>(publisherToUpdateDto); _publisherContext.Update(publisherToUpdate); return(Save()); }
public ActionResult <Publisher> Update(PublisherUpdateDto PublisherUpdateDto) { try { return(service.Update(PublisherUpdateDto)); } catch (ArgumentException error) { return(NotFound(error.Message)); } catch (Exception error) { return(Conflict(error.Message)); } }
public Publisher Update(PublisherUpdateDto dto) { var isExist = GetDetail(dto.Name); if (isExist != null && dto.Id != isExist.Id) { throw new Exception(dto.Name + " existed"); } var entity = new Publisher { Id = dto.Id, Name = FormatString.Trim_MultiSpaces_Title(dto.Name, true), Image = FormatString.Trim_MultiSpaces_Title(dto.Image) }; return(repository.Update(entity)); }