Beispiel #1
0
        public async Task <IActionResult> Add(SubProjectAddInputModel 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 subProjectTypes = await this.subProjectTypesService
                                      .GetAllAsync <SubProjectSubProjectTypeViewModel>();

                this.ViewData["Types"] = subProjectTypes;

                return(this.View(inputModel));
            }

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

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

            return(this.RedirectToAction("Details", "Projects", new { area = "Management", id = project.Id }));
        }
Beispiel #2
0
        public async Task <IActionResult> Add(int id)
        {
            var project = await this.projectsService
                          .GetByIdAsync <SubProjectProjectViewModel>(id);

            if (project == null)
            {
                return(this.NotFound());
            }

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

            this.ViewData["Types"] = subProjectTypes;

            var subproject = new SubProjectAddInputModel
            {
                ProjectId = project.Id,
            };

            return(this.View(subproject));
        }