public async Task EditAsyncShouldReturnCorrectSubProject() { // Arrange var editModel = new SubProjectEditInputModel { Id = 1, Budget = 5000, ProgressStatusId = 3, DueDate = DateTime.Now.AddDays(20), }; var subProject = new SubProject { Id = 1, Budget = 1000, ProgressStatusId = 2, DueDate = DateTime.Now.AddDays(10), }; await this.PlanItDbContext.SubProjects.AddAsync(subProject); await this.PlanItDbContext.SaveChangesAsync(); // Act var expected = new SubProjectEditInputModel { Id = 1, Budget = 5000, ProgressStatusId = 3, DueDate = DateTime.UtcNow.AddDays(20), }; var actual = await this.SubProjectsService .EditAsync <SubProjectEditInputModel>(editModel); // Assert Assert.Equal(expected.Id, actual.Id); Assert.Equal(expected.ProgressStatusId, actual.ProgressStatusId); Assert.Equal(expected.DueDate?.ToString(DateTimeFormat), actual.DueDate?.ToString(DateTimeFormat)); }
public async Task <IActionResult> Edit(int id, SubProjectEditInputModel inputModel) { if (id != inputModel.Id) { return(this.NotFound()); } var project = await this.projectsService .GetByIdAsync <SubProjectProjectViewModel>(inputModel.ProjectId); if (project == null) { return(this.NotFound()); } 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 statuses = await this.progressStatusesService .GetAllAsync <SubProjectProgressStatusViewModel>(); this.ViewData["Statuses"] = statuses; return(this.View(inputModel)); } await this.subProjectsService.EditAsync <SubProjectEditInputModel>(inputModel); await this.projectsService.CalculateProjectBudget(project.Id); return(this.RedirectToAction("Details", "Projects", new { area = "Management", id = project.Id })); }