// POST: api/Projects
        public HttpResponseMessage Post([FromBody] Project value)
        {
            if (ModelState.IsValid)
            {
                return((LogicProjects.AddProject(value)) ?
                       new HttpResponseMessage(HttpStatusCode.Created) :
                       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 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 AddProject([FromBody] Project value)
        {
            if (ModelState.IsValid)
            {
                return((LogicProjects.AddProject(value)) ?
                       new HttpResponseMessage(HttpStatusCode.Created) :
                       new HttpResponseMessage(HttpStatusCode.BadRequest)
                {
                    Content = new ObjectContent <String>("Can not add to DB", new JsonMediaTypeFormatter())
                });
            }
            ;

            return(Request.CreateResponse(HttpStatusCode.BadRequest, BaseLogic.GetErorList(ModelState.Values)));
        }
        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())
            });
        }
Пример #4
0
        public HttpResponseMessage AddProject([FromBody] Project value)
        {
            if (ModelState.IsValid)
            {
                return((LogicProjects.AddProject(value)) ?
                       Request.CreateResponse(HttpStatusCode.Created) :
                       Request.CreateResponse(HttpStatusCode.BadRequest, "Can not add to DB"));
            }
            ;

            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(Request.CreateResponse(HttpStatusCode.BadRequest, ErrorList));
        }