public IActionResult EditProjectSubmit(EditProjectVm model) { var prAll = dbContext.Projects .Include(p => p.Attachments) .ToList(); var updatePr = prAll.FirstOrDefault(p => p.Id == model.Id); var startRes = DateParsers.ddMMyyyy(model.Start); if (startRes.IsValid) { DateTime dateStart = new DateTime(startRes.Value.Year, startRes.Value.Month, startRes.Value.Day); updatePr.Start = dateStart; } var endRes = DateParsers.ddMMyyyy(model.End); var endtimeRes = DateParsers.HHmm(model.EndTime); DateTime dateEnd = default; if (endRes.IsValid) { dateEnd = new DateTime(startRes.Value.Year, startRes.Value.Month, startRes.Value.Day); } if (endtimeRes.IsValid) { dateEnd = dateEnd.AddHours(endtimeRes.Value.Hour); dateEnd = dateEnd.AddMinutes(endtimeRes.Value.Minute); } if (endRes.IsValid || endtimeRes.IsValid) { updatePr.End = dateEnd; } var type = this.dbContext.Types.FirstOrDefault(t => t.Id == model.TypeId); updatePr.Title = model.Title; updatePr.Description = model.Description; updatePr.Organization = model.Organization; updatePr.Link = model.Link; updatePr.ProjectTypeId = type.Id; updatePr.Updated = DateTime.Now; dbContext.Update(updatePr); dbContext.SaveChanges(); return(RedirectToAction(nameof(Index))); }
public async Task <IActionResult> Edit(int id) { // Summary // // Fetch associated project by Id and render view var vm = new EditProjectVm { Project = await _projectsApi.GetProjectAsync(id).ConfigureAwait(false) }; return(View("EditProjectForm", vm)); }
public IActionResult EditProject(Guid Id) { var prAll = dbContext.Projects .Include(p => p.Attachments) .Include(p => p.ProjectType) .Include(p => p.Skills) .ToList(); var updatePr = prAll.FirstOrDefault(p => p.Id == Id); var allTypes = this.dbContext.Types.ToList(); var model = new EditProjectVm() { Id = updatePr.Id, Title = updatePr.Title, Description = updatePr.Description, Organization = updatePr.Organization, End = ParseDateForProject.GetDateTimeForProgect(updatePr), Start = updatePr.Start != null || updatePr.Start.HasValue ? updatePr.Start.Value.ToString("dd.MM.yyyy") : "", Role = updatePr.Role, Link = string.IsNullOrEmpty(updatePr.Link) ? "" : updatePr.Link, // Skills = updatePr.Skills != null || updatePr.Skills.Count != 0 ? string.Join(", ", updatePr.Skills.Select(s => s.Name).ToArray()) : "", AttachmentVm = updatePr.Attachments.Select(f => new FileVm() { Id = f.Id, File = f.File, FileName = f.FileName }).ToList(), SkillsVm = updatePr.Skills == null ? new List <SkillVm>() : updatePr.Skills.Select(s => new SkillVm() { Id = s.Id, SkillName = s.Name }).ToList(), ProjectType = updatePr.ProjectType.NameType, Create = updatePr.Created.ToString("dd.MM.yyyy"), Update = updatePr.Updated.ToString("dd.MM.yyyy"), Types = allTypes.Select(t => new SelectListItem { Value = t.Id.ToString(), Text = t.NameType }).ToList() }; return(View("/Views/Projects/EditProject.cshtml", model)); }
public async Task <IActionResult> Save(EditProjectVm vm) { // Summary // // Validate form submission, call api, then return detail view if (!ModelState.IsValid) { return(View("Edit", vm)); } var project = vm.Project; var apiResponse = await _projectsApi.PutProjectAsync(project.Id, project).ConfigureAwait(false); if (!apiResponse.IsSuccessStatusCode) { _logger.LogInformation($"Failed to update Project {project.Id}"); } project = await _projectsApi.GetProjectAsync(project.Id); return(View("Detail", project)); }