Пример #1
0
        public ActionResult SaveCustomer(CustomerModel model) {
            Customer customer
                ;
            try {
                customer = new Customer();
                customer.id = model.id;
                customer.Name = model.Name;
                customer.Address = model.Address;
                customer.Address2 = model.Address2;
                customer.City = model.City;
                customer.State = model.State;
                customer.Zip = model.Zip;
                customer.Tax = model.Tax;
                customer.Phone = model.Phone;
                customer.ImageUrl = model.ImageUrl;

                // Image
                if (model.Image != null) {
                    if (customer.id == 0)
                        customer.ImageUrl = Path.GetExtension(model.Image.FileName);
                    else
                        customer.ImageUrl = String.Format("{0}{1}", model.id, Path.GetExtension(model.Image.FileName));
                }

                Int32 result = _customerService.SaveCustomer(customer);
                if (result == 0)
                    return RedirectToAction("Index", "Error");
                SessionData.customer = customer;

                String fileName = (model.Image == null ? model.ImageUrl : model.Image.FileName);
                String path = Path.Combine(Server.MapPath("~/Images/Menus/"), SessionData.customer.id.ToString(), "Customers", String.Format("{0}{1}", result, Path.GetExtension(fileName)));
                if (model.Image == null && model.ImageUrl == null) {
                    if (System.IO.File.Exists(path)) {
                        System.IO.File.Delete(path);
                    }
                }
                else if (model.Image != null) {
                    model.Image.SaveAs(path);
                }
                SaveSetting(Common.Settings.Language, model.SelectedLanguage);
                SaveSetting(Common.Settings.PrinterPOS, model.PrinterPOS);
                SaveSetting(Common.Settings.PrinterKitchen, model.PrinterKitchen);
                SaveSetting(Common.Settings.PrinterPOSWidth, ((Int32)(Common.PrinterWidth)Enum.Parse(typeof(Common.PrinterWidth), model.PrinterPOSWidth)).ToString());
                SaveSetting(Common.Settings.PrinterKitchenWidth, ((Int32)(Common.PrinterWidth)Enum.Parse(typeof(Common.PrinterWidth), model.PrinterKitchenWidth)).ToString());
                return RedirectToAction("Index", "Login");
            }
            catch (Exception ex) {
                base.Log(ex);
            }
            finally {
            }
            return null;
        }
Пример #2
0
        private CustomerModel GetModel(Int32? id) {
            CustomerModel model;

            try {
                model = new CustomerModel();
                model.States = Utility.States.ToSelectListItems();
                if (SessionData.printers == null) {
                    SessionData.printers = new String[] { "None" };
                }

                model.Printers = SessionData.printers.Select(r => new SelectListItem { Text = r, Value = r });
                model.PrinterWidth = Enum.GetValues(typeof(Common.PrinterWidth)).Cast<Common.PrinterWidth>().Select(r => new SelectListItem { Text = EnumHelper<Common.PrinterWidth>.GetDisplayValue(r), Value = r.ToString() });
                model.Languages = Enum.GetValues(typeof(Common.Languages)).Cast<Common.Languages>().Select(r => new SelectListItem { Value = ((Int32)r).ToString(), Text = r.ToString() });
                if (id != null && id.HasValue) {
                    Customer customer = _customerService.GetCustomer(id.Value);
                    model.id = customer.id;
                    model.Name = customer.Name;
                    model.Address = customer.Address;
                    model.Address2 = customer.Address2;
                    model.City = customer.City;
                    model.State = customer.State;
                    model.Zip = customer.Zip;
                    model.Tax = customer.Tax.HasValue ? customer.Tax.Value : 0;
                    model.Phone = customer.Phone.FormatPhone();
                    model.ImageUrl = customer.ImageUrl;
                    model.PrinterKitchen = _settingsService.GetSettings(SessionData.customer.id, Common.Settings.PrinterKitchen);
                    model.PrinterPOS = _settingsService.GetSettings(SessionData.customer.id, Common.Settings.PrinterPOS);
                    model.PrinterKitchenWidth = ((Common.PrinterWidth)Convert.ToInt32(_settingsService.GetSettings(SessionData.customer.id, Common.Settings.PrinterKitchenWidth))).ToString();
                    model.PrinterPOSWidth = ((Common.PrinterWidth)Convert.ToInt32(_settingsService.GetSettings(SessionData.customer.id, Common.Settings.PrinterPOSWidth))).ToString();
                    model.Modules = _customerService.GetModulesAll();
                    model.SelectedLanguage = _settingsService.GetSettings(SessionData.customer.id, Common.Settings.Language);
                    model.CustomerModules = customer.CustomerModules.Where(cm => cm.EndDate == null).Select(m => m.ModulePriceId).ToArray();
                }
                return model;
            }
            catch (Exception ex) {
                base.Log(ex);
            }
            finally {
            }
            return null;
        }