Exemple #1
0
        public CustomerViewModel GetCustomerById(int id)
        {
            var customerViewModel = new CustomerViewModel();
            var cust = new EfDbContext.Customer();

            try
            {
                using (_dbContext = new AccountdbContext())
                {
                    //cust = _dbContext.Customer.Where(e => e.CustId.Equals(id)).FirstOrDefault();
                    customerViewModel = (from c in _dbContext.Customer
                                         join cd in _dbContext.CustomerDetails on c.CustId equals cd.CustId
                                         where c.CustId == id
                                         select ConstructCustomerViewModelFromContext(c, cd)
                                         ).FirstOrDefault();
                }
                //customerViewModel = ConstructCustomerViewModelFromContext(cust);
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(customerViewModel);
        }
Exemple #2
0
        private static CustomerViewModel ConstructCustomerViewModelFromContext(EfDbContext.Customer c, EfDbContext.CustomerDetails cd)
        {
            return(new CustomerViewModel()
            {
                id = c.CustId,
                nickName = c.NickName,
                firstName = c.FirstName,
                middleName = c.MiddleName,
                lastName = c.LastName,
                mobile = c.Mobile,
                referredBy = c.ReferredBy,
                createdDate = c.CreatedDate,
                formattedCreatedDate = c.CreatedDate.ToString(_dateFormat),
                createdBy = c.CreatedBy,
                modifiedDate = c.ModifiedDate,
                formattedModifiedDate = c.ModifiedDate.ToString(_dateFormat),
                modifiedBy = c.ModifiedBy,

                alternateMobile = cd.AlternateMobile,
                homePhone = cd.HomePhone,
                officePhone = cd.OfficePhone,
                email = cd.Email,
                address = cd.Address,
                city = cd.City,
                state = cd.State,
                shopName = cd.ShopName,
                shopLocation = cd.ShopLocation
            });
        }
Exemple #3
0
 private CustomerViewModel ConstructCustomerViewModelFromContext(EfDbContext.Customer item)
 {
     return(new CustomerViewModel
     {
         firstName = item.FirstName,
         lastName = item.LastName,
         middleName = item.MiddleName,
         id = HelperUtility.ConvertLongToInt(item.CustId),
         mobile = item.Mobile
     });
 }
Exemple #4
0
        public CommonResponseViewModel AddCustomer(CustomerViewModel customerVM)
        {
            CommonResponseViewModel response = new CommonResponseViewModel();

            try
            {
                var cust = new EfDbContext.Customer();
                cust.FirstName  = customerVM.firstName;
                cust.MiddleName = customerVM.middleName;
                cust.NickName   = customerVM.nickName;
                cust.LastName   = customerVM.lastName;
                cust.Mobile     = customerVM.mobile;
                cust.ReferredBy = customerVM.referredBy;
                cust.CreatedBy  = customerVM.createdBy;
                cust.ModifiedBy = customerVM.modifiedBy;

                using (_dbContext = new AccountdbContext())
                {
                    //Save the customer entity first........
                    _dbContext.Customer.Add(cust);
                    _dbContext.SaveChanges();

                    response.isSuccess = true;
                    //update the custid from db to viewModel............................
                    response.recordId = cust.CustId;
                    customerVM.id     = response.recordId;

                    EfDbContext.CustomerDetails customerDetails = new EfDbContext.CustomerDetails()
                    {
                        CustId          = customerVM.id,
                        AlternateMobile = customerVM.alternateMobile,
                        HomePhone       = customerVM.homePhone,
                        OfficePhone     = customerVM.officePhone,
                        Email           = customerVM.email,
                        Address         = customerVM.address,
                        City            = customerVM.city,
                        State           = customerVM.state,
                        ShopName        = customerVM.shopName,
                        ShopLocation    = customerVM.shopLocation
                    };

                    _dbContext.CustomerDetails.Add(customerDetails);
                    _dbContext.SaveChanges();

                    //Loop all the address list and update the address in the db....................
                    //if (customerVM.CustAddressList != null && customerVM.CustAddressList.Any())
                    //{
                    //    foreach (var item in customerVM.CustAddressList)
                    //    {
                    //        _dbContext.CustomerDetails.Add(ConstructCustAddressAsPerContext(item, customerVM.id));
                    //    }
                    //}
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(response);
        }