public ActionResult Complete(ReportCompletionViewModel model) { if (ModelState.IsValid) { ReportDAL dal = new ReportDAL(_db); string userId = User.Identity.GetUserId(); Report report = dal.GetLatestUncompletedReport(userId); if (report.OdometerStart >= model.OdometerEnd) { ViewBag.OdometerError = AppString.ErrorOdometerEnd; return(View(model)); } report.OdometerEnd = model.OdometerEnd; report.ToLocation = model.ToLocation; report.Passengers = model.Passengers; report.Debitable = model.Debitable; report.Purpose = model.Purpose; _db.Reports.Attach(report); _db.Entry(report).State = EntityState.Modified; _db.SaveChanges(); return(RedirectToAction("Startup", "Report", new { reportCompleted = true })); } return(View(model)); }
public ActionResult Complete(bool uncompletedExists = false, bool reportStarted = false) { if (reportStarted) { ViewBag.AppMessage = new AppMessage() { Type = AppMessage.Success, Message = AppString.ReportStarted } } ; if (uncompletedExists) { ViewBag.AppMessage = new AppMessage() { Type = AppMessage.Warning, Message = AppString.ReportUncompletedExists } } ; ReportDAL dal = new ReportDAL(_db); string userId = User.Identity.GetUserId(); Report report = dal.GetLatestUncompletedReport(userId); string projectInfo = null; if (report.AssociatedProject.Name == "DefaultProject") { projectInfo = "[ " + AppString.ProjectNotBound + " ]"; } else { projectInfo = report.AssociatedProject.Name + " - " + report.AssociatedProject.ProjectNumber; } ReportCompletionViewModel model = new ReportCompletionViewModel() { Date = report.Date.ToString("yyyy-MM-dd HH:mm"), CarRegistrationNumber = report.AssociatedCar.RegistrationNumber, ProjectInfo = projectInfo, OdometerStart = report.OdometerStart }; return(View(model)); }