Example #1
0
        public ActionResult AddOrEditCustomer(Models.ViewModels.Sales.EditCustomer model)
        {
            Customer customer = null;

            if (model.Id != 0)
            {
                customer = _salesService.GetCustomerById(model.Id);
            }
            else
            {
                customer = new Customer();
            }

            customer.Name = model.Name;
            if (model.PrimaryContactId != -1)
            {
                customer.PrimaryContactId = model.PrimaryContactId;
            }
            customer.AccountsReceivableAccountId = model.AccountsReceivableAccountId.Value == -1 ? null : model.AccountsReceivableAccountId;
            customer.SalesAccountId                 = model.SalesAccountId.Value == -1 ? null : model.SalesAccountId;
            customer.SalesDiscountAccountId         = model.SalesDiscountAccountId.Value == -1 ? null : model.SalesDiscountAccountId;
            customer.PromptPaymentDiscountAccountId = model.PromptPaymentDiscountAccountId.Value == -1 ? null : model.PromptPaymentDiscountAccountId;
            customer.CustomerAdvancesAccountId      = model.CustomerAdvancesAccountId.Value == -1 ? null : model.CustomerAdvancesAccountId;

            if (model.Id != 0)
            {
                _salesService.UpdateCustomer(customer);
            }
            else
            {
                _salesService.AddCustomer(customer);
            }

            return(RedirectToAction("Customers"));
        }
Example #2
0
        public ActionResult AddOrEditCustomer(int id = 0)
        {
            Models.ViewModels.Sales.EditCustomer model = new Models.ViewModels.Sales.EditCustomer();
            var accounts = _financialService.GetAccounts();

            if (id != 0)
            {
                var customer = _salesService.GetCustomerById(id);
                model.Id                             = customer.Id;
                model.Name                           = customer.Name;
                model.PrimaryContactId               = customer.PrimaryContactId.HasValue ? customer.PrimaryContactId.Value : -1;
                model.AccountsReceivableAccountId    = customer.AccountsReceivableAccountId.HasValue ? customer.AccountsReceivableAccountId : -1;
                model.SalesAccountId                 = customer.SalesAccountId.HasValue ? customer.SalesAccountId : -1;
                model.SalesDiscountAccountId         = customer.SalesDiscountAccountId.HasValue ? customer.SalesDiscountAccountId : -1;
                model.PromptPaymentDiscountAccountId = customer.PromptPaymentDiscountAccountId.HasValue ? customer.PromptPaymentDiscountAccountId : -1;
            }
            return(View(model));
        }
Example #3
0
 public ActionResult AddOrEditCustomer(int id = 0)
 {
     Models.ViewModels.Sales.EditCustomer model = new Models.ViewModels.Sales.EditCustomer();
     var accounts = _financialService.GetAccounts();
     if (id != 0)
     {
         var customer = _salesService.GetCustomerById(id);
         model.Id = customer.Id;
         model.Name = customer.Name;
         model.PrimaryContactId = customer.PrimaryContactId.HasValue ? customer.PrimaryContactId.Value : -1;
         model.AccountsReceivableAccountId = customer.AccountsReceivableAccountId.HasValue ? customer.AccountsReceivableAccountId : -1;
         model.SalesAccountId = customer.SalesAccountId.HasValue ? customer.SalesAccountId : -1;
         model.SalesDiscountAccountId = customer.SalesDiscountAccountId.HasValue ? customer.SalesDiscountAccountId : -1;
         model.PromptPaymentDiscountAccountId = customer.PromptPaymentDiscountAccountId.HasValue ? customer.PromptPaymentDiscountAccountId : -1;
     }
     return View(model);
 }