public async Task <ActionResult> RestoreProjectScheduleVersionToCurrent(int id) { // load ProjectScheduleVersion, confirm it's not null var targetScheduleVersion = await db.ProjectScheduleVersions.FindAsync(id); if (targetScheduleVersion == null) { return(HttpNotFound()); } // authorize user ApplicationUser user = await ReturnCurrentUserAsync(); var parentUserProject = await db.UserProjects.FindAsync(targetScheduleVersion.ProjectID); if (parentUserProject.ApplicationUserID == user.Id) { ProjectScheduleVersionsRepository repo = new ProjectScheduleVersionsRepository(); if (await repo.RestoreArchivedProjectScheduleVersionToCurrent(parentUserProject.ID, targetScheduleVersion.VersionNum)) { Success("Archived Project Schedule (Revision date: " + targetScheduleVersion.SavedAt + ") has been restored as Current Project Schedule.", true); return(RedirectToAction("Details", new { id = parentUserProject.ID })); } } Warning("Update failed.", true); return(RedirectToAction("Details", new { id = id })); }
public async Task <ActionResult> EditScheduleFS(UserProjectViewModel viewModel) { ProjectScheduleVersionsRepository repo = new ProjectScheduleVersionsRepository(); if (await repo.SaveClonedProjectScheduleVersion(viewModel.ProjectScheduleVersion)) { Success("Project schedule updated successfully.", true); return(RedirectToAction("Details", new { id = viewModel.ID })); } Warning("Update failed.", true); return(RedirectToAction("Details", new { id = viewModel.ID })); }
// GET: UserProjects/EditScheduleFS/5 public async Task <ActionResult> EditScheduleFS(int?id, bool deleteAbandonedSchedule = false) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } // load project from db, confirm that it's not null UserProjectsRepository repo = new UserProjectsRepository(); UserProjectViewModel viewModel = await repo.GetUserProject(id); if (viewModel == null) { return(HttpNotFound()); } // authorize user ApplicationUser user = await ReturnCurrentUserAsync(); if (viewModel.ApplicationUserID == user.Id) { ProjectScheduleVersionsRepository scheduleRepo = new ProjectScheduleVersionsRepository(); Tuple <ProjectScheduleVersion, bool> newSchedule = await scheduleRepo.CloneProjectScheduleVersionForEdit(viewModel.ID); if (deleteAbandonedSchedule) { return(RedirectToAction("RemoveProjectScheduleVersion", new { id = newSchedule.Item1.ID })); } viewModel.ProjectScheduleVersion = newSchedule.Item1; viewModel.FullScreen = true; viewModel.ReadOnly = false; viewModel.AbandonedSchedule = newSchedule.Item2; return(View(viewModel)); } else { Danger(unauthorizedAccessMessage, true); return(RedirectToAction("Index")); } }
public async Task <ActionResult> RemoveProjectScheduleVersion(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } // load schedule from db, confirm that it's not null ProjectScheduleVersionsRepository schedulesRepo = new ProjectScheduleVersionsRepository(); var schedule = await schedulesRepo.FindProjectScheduleVersion(id.Value); if (schedule == null) { return(HttpNotFound()); } // load project from db, confirm that it's not null UserProjectsRepository projectsRepo = new UserProjectsRepository(); UserProjectViewModel project = await projectsRepo.GetUserProject(schedule.ProjectID); if (project == null) { return(HttpNotFound()); } // authorize user ApplicationUser user = await ReturnCurrentUserAsync(); if (project.ApplicationUserID == user.Id) { if (await schedulesRepo.RemoveProjectScheduleVersion(id.Value)) { return(RedirectToAction("EditScheduleFS", new { id = project.ID })); } } Danger("Error: Unable to abandon unsaved changes."); return(RedirectToAction("Details", new { id = project.ID })); }