public HttpResponseMessage PostTaskTab(TaskTab taskTab)
        {
            var lstTasks = GetTaskTabs();
            var task_id  = 1;

            if (lstTasks != null && lstTasks.Count() > 0)
            {
                task_id = lstTasks.Max(x => x.Task_ID) + 1;
            }

            taskTab.Task_ID = task_id;

            db.TaskTabs.Add(taskTab);

            try
            {
                db.SaveChanges();

                if (taskTab.User != null)
                {
                    taskTab.User.Task_ID = task_id;
                    var usersTabController = new UsersTabsController();
                    usersTabController.Put(taskTab.User);
                }

                var message = Request.CreateResponse(HttpStatusCode.Created, taskTab);
                return(message);
            }
            catch (Exception ex)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, ex));
            }
        }
        // PUT: api/TaskTabs/5

        public HttpResponseMessage Put(TaskTab taskTab)
        {
            db.Entry(taskTab).State = EntityState.Modified;

            try
            {
                taskTab.User.Task_ID = taskTab.Task_ID;
                var usersTabController = new UsersTabsController();
                var prevUser           = usersTabController.GetUsersTabs().FirstOrDefault
                                             (x => x.Task_ID == taskTab.Task_ID);

                if (prevUser == null)
                {
                    usersTabController.Put(taskTab.User);
                }

                else if (prevUser != null && prevUser.Task_ID != null && prevUser.User_ID != taskTab.User.User_ID)
                {
                    prevUser.Task_ID = (int?)null;
                    usersTabController.Put(prevUser);
                    usersTabController.Put(taskTab.User);
                }


                db.SaveChanges();

                var message = Request.CreateResponse(HttpStatusCode.Created, taskTab);
                return(message);
            }
            catch (Exception ex)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, ex));
            }
        }
Exemple #3
0
        // PUT: api/ProjectTabs/5

        public HttpResponseMessage Put(ProjectTab projectTab)
        {
            db.Entry(projectTab).State = EntityState.Modified;

            try
            {
                if (projectTab.Manager != null)
                {
                    projectTab.Manager.Project_ID = projectTab.Project_ID;
                    var usersTabController = new UsersTabsController();
                    var proj        = this.GetProjectTab(projectTab.Project_ID);
                    var prevManager = usersTabController.GetUsersTabs().FirstOrDefault
                                          (x => x.Project_ID == proj.Project_ID);

                    if (prevManager != null && prevManager.Project_ID != null && prevManager.User_ID != projectTab.Manager.User_ID)
                    {
                        prevManager.Project_ID = (int?)null;
                        usersTabController.Put(prevManager);
                        usersTabController.Put(projectTab.Manager);
                    }
                }

                db.SaveChanges();



                var message = Request.CreateResponse(HttpStatusCode.Created, projectTab);
                return(message);
            }
            catch (Exception ex)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, ex));
            }
        }
Exemple #4
0
        public HttpResponseMessage PostProjectTab(ProjectTab projectTab)
        {
            var lstProj    = GetProjectTabs();
            var project_id = 1;

            if (lstProj != null && lstProj.Count() > 0)
            {
                project_id = lstProj.Max(x => x.Project_ID) + 1;
            }

            projectTab.Project_ID = project_id;

            db.ProjectTabs.Add(projectTab);



            try
            {
                db.SaveChanges();

                if (projectTab.Manager != null)
                {
                    projectTab.Manager.Project_ID = project_id;
                    var usersTabController = new UsersTabsController();
                    usersTabController.Put(projectTab.Manager);
                }

                var message = Request.CreateResponse(HttpStatusCode.Created, projectTab);
                return(message);
            }
            catch (Exception ex)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, ex));
            }
        }
Exemple #5
0
        // GET: api/ProjectTabs
        public IQueryable <ProjectTab> GetProjectTabs()
        {
            var projList = db.ProjectTabs;

            if (projList != null && projList.Count() > 0)
            {
                var taskCtrl = new TaskTabsController();
                var userCtrl = new UsersTabsController();

                foreach (var proj in projList)
                {
                    var taskList = taskCtrl.GetTaskTabs().Where(x => x.Project_ID == proj.Project_ID);
                    var userList = userCtrl.GetUsersTabs().Where(x => x.Project_ID == proj.Project_ID);
                    proj.NoofTasks = taskList.Count();
                    proj.Completed = taskList.Where(x => x.Status == "Completed").Count();

                    if (userList != null && userList.Count() > 0)
                    {
                        proj.Manager = userList.FirstOrDefault();
                    }
                }
            }

            return(projList);
        }