public ActionResult Edit(int id) { var statement = _context.StatementIEs.SingleOrDefault(m => m.Id == id); if (statement == null) { return(HttpNotFound()); } var ies = _context.IncomeExpenditure_StatementIE.SingleOrDefault(m => m.StatementId == id); var proposal = _context.Proposals.SingleOrDefault(m => m.IncomeExpenditureId == ies.IncomeExpenditureId); if (proposal == null || proposal.Submitted) { return(HttpNotFound()); } if (!proposal.IsEditable(User.Identity.GetUserId())) { return(HttpNotFound()); } var viewModel = new StatementIEFormViewModel { StatementIE = statement, Proposal = proposal, }; return(View("Form", viewModel)); }
public ActionResult Save(StatementIEFormViewModel vm, HttpPostedFileBase postedFile) { var proposal = vm.Proposal; proposal = _context.Proposals.SingleOrDefault(m => m.Id == proposal.Id); if (proposal == null || proposal.Submitted) { return(HttpNotFound()); } if (postedFile != null) { vm.StatementIE.Upload = postedFile.FileName.Replace(' ', '_'); } var statement = vm.StatementIE; if (vm.StatementIE.Upload == null) { var viewModel = new StatementIEFormViewModel { Proposal = proposal, StatementIE = statement }; return(View("Form", viewModel)); } if (postedFile != null) { string path = Server.MapPath("~/Uploads/"); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } postedFile.SaveAs(path + Path.GetFileName(postedFile.FileName.Replace(' ', '_'))); } if (statement.Id == 0) { if (postedFile != null) { statement.Upload = postedFile.FileName.Replace(' ', '_'); } _context.StatementIEs.Add(statement); IncomeExpenditure_StatementIE ies = new IncomeExpenditure_StatementIE(); ies.StatementIE = statement; ies.IncomeExpenditure = proposal.IncomeExpenditure; _context.IncomeExpenditure_StatementIE.Add(ies); } else { var statementInDb = _context.StatementIEs.SingleOrDefault(m => m.Id == statement.Id); if (postedFile != null) { statementInDb.Upload = postedFile.FileName.Replace(' ', '_'); } } _context.SaveChanges(); return(RedirectToAction("Index", "IncomeExpenditure", new { id = proposal.Id })); }
public ActionResult New(int id) { var proposal = _context.Proposals.SingleOrDefault(m => m.Id == id); if (proposal == null || proposal.Submitted) { return(HttpNotFound()); } var viewModel = new StatementIEFormViewModel { Proposal = proposal, StatementIE = new StatementIE() }; return(View("Form", viewModel)); }