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;
 }