public HttpResponseMessage Patch(int id, [FromBody] StudiosModel model) { try { var entity = this.movieRepo.GetSingleStudio(id); if (entity == null) { return(this.Request.CreateResponse(HttpStatusCode.NotFound)); } var parsedUserValue = this.modelFactory.ParsePatch(model, id); if (parsedUserValue == null) { return(this.Request.CreateResponse(HttpStatusCode.BadRequest)); } var studioCheck = this.Validate.StudioNameCheck(entity.StudioName); if (studioCheck != string.Empty) { return(this.Request.CreateErrorResponse(HttpStatusCode.BadRequest, studioCheck)); } if (this.movieRepo.SaveAll()) { return(this.Request.CreateResponse(HttpStatusCode.OK)); } return(this.Request.CreateResponse(HttpStatusCode.BadRequest)); } catch (Exception ex) { return(this.Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } }
public HttpResponseMessage Post([FromBody] StudiosModel studioModel) { try { var entity = this.modelFactory.Parse(studioModel); if (entity == null) { return(this.Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Bad formed JSON request.")); } var studioCheck = this.Validate.StudioNameCheck(entity.StudioName); if (studioCheck != string.Empty) { return(this.Request.CreateErrorResponse(HttpStatusCode.BadRequest, studioCheck)); } if (this.movieRepo.Add(entity)) { if (this.movieRepo.SaveAll()) { return(this.Request.CreateResponse(HttpStatusCode.OK)); } } return(this.Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Bad formed JSON request")); } catch (Exception ex) { return(this.Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } }