public ActionResult Save(EditPurchaseOrderHeaderTempViewModel 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.PurchaseTemp, model.TZ);

                    var modelError = PurchasingService.InsertOrUpdatePurchaseOrderHeaderTemp(model.PurchaseTemp, CurrentUser, model.LGST);
                    if (modelError.IsError)
                    {
                        model.Error.SetError(modelError.Message,
                                             "Purchase_" + modelError.FieldName);
                    }
                    else
                    {
                        // Copy the temp tables back to the main tables
                        modelError = PurchasingService.CopyTempToPurchaseOrderHeader(model.PurchaseTemp.Id, CurrentUser, model.LGS);
                        if (modelError.IsError)
                        {
                            prepareEditModel(model, model.PurchaseTemp.Id);
                            model.Error.SetError(modelError.Message,
                                                 "Purchase_" + modelError.FieldName);
                        }
                        else
                        {
                            return(RedirectToAction("Purchases"));
                        }
                    }
                }
                prepareEditModel(model, model.PurchaseTemp.Id);
                return(View("Edit", model));

            default:
                return(RedirectToAction("Index", "Purchasing", new { area = "Purchasing" }));
            }
        }