public Projectify.Models.Task CreateTask(int projectID, int sprintID, Projectify.Models.Task task)
    {
        Project project = _context.Projects.Include(s => s.Sprints).ThenInclude(s => s.Tasks).Where(p => p.ProjectID == projectID).SingleOrDefault();
        Sprint  sprint  = _context.Sprints.Include(s => s.Tasks).Where(s => s.SprintID == sprintID).SingleOrDefault();

        Debug.WriteLine(sprint);
        Projectify.Models.Task newTask = new Projectify.Models.Task()
        {
            TaskName        = task.TaskName,
            TaskPriority    = task.TaskPriority,
            TaskDescription = task.TaskDescription,
            TaskStartedAt   = task.TaskStartedAt,
            TaskEndedAt     = "",
        };
        newTask.Sprint = sprint;

        try
        {
            _context.Tasks.Add(newTask);
            _context.SaveChanges();
            return(newTask);
        }
        catch (Exception e)
        {
            Debug.WriteLine(e.StackTrace);
            return(null);
        }
    }
 public bool DeleteTask(int taskID)
 {
     Projectify.Models.Task task = _context.Tasks.Where(t => t.TaskID == taskID).SingleOrDefault();
     _context.Tasks.Remove(task);
     try
     {
         _context.SaveChanges();
         return(true);
     }
     catch (Exception e)
     {
         Debug.WriteLine(e.StackTrace);
         return(false);
     }
 }
    public IActionResult UpdateTask([FromBody] Object obj)
    {
        Projectify.Models.Task task = JsonSerializer.Deserialize <Task>(obj.ToString());
        bool response = _taskService.UpdateTask(task);

        switch (response)
        {
        case false:
            return(BadRequest(new
            {
                userMessage = "Operation was unsuccessful",
                errorCode = "Something went wrong"
            }));

        default:
            return(NoContent());
        }
        ;
    }
    public bool UpdateTask(Projectify.Models.Task task)
    {
        Debug.WriteLine(task.TaskID);
        Debug.WriteLine(task.TaskName);
        Debug.WriteLine(task.TaskPriority);
        Debug.WriteLine(task.TaskState);
        Debug.WriteLine(task.TaskStartedAt);

        Projectify.Models.Task taskToChange = _context.Tasks.Where(t => t.TaskID == task.TaskID).SingleOrDefault();
        taskToChange.TaskDescription = task.TaskDescription;
        taskToChange.TaskName        = task.TaskName;
        taskToChange.TaskPriority    = task.TaskPriority;
        taskToChange.TaskState       = task.TaskState;
        try
        {
            _context.SaveChanges();
            return(true);
        }
        catch (Exception e)
        {
            Debug.WriteLine(e.StackTrace);
            return(false);
        }
    }
    public bool ChangeTaskState(int taskID, string taskState)
    {
        Projectify.Models.Task task = _context.Tasks.SingleOrDefault(t => t.TaskID == taskID);

        if (taskState == Projectify.Models.Task.TASK_STATES[2])
        {
            try
            {
                _context.Entry(task).Property(t => t.TaskState).CurrentValue = taskState;
                task.TaskEndedAt = DateTime.Now.ToString("dd/MM/YY");
                _context.SaveChangesAsync();
            }

            catch (Exception e)
            {
                Debug.WriteLine(e.StackTrace);
                return(false);
            }
            return(true);
        }
        else
        {
            try
            {
                _context.Entry(task).Property(t => t.TaskState).CurrentValue = taskState;
                _context.SaveChangesAsync();
                return(true);
            }

            catch (Exception e)
            {
                Debug.WriteLine(e.StackTrace);
                return(false);
            }
        }
    }