public ActionResult Manage(string id, EditMode mode) { Employee currentUser = _session.GetCurrentUser(); ExpenseReport expenseReport; if (mode == EditMode.New) { expenseReport = _expenseReportBuilder.Build(currentUser); if (!string.IsNullOrEmpty(id)) { expenseReport.Number = id; } } else { expenseReport = _bus.Send(new ExpenseReportByNumberQuery { ExpenseReportNumber = id }).Result; } ExpenseReportManageModel model = CreateViewModel(mode, expenseReport); model.IsReadOnly = !_workflowFacilitator.GetValidStateCommands(new ExecuteTransitionCommand(expenseReport, null, currentUser, _calendar.GetCurrentTime())).Any(); ViewBag.ExpenseReport = expenseReport; ViewBag.CurrentUser = currentUser; return(View("Manage", model)); }
public ActionResult Manage(ExpenseReportManageModel model, string command) { Employee currentUser = _session.GetCurrentUser(); ExpenseReport expenseReport; if (model.Mode == EditMode.New) { expenseReport = _expenseReportBuilder.Build(currentUser); } else { expenseReport = _expenseReportRepository.GetSingle(model.ExpenseReportNumber); } if (!ModelState.IsValid) { ViewBag.ExpenseReport = expenseReport; ViewBag.CurrentUser = currentUser; return(View("Manage", model)); } Employee practiceOwner = _employeeRepository.GetByUserName(model.ApproverUserName); Employee accountManager = _employeeRepository.GetByUserName(model.SubmitterUserName); expenseReport.Number = model.ExpenseReportNumber; expenseReport.Submitter = accountManager; expenseReport.Approver = practiceOwner; expenseReport.Title = model.Title; expenseReport.Description = model.Description; return(new ExecuteCommandResult(expenseReport, command)); }
public ActionResult Manage(string id, EditMode mode) { Employee currentUser = _session.GetCurrentUser(); ExpenseReport expenseReport; if (mode == EditMode.New) { expenseReport = _expenseReportBuilder.Build(currentUser); if (!string.IsNullOrEmpty(id)) { expenseReport.Number = id; } } else { expenseReport = _expenseReportRepository.GetSingle(id); } ExpenseReportManageModel model = CreateViewModel(mode, expenseReport); model.IsReadOnly = !_workflowFacilitator.GetValidStateCommands(expenseReport, currentUser).Any(); ViewBag.ExpenseReport = expenseReport; ViewBag.CurrentUser = currentUser; return(View("Manage", model)); }
public ActionResult Manage(ExpenseReportManageModel model, string command) { Employee currentUser = _session.GetCurrentUser(); ExpenseReport expenseReport; if (model.Mode == EditMode.New) { expenseReport = _expenseReportBuilder.Build(currentUser); } else { expenseReport = _bus.Send(new ExpenseReportByNumberQuery { ExpenseReportNumber = model.ExpenseReportNumber }).Result; } if (!ModelState.IsValid) { ViewBag.ExpenseReport = expenseReport; ViewBag.CurrentUser = currentUser; return(View("Manage", model)); } Employee approver = _bus.Send(new EmployeeByUserNameQuery(model.ApproverUserName)).Result; Employee submitter = _bus.Send(new EmployeeByUserNameQuery(model.SubmitterUserName)).Result; expenseReport.Number = model.ExpenseReportNumber; expenseReport.Submitter = submitter; expenseReport.Approver = approver; expenseReport.Title = model.Title; expenseReport.Description = model.Description; expenseReport.Total = model.Total; var transitionCommand = new ExecuteTransitionCommand(expenseReport, command, currentUser, _calendar.GetCurrentTime()); ExecuteTransitionResult transitionResult = _bus.Send(transitionCommand); if (transitionResult.NextStep == NextStep.Dashboard) { return(Redirect("~/Home")); } return(RedirectToAction("Manage", new { id = expenseReport.Number, mode = "edit" })); }
private ExpenseReportManageModel CreateViewModel(EditMode mode, ExpenseReport expenseReport) { var model = new ExpenseReportManageModel { ExpenseReport = expenseReport, Mode = mode, ExpenseReportNumber = expenseReport.Number, Status = expenseReport.FriendlyStatus, SubmitterUserName = expenseReport.Submitter.UserName, SubmitterFullName = expenseReport.Submitter.GetFullName(), ApproverUserName = expenseReport.Approver != null ? expenseReport.Approver.UserName : "", Title = expenseReport.Title, Description = expenseReport.Description, CanReassign = UserCanChangeAssignee(expenseReport), Total = expenseReport.Total, }; return(model); }