public HttpResponseMessage AddProject([FromBody] Project value, [FromUri] int userId) { if (ModelState.IsValid) { if (LogicProjects.AddProject(value, userId)) { List <User> users = LogicWorkerToProject.getUsersByTeamLeaderId(value.TeamLeaderId); var id = LogicProjects.getProjectId(value.ProjectName); value.ProjectId = id; foreach (var item in users) { LogicWorkerToProject.AddWorkersByTeamLeaderId(id, item.UserId); } return(Request.CreateResponse(HttpStatusCode.Created, value)); } else { new HttpResponseMessage(HttpStatusCode.BadRequest) { Content = new ObjectContent <String>("Can not add to DB", new JsonMediaTypeFormatter()) }; } } ; List <string> ErrorList = new List <string>(); //if the code reached this part - the project 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()) }); }