public ActionResult Save(EditSalesOrderHeaderTempViewModel model, string command) { switch (command.ToLower()) { case "save": // Save the screen data back to the temp tables, then copy to live tables and exit if (ModelState.IsValid) { adjustDates(model.SaleTemp, model.TZ); var modelError = new Error(); var items = SalesService.FindSalesOrderDetailTempsListModel(CurrentCompany.Id, model.SaleTemp.Id, 0, 1, 9999, ""); if (items.Items.Count() == 0) { prepareEditModel(model, model.SaleTemp.Id); model.SetErrorOnField(ErrorIcon.Error, EvolutionResources.errCantSaveSaleWithNoLines, "SaleTemp_EndUserName"); return(View("Edit", model)); } else { modelError = SalesService.InsertOrUpdateSalesOrderHeaderTemp(model.SaleTemp, CurrentUser, model.LGST, false); if (modelError.IsError) { prepareEditModel(model, model.SaleTemp.Id); model.SetErrorOnField(ErrorIcon.Error, modelError.Message, "SaleTemp_" + modelError.FieldName); return(View("Edit", model)); } else { // Copy the temp tables back to the main tables modelError = SalesService.CopyTempToSalesOrderHeader(model.SaleTemp.Id, CurrentUser, model.LGS); if (modelError.IsError) { prepareEditModel(model, model.SaleTemp.Id); model.SetErrorOnField(ErrorIcon.Error, modelError.Message, "SaleTemp_" + modelError.FieldName); } else { if (model.SaleTemp.OverrideApproverId != null) { // Send override approbal notification var sohm = SalesService.FindSalesOrderHeaderModel(modelError.Id, CurrentCompany, false); SalesService.SendMSQOverrideEMail(CurrentCompany, CurrentUser, MembershipManagementService.FindUserModel(model.SaleTemp.OverrideApproverId.Value), sohm); // Update the temp record so that we don't send a second approval email model.SaleTemp.OverrideApproverId = null; SalesService.InsertOrUpdateSalesOrderHeaderTemp(model.SaleTemp, CurrentUser, SalesService.LockSalesOrderHeaderTemp(model.SaleTemp), false); } return(RedirectToAction("Sales")); } } } } prepareEditModel(model, model.SaleTemp.Id); return(View("Edit", model)); default: return(RedirectToAction("Sales")); } }