public ActionResult New(int id) { var proposal = _context.Proposals.SingleOrDefault(m => m.Id == id); if (proposal == null) { return(HttpNotFound()); } if (proposal.ProgrammeRationaleId != null) { return(HttpNotFound()); } if (!proposal.IsEditable(User.Identity.GetUserId())) { return(HttpNotFound()); } proposal.IsInEdit = true; proposal.UserEditing = User.Identity.GetUserId(); _context.SaveChanges(); var viewModel = new RationaleFormViewModel { Proposal = proposal, }; return(View("Form", viewModel)); }
public ActionResult Edit(int id) { var proposal = _context.Proposals.SingleOrDefault(c => c.Id == id); if (proposal == null || proposal.Submitted) { return(HttpNotFound()); } if (!proposal.IsEditable(User.Identity.GetUserId())) { return(HttpNotFound()); } proposal.IsInEdit = true; proposal.UserEditing = User.Identity.GetUserId(); _context.SaveChanges(); if (proposal.ProgrammeRationaleId == null) { return(HttpNotFound()); } var pr = _context.ProgrammeRationales.SingleOrDefault(c => c.Id == proposal.ProgrammeRationaleId); var rationale = _context.Rationales.SingleOrDefault(c => c.Id == pr.RationaleId); if (rationale == null) { return(HttpNotFound()); } var viewModel = new RationaleFormViewModel { Proposal = proposal, Rationale = rationale, }; return(View("Form", viewModel)); }
public ActionResult Edit(int id) { var proposal = _context.Proposals.SingleOrDefault(c => c.Id == id); if (proposal == null || proposal.Submitted) { return(HttpNotFound()); } if (proposal.ProgrammeRationaleId == null) { return(HttpNotFound()); } var pr = _context.ProgrammeRationales.SingleOrDefault(c => c.Id == proposal.ProgrammeRationaleId); var rationale = _context.Rationales.SingleOrDefault(c => c.Id == pr.RationaleId); if (rationale == null) { return(HttpNotFound()); } var viewModel = new RationaleFormViewModel { Proposal = proposal, Rationale = rationale, }; return(View("Form", viewModel)); }
public ActionResult New(int id) { var proposal = _context.Proposals.SingleOrDefault(m => m.Id == id); if (proposal == null) { return(HttpNotFound()); } if (proposal.ProgrammeRationaleId != null) { return(HttpNotFound()); } var viewModel = new RationaleFormViewModel { Proposal = proposal, }; return(View("Form", viewModel)); }
public ActionResult Save(RationaleFormViewModel vm) { var rationale = vm.Rationale; var proposal = _context.Proposals.SingleOrDefault(m => m.Id == vm.Proposal.Id); if (proposal == null) { return(HttpNotFound()); } if (!proposal.IsEditable(User.Identity.GetUserId())) { return(HttpNotFound()); } if (proposal.Submitted) { return(Content("Proposal already submitted")); } if (!ModelState.IsValid) { return(View("Form", rationale)); } if (rationale.Id == 0) { Thread t = new Thread(); _context.Threads.Add(t); rationale.Thread = t; _context.Rationales.Add(rationale); ProgrammeRationale pr = new ProgrammeRationale(); pr.RationaleId = rationale.Id; _context.ProgrammeRationales.Add(pr); proposal.ProgrammeRationaleId = pr.Id; proposal.ProgrammeRationale = pr; } else { var rationaleInDb = _context.Rationales.SingleOrDefault(m => m.Id == rationale.Id); rationaleInDb.Justification = rationale.Justification; rationaleInDb.Fit = rationale.Fit; rationaleInDb.Differences = rationale.Differences; } _context.SaveChanges(); var jump = Request["jump"]; switch (jump) { case "0": { // Save pressed -> return form return(RedirectToAction("Edit", "Rationale", new { id = proposal.Id })); } case "-1": { // Previous pressed -> return form return(RedirectToAction("Edit", "General", new { id = proposal.Id })); } case "1": { // Next pressed -> return next page return(RedirectToAction("Jump", "Rationale", new { id = proposal.Id })); } case "2": { //Save and exit return(RedirectToAction("CloseEdit", "Proposal", new { id = proposal.Id })); } case "A": { // A pressed -> go to Section A return(RedirectToAction("Edit", "General", new { id = proposal.Id })); } case "B": { // B pressed -> go to Section B return(RedirectToAction("Jump", "ProgrammeRationale", new { id = proposal.Id })); } case "C": { // C pressed -> go to Section C return(RedirectToAction("Jump", "ExternalReview", new { id = proposal.Id })); } case "D": { // D pressed -> go to Section D return(RedirectToAction("Jump", "IncomeExpenditure", new { id = proposal.Id })); } default: { return(RedirectToAction("Index", "Proposal")); } } }