public async Task <IActionResult> Assign(TaskAssignInputModel inputModel)
        {
            var subProject = await this.subProjectsService
                             .GetByIdAsync <TaskAssignSubProjectViewModel>(inputModel.SubProjectId);

            if (subProject == null)
            {
                this.ModelState.AddModelError(string.Empty, "Project part doesn`t exist!");
            }

            var user = await this.userManager.FindByIdAsync(inputModel.UserId);

            if (user == null)
            {
                this.ModelState.AddModelError(string.Empty, "User is not assigned!");
            }

            var selectedProject = await this.projectsService
                                  .GetByIdAsync <TaskAssignProjectViewModel>(inputModel.ProjectId);

            if (selectedProject == null)
            {
                this.ModelState.AddModelError(string.Empty, "Project doesn`t exist!");
            }

            if (inputModel.DueDate != null)
            {
                if (inputModel.DueDate?.ToUniversalTime() > subProject.DueDate)
                {
                    this.ModelState.AddModelError(string.Empty, $"Due date has to be before project part Due date");
                }
            }

            if (!this.ModelState.IsValid)
            {
                var projects = await this.GetProjects(this.User);

                var selectUsers = await this.SelectUsersAsync(this.User);

                this.ViewData["Projects"] = projects;
                this.ViewData["Project"]  = selectedProject;
                this.ViewData["Users"]    = selectUsers;

                return(this.View(inputModel));
            }

            await this.problemsService.AssignAsync <TaskAssignInputModel>(user, inputModel);

            return(this.RedirectToAction(nameof(this.Index)));
        }
        public async Task AssignAsyncShouldAssignCorrectly()
        {
            // Arrange
            var inputProblem = new TaskAssignInputModel
            {
                Name         = "First",
                Instructions = "Draw",
                SubProjectId = 2,
                DueDate      = DateTime.Now,
                HourlyRate   = 25,
            };

            var status = new ProgressStatus
            {
                Name = GlobalConstants.ProgressStatusAssigned,
            };

            await this.PlanItDbContext.ProgressStatuses.AddAsync(status);

            await this.PlanItDbContext.SaveChangesAsync();

            var user = new PlanItUser
            {
                Id = "First",
            };

            // Act
            var expected = new Problem
            {
                Id             = 1,
                Name           = "First",
                Instructions   = "Draw",
                SubProjectId   = 2,
                DueDate        = DateTime.UtcNow,
                HourlyRate     = 25,
                ProgressStatus = new ProgressStatus
                {
                    Name = GlobalConstants.ProgressStatusAssigned,
                },
                UserProblems = new List <UserProblem>
                {
                    new UserProblem
                    {
                        PlanItUserId = "First",
                        ProblemId    = 1,
                    },
                },
            };

            var actual = await this.ProblemsService
                         .AssignAsync <TaskAssignInputModel>(user, inputProblem);

            // Assert
            Assert.Equal(expected.Name, actual.Name);
            Assert.Equal(expected.Instructions, actual.Instructions);
            Assert.Equal(expected.SubProjectId, actual.SubProjectId);
            Assert.Equal(expected.DueDate?.ToString(DateTimeFormat), actual.DueDate?.ToString(DateTimeFormat));
            Assert.Equal(expected.HourlyRate, actual.HourlyRate);
            Assert.Equal(expected.ProgressStatus.Name, actual.ProgressStatus.Name);
            Assert.Equal(expected.UserProblems.First().PlanItUserId, actual.UserProblems.First().PlanItUserId);
            Assert.Equal(expected.UserProblems.First().ProblemId, actual.UserProblems.First().ProblemId);
        }