public IActionResult GetByTaskID(int TaskID)
        {
            //Get task from database
            MvcTaskManager.Models.Task task = db.Tasks
                                              .Include(temp => temp.CreatedByUser)
                                              .Include(temp => temp.AssignedToUser)
                                              .Include(temp => temp.Project).ThenInclude(temp => temp.ClientLocation)
                                              .Include(temp => temp.TaskStatusDetails)
                                              .Include(temp => temp.TaskPriority)
                                              .Where(temp => temp.TaskID == TaskID)
                                              .FirstOrDefault();

            if (task != null)
            {
                //Date conversion
                task.CreatedOnString     = task.CreatedOn.ToString("dd/MM/yyyy");
                task.LastUpdatedOnString = task.LastUpdatedOn.ToString("dd/MM/yyyy");

                foreach (var item2 in task.TaskStatusDetails)
                {
                    item2.StatusUpdationDateTimeString = item2.StatusUpdationDateTime.ToString("dd/MM/yyyy");
                }

                return(Ok(task));
            }
            else
            {
                return(NoContent());
            }
        }
        public IActionResult Post([FromBody] MvcTaskManager.Models.Task task)
        {
            task.Project             = null;
            task.CreatedByUser       = null;
            task.AssignedToUser      = null;
            task.TaskPriority        = null;
            task.TaskStatusDetails   = null;
            task.CreatedOn           = DateTime.Now;
            task.LastUpdatedOn       = DateTime.Now;
            task.CurrentStatus       = "Holding";
            task.CurrentTaskStatusID = 1;
            task.CreatedOnString     = task.CreatedOn.ToString("dd/MM/yyyy");
            task.LastUpdatedOnString = task.LastUpdatedOn.ToString("dd/MM/yyyy");
            task.CreatedBy           = User.Identity.Name;

            db.Tasks.Add(task);
            db.SaveChanges();

            TaskStatusDetail taskStatusDetail = new TaskStatusDetail();

            taskStatusDetail.TaskID                 = task.TaskID;
            taskStatusDetail.UserID                 = task.CreatedBy;
            taskStatusDetail.TaskStatusID           = 1;
            taskStatusDetail.StatusUpdationDateTime = DateTime.Now;
            taskStatusDetail.TaskStatus             = null;
            taskStatusDetail.User        = null;
            taskStatusDetail.Description = "Task Created";
            db.TaskStatusDetails.Add(taskStatusDetail);
            db.SaveChanges();

            MvcTaskManager.Models.Task existingTask = db.Tasks.Where(temp => temp.TaskID == task.TaskID).FirstOrDefault();
            return(Ok(existingTask));
        }
 public IActionResult Updatetask([FromBody] TaskViewModel taskViewModel)
 {
     //Update existing task
     MvcTaskManager.Models.Task existingTask = db.Tasks.Where(temp => temp.TaskID == taskViewModel.TaskID).FirstOrDefault();
     if (existingTask != null)
     {
         existingTask.TaskName       = taskViewModel.TaskName;
         existingTask.Description    = taskViewModel.Description;
         existingTask.ProjectID      = taskViewModel.ProjectID;
         existingTask.TaskPriorityID = taskViewModel.TaskPriorityID;
         existingTask.AssignedTo     = taskViewModel.AssignedTo;
         existingTask.LastUpdatedOn  = DateTime.Now;
         db.SaveChanges();
         return(Ok(taskViewModel));
     }
     else
     {
         return(NoContent());
     }
 }
        public IActionResult UpdateTaskStatus([FromBody] TaskStatusDetail taskStatusDetail)
        {
            //Insert task status detail
            taskStatusDetail.UserID = User.Identity.Name;
            taskStatusDetail.StatusUpdationDateTime       = DateTime.Now;
            taskStatusDetail.StatusUpdationDateTimeString = taskStatusDetail.StatusUpdationDateTime.ToString("dd/MM/yyyy");
            taskStatusDetail.TaskStatus = null;
            taskStatusDetail.User       = null;
            db.TaskStatusDetails.Add(taskStatusDetail);
            db.SaveChanges();

            //Update existing task
            MvcTaskManager.Models.Task existingTask = db.Tasks.Where(temp => temp.TaskID == taskStatusDetail.TaskID).FirstOrDefault();
            existingTask.LastUpdatedOn       = DateTime.Now;
            existingTask.CurrentStatus       = db.TaskStatuses.Where(temp => temp.TaskStatusID == taskStatusDetail.TaskStatusID).FirstOrDefault().TaskStatusName;
            existingTask.CurrentTaskStatusID = taskStatusDetail.TaskStatusID;
            db.SaveChanges();

            return(Ok(taskStatusDetail));
        }