Beispiel #1
0
        public void Save(CustomerEditorModel model)
        {
            Customer customer = null;

            if (model.Id > 0)
            {
                customer = _customerService.Find(model.Id);
            }
            else
            {
                customer = new Customer();
            }

            customer.Email = model.Email;

            customer.FirstName    = model.FirstName;
            customer.LastName     = model.LastName;
            customer.Group        = model.Group;
            customer.SavingPoints = model.SavingPoints;
            customer.Gender       = model.Gender;

            customer.CustomFields.Clear();

            foreach (var field in model.CustomFields)
            {
                customer.CustomFields.Add(new CustomerCustomField(field.Name, field.Value));
            }

            if (model.Id > 0)
            {
                _customerService.Update(customer);
            }
            else
            {
                _customerService.Create(customer);
            }

            foreach (var address in customer.Addresses.ToList())
            {
                if (!model.Addresses.Any(it => it.Id == address.Id))
                {
                    customer.Addresses.Remove(address);
                }
            }

            foreach (var addressModel in model.Addresses)
            {
                var address = customer.Addresses.FirstOrDefault(it => it.Id == addressModel.Id);
                if (address == null)
                {
                    address = new Address();
                    customer.Addresses.Add(address);
                }

                UpdateAddress(address, addressModel);
            }

            _customerService.Update(customer);
        }
Beispiel #2
0
        public CustomerEditorForm(CustomerEditorModel model)
        {
            InitializeComponent();
            _presenter = new CustomerEditorPresenter(this, model);

            // set validation alignment
            valCode.SetIconAlignment(txtCode, System.Windows.Forms.ErrorIconAlignment.MiddleRight);
            valCompanyName.SetIconAlignment(txtCompanyName, System.Windows.Forms.ErrorIconAlignment.MiddleRight);
            valAddress.SetIconAlignment(txtAddress, System.Windows.Forms.ErrorIconAlignment.MiddleRight);
            valCity.SetIconAlignment(cbCity, System.Windows.Forms.ErrorIconAlignment.MiddleRight);
            valContact.SetIconAlignment(txtContactName, System.Windows.Forms.ErrorIconAlignment.MiddleRight);
            valPhone.SetIconAlignment(txtPhoneNumber, System.Windows.Forms.ErrorIconAlignment.MiddleRight);

            this.Load += CustomerEditorForm_Load;
        }
Beispiel #3
0
        public ActionResult Get(int?id = null)
        {
            CustomerEditorModel model = null;

            if (id != null && id > 0)
            {
                var customer = _customerService.Find(id.Value);
                model = Mapper.Map <Customer, CustomerEditorModel>(customer);
            }
            else
            {
                model = new CustomerEditorModel();
            }

            return(JsonNet(model).UsingClientConvention());
        }