// PUT: api/Projects/5 public HttpResponseMessage Put([FromBody] Project value) { if (ModelState.IsValid) { return((LogicProjects.UpdateProject(value)) ? new HttpResponseMessage(HttpStatusCode.OK) : new HttpResponseMessage(HttpStatusCode.BadRequest) { Content = new ObjectContent <String>("Can not update in DB", new JsonMediaTypeFormatter()) }); } ; List <string> ErrorList = new List <string>(); //if the code reached this part - the user is not valid foreach (var item in ModelState.Values) { foreach (var err in item.Errors) { ErrorList.Add(err.ErrorMessage); } } return(new HttpResponseMessage(HttpStatusCode.BadRequest) { Content = new ObjectContent <List <string> >(ErrorList, new JsonMediaTypeFormatter()) }); }
public HttpResponseMessage UpdateProject([FromBody] Project value, [FromUri] int userId) { return((LogicProjects.UpdateProject(value, userId)) ? new HttpResponseMessage(HttpStatusCode.OK) : new HttpResponseMessage(HttpStatusCode.BadRequest) { Content = new ObjectContent <String>("Can not update in DB", new JsonMediaTypeFormatter()) }); }
public HttpResponseMessage UpdateProject([FromBody] Project value) { ModelState.Remove("value.DateBegin"); if (ModelState.IsValid) { bool b = LogicProjects.UpdateProject(value); return((b) ? Request.CreateResponse(HttpStatusCode.OK, b) : Request.CreateResponse(HttpStatusCode.BadRequest, "Can not update")); } ; return(Request.CreateResponse(HttpStatusCode.BadRequest, BaseLogic.GetErorList(ModelState.Values))); }