Ejemplo n.º 1
0
        public async Task CreateAsyncWithNullDueDateShouldReturnCorrectSubProject()
        {
            // Arrange
            var project = new Project
            {
                Id = 2,
                ProgressStatusId = 2,
                DueDate          = DateTime.UtcNow,
            };

            await this.PlanItDbContext.Projects.AddAsync(project);

            await this.PlanItDbContext.SaveChangesAsync();

            var inputModel = new SubProjectCreateInputModel
            {
                SubProjectTypeId = 1,
                ProjectId        = 2,
                Budget           = 3000,
                DueDate          = null,
            };

            // Act
            var expected = new SubProject
            {
                SubProjectTypeId = 1,
                ProjectId        = 2,
                Budget           = 3000,
                DueDate          = DateTime.UtcNow,
                ProgressStatusId = 2,
            };

            var actual = await this.SubProjectsService
                         .CreateAsync <SubProjectCreateInputModel>(inputModel);

            // Assert
            Assert.Equal(expected.SubProjectTypeId, actual.SubProjectTypeId);
            Assert.Equal(expected.ProjectId, actual.ProjectId);
            Assert.Equal(expected.Budget, actual.Budget);
            Assert.Equal(expected.DueDate?.ToString(DateTimeFormat), actual.DueDate?.ToString(DateTimeFormat));
            Assert.Equal(expected.ProgressStatusId, actual.ProgressStatusId);
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Create(SubProjectCreateInputModel inputModel)
        {
            var project = await this.projectsService
                          .GetByIdAsync <SubProjectProjectViewModel>(inputModel.ProjectId);

            if (project == null)
            {
                this.ModelState.AddModelError(string.Empty, "Project does not exist");
            }

            if (project.DueDate != null)
            {
                if (project.DueDate < inputModel.DueDate?.ToUniversalTime() || project.StartDate > inputModel.DueDate?.ToUniversalTime())
                {
                    this.ModelState.AddModelError(string.Empty, "SubProject due date have to be before project due date or after start date");
                }
            }

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

                var subProjectTypes = await this.subProjectTypesService
                                      .GetAllAsync <SubProjectSubProjectTypeViewModel>();

                this.ViewData["My Projects"] = projects;
                this.ViewData["Types"]       = subProjectTypes;

                return(this.View(inputModel));
            }

            await this.subProjectsService.CreateAsync <SubProjectCreateInputModel>(inputModel);

            await this.projectsService.CalculateProjectBudget(project.Id);

            return(this.RedirectToAction("Details", "Projects", new { area = "Management", id = project.Id }));
        }