Esempio n. 1
0
        public IHttpActionResult addProject([FromBody] ProjectModel project)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("Not a valid data"));
            }
            try
            {
                if (project != null)
                {
                    TaskManagerRepository tmRep = new TaskManagerRepository();

                    Project_Tbl projectDb = new Project_Tbl
                    {
                        Project    = project.ProjectName,
                        Start_Date = project.StartDate != null?Convert.ToDateTime(project.StartDate) : (DateTime?)null,
                                         End_Date = project.EndDate != null?Convert.ToDateTime(project.EndDate) : (DateTime?)null,
                                                        Priority = project.Priority,
                    };

                    int userId = project.Users != null?project.Users.FirstOrDefault().UserId : 0;

                    string result = "{'ProjectID': " + tmRep.addProject(projectDb, userId) + "}";

                    JObject json = JObject.Parse(result);

                    return(Ok <JObject>(json));
                }
                else
                {
                    return(BadRequest("Error occurred in addProject"));
                }
            }
            catch (Exception ex)
            {
                return(BadRequest("Error occurred in addProject :" + ex.StackTrace));
            }
        }