public IHttpActionResult SaveParentTask(ParentTasks objPTask)
        {
            ParentTasks ptaskData = new ParentTasks();

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            try
            {
                objPtaskRepo.AddParentTask(objPTask);
            }
            catch (DbUpdateException)
            {
                ptaskData = objPtaskRepo.GetParentTaskById(objPTask.ParentTaskId);

                if (ptaskData == null)
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }
            return(Ok(objPTask.ParentTaskId));
        }
        public void GetParentTaskByIdBenchmark()
        {
            ParentTasks firstParent = randomParents.First();
            ParentTasks getParent   = parentRepository.GetParentTaskById(firstParent.ParentTaskId);

            _counter.Increment();
        }
        public IHttpActionResult EditParentTask(int id, ParentTasks objPTask)
        {
            ParentTasks ptaskData = new ParentTasks();

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != objPTask.ParentTaskId)
            {
                return(BadRequest());
            }

            try
            {
                objPtaskRepo.EditParentTask(objPTask);
            }
            catch (DbUpdateConcurrencyException)
            {
                ptaskData = objPtaskRepo.GetParentTaskById(id);
                if (ptaskData == null)
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public IHttpActionResult GetParentTaskById(int id)
        {
            IHttpActionResult retResult = null;
            ParentTasks       ptaskData = new ParentTasks();

            try
            {
                ptaskData = objPtaskRepo.GetParentTaskById(id);
                if (ptaskData == null)
                {
                    retResult = NotFound();
                }

                retResult = Ok(ptaskData);
            }
            catch (ApplicationException ex)
            {
                throw new HttpResponseException(new HttpResponseMessage {
                    StatusCode = HttpStatusCode.BadRequest, ReasonPhrase = ex.Message
                });
            }
            catch (Exception ex)
            {
                throw new HttpResponseException(new HttpResponseMessage {
                    StatusCode = HttpStatusCode.BadGateway, ReasonPhrase = ex.Message
                });
            }

            return(retResult);
        }
        public bool UpdateTask(TasksModel tsk)
        {
            ParentTasks pt = new ParentTasks();

            pt.ParentID       = tsk.ParentID;
            pt.ParentTaskName = tsk.ParentTaskName;

            Tasks t = new Tasks();

            t.TaskID   = tsk.TaskID;
            t.TaskName = tsk.TaskName;
            t.Priority = tsk.Priority;
            t.ParentID = pt.ParentID;
            if (tsk.StartDate.HasValue)
            {
                t.StartDate = tsk.StartDate.Value;
            }
            if (tsk.EndDate.HasValue)
            {
                t.EndDate = tsk.EndDate.Value;
            }
            //t.StartDate = DbFunctions.TruncateTime(tsk.StartDate.Value.Date);
            //t.EndDate = DbFunctions.TruncateTime(tsk.EndDate.Value.Date);
            //db.Entry(pt).State = EntityState.Modified;
            //db.MarkAsModified(t);
            //db.SaveChanges();
            //db.Entry(t).State = EntityState.Modified;
            db.MarkAsModified(t);
            db.SaveChanges();
            return(true);
        }
        public void InitializeTest()
        {
            for (int i = 100; i < 500; i = i + 100)
            {
                parentTask = new ParentTasks {
                    Parent_ID = 100, Parent_Task = "Parent Task"
                };
                for (int j = 1; j < 3; j++)
                {
                    tasks.Add(new Tasks {
                        Parent_ID = i, ParentTask = parentTask, TaskName = String.Format("Task-{0}", i), Task_ID = i + j
                    });
                }
            }

            repository.Setup(x => x.GetTask()).Returns(() => tasks);
            repository.Setup(x => x.GetTask(It.IsAny <int>())).Returns((int id) => tasks.Find(x => x.Task_ID == id));
            repository.Setup(x => x.AddTask(It.IsAny <Tasks>())).Callback((Tasks task) => tasks.Add(task));
            repository.Setup(x => x.UpdateTask(It.IsAny <int>(), It.IsAny <Tasks>())).Callback((int id, Tasks task) =>
            {
                foreach (Tasks item in tasks)
                {
                    if (item.Task_ID == id)
                    {
                        item.TaskName = task.TaskName;
                    }
                }
            });
            // repository.Setup(x => x.DeleteTask(It.IsAny<int>())).Callback((int id) => tasks.RemoveAt(tasks.IndexOf(tasks.Where(x => x.Task_ID == id).FirstOrDefault())));

            controller = new TaskController(repository.Object);
        }
 /* Methods for ParentTask Maintenance */
 public void AddParentTask(ParentTasks objTask)
 {
     using (var ptaskContext = new DatabaseContext())
     {
         ptaskContext.Entry(objTask).State = System.Data.Entity.EntityState.Added;
         ptaskContext.ParentTask.Add(objTask);
         ptaskContext.SaveChanges();
     }
 }
        public void TestGetParentTaskById()
        {
            ParentTasks firstParent = randomParents.First();
            ParentTasks getParent   = parentRepository.GetParentTaskById(firstParent.ParentTaskId);

            Assert.IsNotNull(getParent);
            Assert.AreEqual(firstParent.ParentTaskId, getParent.ParentTaskId);
            Assert.AreEqual(firstParent.ProjectID, getParent.ProjectID);
        }
        public void AddTask(ParentTasks TasksModel)
        {
            var TaskDBcontext = new TaskDBEntities();
            var task          = new ParentTask();

            task.Parent_ID   = TasksModel.Parent_ID;
            task.Parent_Task = TasksModel.Parent_Task;
            TaskDBcontext.ParentTasks.Add(task);
            TaskDBcontext.SaveChanges();
        }
Exemplo n.º 10
0
        public void AddParentTask(CommonEntities.ParentTasks pTask)
        {
            ParentTasks tk = new ParentTasks
            {
                ParentTask = pTask.ParentTask
            };

            _projectManager.ParentTasks1.Add(tk);
            _projectManager.SaveChanges();
        }
        public ParentTasks GetParentTaskById(int TaskId)
        {
            ParentTasks objdata = new ParentTasks();

            objdata = null;
            using (var ptaskContext = new DatabaseContext())
            {
                objdata = (from obTask in ptaskContext.ParentTask where obTask.ParentTaskId == TaskId select obTask).FirstOrDefault();
            }
            return(objdata);
        }
        public void AddParentTaskBenchmark()
        {
            ParentTasks newParent = new ParentTasks()
            {
                ParentTaskName = "Development",
                ProjectID      = 3
            };

            parentRepository.AddParentTask(newParent);
            _counter.Increment();
        }
Exemplo n.º 13
0
 public void AddTask(ParentTasks model)
 {
     using (var TaskDBcontext = new TaskDBEntities())
     {
         var task = new ParentTask();
         task.Parent_ID   = model.Parent_ID;
         task.Parent_Task = model.Parent_Task;
         task.Project_ID  = model.Project_ID;
         TaskDBcontext.ParentTasks.Add(task);
         TaskDBcontext.SaveChanges();
     }
 }
        public IHttpActionResult DeleteParentTask(int id)
        {
            ParentTasks ptaskData = new ParentTasks();

            ptaskData = objPtaskRepo.GetParentTaskById(id);
            if (ptaskData == null)
            {
                return(NotFound());
            }
            objPtaskRepo.RemoveParentTask(id);
            return(Ok(ptaskData));
        }
Exemplo n.º 15
0
        public void UpdateTask(int id, ParentTasks TasksModel)
        {
            var TaskDBcontext = new TaskDBEntities();
            var task          = TaskDBcontext.ParentTasks.FirstOrDefault(x => x.Parent_ID == id);

            if (task != null)
            {
                task.Parent_ID   = TasksModel.Parent_ID;
                task.Parent_Task = TasksModel.Parent_Task;
                TaskDBcontext.SaveChanges();
            }
        }
        public void RemoveParentTask(int TaskId)
        {
            ParentTasks objdata = new ParentTasks();

            using (var ptaskContext = new DatabaseContext())
            {
                objdata = ptaskContext.ParentTask.Find(TaskId);
                if (objdata != null)
                {
                    ptaskContext.ParentTask.Remove(objdata);
                    ptaskContext.SaveChanges();
                }
            }
        }
        public void UpdateParentTaskBenchmark()
        {
            ParentTasks firstParent = randomParents.Find(a => a.ParentTaskId == 1001);

            ParentTasks UpdateParent = new ParentTasks()
            {
                ParentTaskId   = firstParent.ParentTaskId,
                ParentTaskName = firstParent.ParentTaskName,
                ProjectID      = 5
            };

            parentRepository.EditParentTask(UpdateParent);
            _counter.Increment();
        }
Exemplo n.º 18
0
        /* To insert or update the task */

        public TaskUpdateModel InsertUpdateTask(TaskModel task_Model)
        {
            StatusModel _status = new StatusModel();

            if (task_Model.Parent_ID == null)
            {
                ParentTasks oParent = new ParentTasks()
                {
                    Parent_Task = task_Model.TaskName
                };
                oParent = parent.AddParentTask(oParent);
                task_Model.Parent_ID = oParent.Parent_ID;
            }
            Task task = new Task()
            {
                End_Date   = task_Model.End_Date,
                Parent_ID  = task_Model.Parent_ID,
                Priority   = task_Model.Priority,
                Project_ID = task_Model.Project_ID,
                Start_Date = task_Model.Start_Date,
                Status     = task_Model.Status,
                Task1      = task_Model.TaskName,
                User_ID    = task_Model.User_ID
            };

            if (task_Model.Task_ID == 0)
            {
                task    = repoTask.AddTask(task);
                _status = new StatusModel()
                {
                    Message = "Task details are added successfully", Result = true
                };
            }
            else
            {
                task.Task_ID = task_Model.Task_ID;
                task         = repoTask.UpdateTask(task);
                _status      = new StatusModel()
                {
                    Message = "Task details are updated successfully", Result = true
                };
            }

            return(new TaskUpdateModel()
            {
                status = _status,
                task = null
            });
        }
Exemplo n.º 19
0
        public ParentTasks GetTask(int id)
        {
            ParentTasks Tasks = null;
            var         task  = new TaskDBEntities().ParentTasks.FirstOrDefault(x => x.Parent_ID == id);

            if (task != null)
            {
                Tasks = new ParentTasks()
                {
                    Parent_ID   = task.Parent_ID,
                    Parent_Task = task.Parent_Task
                };
            }
            return(Tasks);
        }
        public void TestAddParentTask()
        {
            ParentTasks newParent = new ParentTasks()
            {
                ParentTaskName = "Development",
                ProjectID      = 3
            };

            parentRepository.AddParentTask(newParent);
            randomParents = SetupParent();
            ParentTasks lastParent = randomParents.Last();

            Assert.AreEqual(lastParent.ParentTaskName, "Development");
            Assert.AreEqual(newParent.ProjectID, lastParent.ProjectID);
        }
        public void TestUpdateParentTask()
        {
            ParentTasks firstParent = randomParents.Find(a => a.ParentTaskId == 1001);

            ParentTasks UpdateParent = new  ParentTasks()
            {
                ParentTaskId   = firstParent.ParentTaskId,
                ParentTaskName = firstParent.ParentTaskName,
                ProjectID      = 5
            };

            parentRepository.EditParentTask(UpdateParent);

            Assert.AreEqual(firstParent.ParentTaskId, UpdateParent.ParentTaskId);
            Assert.That(firstParent.ProjectID, Is.EqualTo(5));
        }
        public void EditParentTask(ParentTasks objTask)
        {
            ParentTasks objdata = new ParentTasks();

            using (var ptaskContext = new DatabaseContext())
            {
                objdata = ptaskContext.ParentTask.Find(objTask.ParentTaskId);
                if (objdata != null)
                {
                    objdata.ParentTaskName = objTask.ParentTaskName;
                    objdata.ProjectID      = objTask.ProjectID;
                }
                ptaskContext.Entry(objdata).CurrentValues.SetValues(objTask);
                ptaskContext.SaveChanges();
            }
        }
Exemplo n.º 23
0
        private ParentTasks GetParentInfo(int ID)
        {
            var ObjModel = new ParentTasks();

            using (var ObjDBcontext = new TaskDBEntities())
            {
                var pTask = ObjDBcontext.ParentTasks.FirstOrDefault(e => e.Parent_ID == ID);
                if (pTask != null)
                {
                    ObjModel = new ParentTasks()
                    {
                        Parent_ID   = pTask.Parent_ID,
                        Parent_Task = pTask.Parent_Task,
                        Project_ID  = pTask.Project_ID
                    };
                }
            }
            return(ObjModel);
        }
Exemplo n.º 24
0
        //public IHttpActionResult GetTask(int id)
        //{
        //    List<FilteredTask> task = new List<FilteredTask>();
        //    task = (from a in db.Tasks
        //                              join c in db.Users
        //                              on a.Task_ID equals c.Task_ID into Tasks
        //                              from c in Tasks.DefaultIfEmpty()
        //                              join b in db.Parent_Task on a.Parent_ID
        //                              equals b.Parent_ID
        //                              join d in db.Projects on a.Project_ID equals d.Project_ID
        //                              where a.Task_ID==id
        //                              select new FilteredTask
        //                              {
        //                                  Id = a.Task_ID,
        //                                  Name = a.Task1,
        //                                  Parent_ID=b.Parent_ID,
        //                                  Parent_Task_Name = b.Parent_Task1,
        //                                  Project_ID=a.Project_ID,
        //                                  Start_Date=a.Start_Date,
        //                                  End_Date=a.End_Date,
        //                                  Priority=a.Priority,
        //                                  Status=a.Status,
        //                                  UserId = c.User_ID== null ?null : c.User_ID,
        //                                  UserFirstName = c.First_Name,
        //                                  UserLastName = c.Last_Name,
        //                                  Project_Name = d.Project1
        //                              }).ToList();

        //    return Ok(task);
        //}
        public IHttpActionResult GetTask(int id)
        {
            var filteredTask_Table = (from t in (from s in (
                                                     from a in db.Tasks
                                                     where a.Task_ID == id
                                                     join c in db.Users
                                                     on a.Task_ID equals c.Task_ID into Tasks
                                                     from c in Tasks.DefaultIfEmpty()
                                                     select new
            {
                a.Task_ID,
                a.Task1,
                a.Project_ID,
                a.Parent_ID,
                a.Start_Date,
                a.End_Date,
                a.Priority,
                a.Status,
                c.User_ID,
                c.First_Name,
                c.Last_Name
            })

                                                 join b in db.Parent_Task
                                                 on s.Parent_ID
                                                 equals b.Parent_ID into ParentTasks
                                                 from b in ParentTasks.DefaultIfEmpty()
                                                 select new
            {
                s.Task_ID,
                s.Task1,
                s.Project_ID,
                s.Parent_ID,
                s.Start_Date,
                s.End_Date,
                s.Priority,
                s.Status,
                s.User_ID,
                s.First_Name,
                s.Last_Name,
                b.Parent_Task1
            }
                                                 )
                                      join d in db.Projects
                                      on t.Project_ID equals d.Project_ID
                                      into Projects
                                      from d in Projects.DefaultIfEmpty()
                                      select new FilteredTask
            {
                Id = t.Task_ID,
                Name = t.Task1,
                Parent_ID = t.Parent_ID,
                Parent_Task_Name = t.Parent_Task1,
                Project_ID = t.Project_ID,
                Start_Date = t.Start_Date,
                End_Date = t.End_Date,
                Priority = t.Priority,
                Status = t.Status,
                UserId = t.User_ID == null ? null : t.User_ID,
                UserFirstName = t.First_Name,
                UserLastName = t.Last_Name,
                Project_Name = d.Project1
            }).ToList();

            return(Ok(filteredTask_Table));
        }
        public void ParentTaskGetTestById()
        {
            ParentTasks task = controller.Get(200);

            Assert.IsNotNull(task);
        }
Exemplo n.º 26
0
 // POST: api/Task
 public void Post(ParentTasks TasksModel)
 {
     parentTaskRepository.AddTask(TasksModel);
 }
Exemplo n.º 27
0
 // PUT: api/Task/5
 public void Put(int id, ParentTasks TasksModel)
 {
     parentTaskRepository.UpdateTask(id, TasksModel);
 }