Пример #1
0
        public void AddCustom(CustomerAddUpdateViewModel model)
        {
            var customer = new Customer
            {
                OrganizationName = model.OrganizationName,
                CustomerName     = model.CustomerName,
                CustomerAddress  = model.CustomerAddress,
                Description      = model.Description,
                DueLimit         = model.DueLimit,
                IsIndividual     = model.IsIndividual,
                Designation      = model.Designation,
                CustomerPhone    = model.PhoneNumbers.Select(p => new CustomerPhone
                {
                    Phone     = p.Phone,
                    IsPrimary = p.IsPrimary
                }).ToList()
            };

            if (model.Photo != null && model.Photo.Length > 0)
            {
                customer.Photo = model.Photo;
            }

            Add(customer);
        }
Пример #2
0
        public void CustomUpdate(CustomerAddUpdateViewModel model)
        {
            var customer = Context.Customer.Include(c => c.CustomerPhone).FirstOrDefault(c => c.CustomerId == model.CustomerId);

            if (customer == null)
            {
                return;
            }
            if (model.Photo != null && model.Photo.Length > 0)
            {
                customer.Photo = model.Photo;
            }

            customer.CustomerAddress  = model.CustomerAddress;
            customer.CustomerName     = model.CustomerName;
            customer.OrganizationName = model.OrganizationName;
            customer.Description      = model.Description;
            customer.DueLimit         = model.DueLimit;
            customer.Designation      = model.Designation;
            customer.IsIndividual     = model.IsIndividual;
            customer.CustomerPhone    = model.PhoneNumbers.Select(p => new CustomerPhone
            {
                CustomerPhoneId = p.CustomerPhoneId.GetValueOrDefault(),
                Phone           = p.Phone,
                IsPrimary       = p.IsPrimary ?? false,
                InsertDate      = DateTime.Now
            }).ToList();
            Context.Customer.Update(customer);
        }