public IActionResult DeleteProject(Guid ProjectId, DeleteProjectViewModel model) { if (!model.ConfirmDelete) { ModelState.AddModelError(nameof(model.ConfirmDelete), "Please confirm the deletion by checking the checkbox."); } if (!ModelState.IsValid) { return View(model); } var documentationProject = Context.DocumentationProjects.FirstOrDefault(Project => Project.Id == model.ProjectId); if (documentationProject == null) { return HttpNotFound(); } if (documentationProject.FolderGuid != Guid.Empty) { // Check if physical files present and if yes, delete them var physicalDirectory = HostingEnvironment.MapPath("App_Data/" + documentationProject.FolderGuid); if (Directory.Exists(physicalDirectory)) { Directory.Delete(physicalDirectory, true); } } Context.DocumentationProjects.Remove(documentationProject); Context.SaveChanges(); ViewBag.SuccessMessage = $"Deleted project {documentationProject.Name}."; return RedirectToAction(nameof(Index)); }
public IActionResult DeleteProject(Guid ProjectId) { var project = Context.DocumentationProjects.FirstOrDefault(Project => Project.Id == ProjectId); if (project == null) { return HttpNotFound(); } var model = new DeleteProjectViewModel(); model.ProjectName = project.Name; model.ProjectId = project.Id; return View(model); }