public IActionResult Put(int id, [FromBody] PublisherUpdateDTO DTO) { if (DTO == null) { return(BadRequest()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var entity = _rep.Get <Publisher>(id); if (entity == null) { return(NotFound()); } Mapper.Map(DTO, entity); if (!_rep.Save()) { return(StatusCode(500, "A problem happened while handling your request.")); } return(NoContent()); }
public IActionResult Put(int id, [FromBody] PublisherUpdateDTO publisher) { if (publisher == null) { return(BadRequest()); } if (publisher.Established < 1534 || publisher.Established > DateTime.Now.Year) { ModelState.AddModelError("Established", "Первое издательское агенство было основано в 1534 г."); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var publisherExists = _rep.PublisherExists(id); if (!publisherExists) { return(NotFound()); } _rep.UpdatePublisher(id, publisher); _rep.Save(); return(NoContent()); }
public void UpdatePublisher(int id, PublisherUpdateDTO publisher) { var publisherToUpdate = GetPublisher(id); publisherToUpdate.Name = publisher.Name; publisherToUpdate.Established = publisher.Established; }
public IActionResult Put(int id, [FromBody] PublisherUpdateDTO publisher) { if (publisher == null) { return(BadRequest()); } if (publisher.Established < 1534) { ModelState.AddModelError("Established", "The first publishing house was founded in 1534."); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var publisherExists = _rep.PublisherExists(id); if (!publisherExists) { return(NotFound()); } _rep.UpdatePublisher(id, publisher); _rep.Save(); return(NoContent()); }
public void UpdatePublisher(int id, PublisherUpdateDTO publisher) { var publisherUpdate = _db.Publishers.FirstOrDefault(p => p.Id.Equals(id)); if (publisherUpdate == null) { return; } publisherUpdate.Name = publisher.Name; publisherUpdate.Established = publisher.Established; }
public IActionResult Patch(int id, [FromBody] JsonPatchDocument <PublisherUpdateDTO> publisher) { if (publisher == null) { return(BadRequest()); } var publisherToUpdate = _rep.GetPublisher(id); if (publisherToUpdate == null) { return(NotFound()); } var publisherPatch = new PublisherUpdateDTO() { Name = publisherToUpdate.Name, Established = publisherToUpdate.Established }; publisher.ApplyTo(publisherPatch, ModelState); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (publisherPatch.Established < 1534) { ModelState.AddModelError("Established", "The oldest publishing house was founded in 1534."); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _rep.UpdatePublisher(id, publisherPatch); _rep.Save(); return(NoContent()); }
public IActionResult Patch(int id, [FromBody] JsonPatchDocument <PublisherUpdateDTO> publisher) { if (publisher == null) { return(BadRequest()); } var publisherToUpdate = _rep.GetPublisher(id); if (publisherToUpdate == null) { return(NotFound()); } var publisherPatch = new PublisherUpdateDTO { Name = publisherToUpdate.Name, Established = publisherToUpdate.Established }; publisher.ApplyTo(publisherPatch, ModelState); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (publisherPatch.Established < 1534 || publisherPatch.Established > DateTime.Now.Year) { ModelState.AddModelError("Established", "Первое издательское агенство было основано в 1534 г."); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _rep.UpdatePublisher(id, publisherPatch); _rep.Save(); return(NoContent()); }