예제 #1
0
        public async Task <IActionResult> GetUserTasksByTaskId(Guid taskId)
        {
            User loggedOnUser = await _identityBusiness.GetUserAsync(User);

            Task userTask = await _taskBookBusiness.GetUsersTaskByUserAndTaskId(loggedOnUser.Id, taskId);

            if (userTask == null)
            {
                return(NotFound());
            }

            var model = _mapper.Map <TaskViewModel>(userTask);

            return(Ok(model));
        }
예제 #2
0
        public async Task <IActionResult> CreateTaskAssignment(Guid?taskId)
        {
            if (!taskId.HasValue)
            {
                return(BadRequest());
            }

            User loggedOnUser = await _identityBusiness.GetUserAsync(User);

            Task userTask = await _taskBookBusiness.GetUsersTaskByUserAndTaskId(loggedOnUser.Id, taskId.Value);

            if (userTask == null)
            {
                return(NotFound());
            }

            if (userTask.AssignedToUserId.HasValue)
            {
                if (userTask.AssignedToUserId != loggedOnUser.Id)
                {
                    return(Conflict("Task has already been assigned to a different assignee."));
                }

                if (userTask.DateTimeCompleted.HasValue)
                {
                    return(Conflict("Cannot create task assignment for a completed task."));
                }

                Task existing = await _taskBookBusiness.GetUsersTaskAssignmentByUserAndTaskId(loggedOnUser.Id, taskId.Value);

                var existingModel = _mapper.Map <TaskViewModel>(existing);

                return(Ok(existingModel));
            }

            Task assignedTask = await _taskBookBusiness.CreateTaskAssignmen(loggedOnUser.Id, taskId.Value);

            var model = _mapper.Map <TaskViewModel>(assignedTask);

            return(CreatedAtRoute(nameof(GetUserTaskAssignmentByTaskId), new { TaskId = assignedTask.Id }, model));
        }
        public async Task <IActionResult> CreateTaskCompletion(Guid?taskId)
        {
            if (!taskId.HasValue)
            {
                return(BadRequest());
            }

            User loggedOnUser = await _identityBusiness.GetUserAsync(User);

            Task userTask = await _taskBookBusiness.GetUsersTaskByUserAndTaskId(loggedOnUser.Id, taskId.Value);

            if (userTask == null)
            {
                return(NotFound());
            }

            if (!userTask.AssignedToUserId.HasValue)
            {
                return(Conflict("There should be a task assignment before task completion."));
            }

            if (userTask.AssignedToUserId != loggedOnUser.Id)
            {
                return(Conflict("Assignment to another assignee exists."));
            }

            if (userTask.DateTimeCompleted.HasValue)
            {
                Task existing = await _taskBookBusiness.GetUsersTaskCompletionByUserAndTaskId(loggedOnUser.Id, taskId.Value);

                var existingModel = _mapper.Map <TaskViewModel>(existing);
                return(Ok(existingModel));
            }

            Task completedTask = await _taskBookBusiness.CreateTaskCompletion(loggedOnUser.Id, taskId.Value);

            var model = _mapper.Map <TaskViewModel>(completedTask);

            return(CreatedAtRoute(nameof(GetUserTaskCompletionByTaskId), new { TaskId = completedTask.Id }, model));
        }