Exemplo n.º 1
0
        public ResponseDTO UpdateCustomer(CustomerDto customerDto)
        {
            ResponseDTO responseDTO = new ResponseDTO();

            var customer = unitOfWork.CustomerRepository.GetById(customerDto.CustomerId);

            if (customer != null)
            {
                CustomerConvertor.ConvertToCustomerEntity(ref customer, customerDto, true);

                customer.ModifiedDate = DateTimeHelper.GetISTDateTime();
                customer.ModifiedBy   = unitOfWork.VLCRepository.GetEmployeeNameByVLCId(customer.VLCId.GetValueOrDefault());

                unitOfWork.CustomerRepository.Update(customer);
                unitOfWork.SaveChanges();

                responseDTO.Status  = true;
                responseDTO.Message = String.Format("Customer Updated Successfully");
                responseDTO.Data    = CustomerConvertor.ConvertToCustomerDto(customer);
            }
            else
            {
                responseDTO.Message = "Customer Account Not Found with Customer Id. Please try to update again.";
                responseDTO.Status  = false;
            }
            return(responseDTO);
        }
Exemplo n.º 2
0
        public CustomerDto GetCustomerById(int customerId)
        {
            CustomerDto customerDto = null;
            var         customer    = unitOfWork.CustomerRepository.GetById(customerId);

            if (customer != null)
            {
                customerDto = CustomerConvertor.ConvertToCustomerDto(customer);
            }
            return(customerDto);
        }
Exemplo n.º 3
0
        public List <CustomerDto> GetAllCustomers()
        {
            List <CustomerDto> customerList = new List <CustomerDto>();
            var customers = unitOfWork.CustomerRepository.GetAll();

            if (customers != null)
            {
                foreach (var customer in customers)
                {
                    customerList.Add(CustomerConvertor.ConvertToCustomerDto(customer));
                }
            }

            return(customerList);
        }
Exemplo n.º 4
0
        public List <CustomerDto> GetCustomerByPageCount(int?pageNumber, int?count)
        {
            List <CustomerDto> customerList = new List <CustomerDto>();
            var customers = unitOfWork.CustomerRepository.GetCustomerByCount(pageNumber, count);

            if (customers != null)
            {
                foreach (var customer in customers)
                {
                    customerList.Add(CustomerConvertor.ConvertToCustomerDto(customer));
                }
            }

            return(customerList);
        }
Exemplo n.º 5
0
        public List <CustomerDto> GetCustomerDetailsByVLCCode(string vlcCode)
        {
            List <CustomerDto> customerList = new List <CustomerDto>();
            var customers = unitOfWork.CustomerRepository.GetAll().Where(id => id.VLC.VLCCode == vlcCode).ToList();

            if (customers != null)
            {
                foreach (var customer in customers)
                {
                    customerList.Add(CustomerConvertor.ConvertToCustomerDto(customer));
                }
            }

            return(customerList);
        }
Exemplo n.º 6
0
        public ResponseDTO GetCustomerListByVLCId(int vlcId, int?pageNumber)
        {
            ResponseDTO responseDTO = new ResponseDTO();

            List <CustomerDto> customerList = new List <CustomerDto>();
            var customers = unitOfWork.CustomerRepository.GetCustomerListByVLCId(vlcId, pageNumber);

            if (customers != null)
            {
                foreach (var customer in customers)
                {
                    customerList.Add(CustomerConvertor.ConvertToCustomerDto(customer));
                }
            }
            responseDTO.Status  = true;
            responseDTO.Message = String.Format("List of Customers By VLC Id");
            responseDTO.Data    = customerList;
            return(responseDTO);
        }
Exemplo n.º 7
0
        public ResponseDTO DeleteCustomer(int id)
        {
            UnitOfWork unitOfWork = new UnitOfWork();
            //get customer
            var customer = unitOfWork.CustomerRepository.GetById(id);

            //if((customer.ProductOrders !=null && customer.ProductOrders.Count()>0) || (customer.CustomerWallets !=null &&
            //    customer.CustomerWallets.Count()>0 && customer.CustomerWallets.FirstOrDefault().WalletBalance>0))
            //    {
            //    throw new PlatformModuleException("Customer Account Cannot be deleted as it is associated with orders");
            //}
            unitOfWork.CustomerRepository.Delete(id);
            unitOfWork.SaveChanges();
            ResponseDTO responseDTO = new ResponseDTO();

            responseDTO.Status  = true;
            responseDTO.Message = String.Format("Customer Deleted Successfully");
            responseDTO.Data    = CustomerConvertor.ConvertToCustomerDto(customer);
            return(responseDTO);
        }
Exemplo n.º 8
0
        public ResponseDTO GetCustomerByCustomerId(int customerId)
        {
            ResponseDTO responseDTO = new ResponseDTO();
            CustomerDto customerDto = null;
            var         customer    = unitOfWork.CustomerRepository.GetById(customerId);

            if (customer != null)
            {
                customerDto         = CustomerConvertor.ConvertToCustomerDto(customer);
                responseDTO.Status  = true;
                responseDTO.Message = "Customer Detail By Customer Id";
                responseDTO.Data    = customerDto;
            }
            else
            {
                responseDTO.Status  = false;
                responseDTO.Message = "No Customer Exist with given customer Id";
                responseDTO.Data    = new object();
            }
            return(responseDTO);
        }
Exemplo n.º 9
0
        public ResponseDTO AddCustomer(CustomerDto customerDto)
        {
            ResponseDTO responseDTO = new ResponseDTO();

            if (!this.CheckForExisitngCustomer(customerDto))
            {
                Customer customer = new Customer();
                customer.CustomerId = unitOfWork.DashboardRepository.NextNumberGenerator("Customer");
                var vlc = unitOfWork.VLCRepository.GetById(customerDto.VLCId);
                if (vlc != null)
                {
                    CustomerConvertor.ConvertToCustomerEntity(ref customer, customerDto, false);
                    customer.CustomerCode  = unitOfWork.CustomerRepository.GetCustomerCodeIdByVLC(customerDto.VLCId);
                    customer.CreatedDate   = DateTimeHelper.GetISTDateTime();
                    customer.ModifiedDate  = DateTimeHelper.GetISTDateTime();
                    customer.CreatedBy     = customer.ModifiedBy = vlc.AgentName ?? "System";
                    customer.DateOfJoinVLC = DateTimeHelper.GetISTDateTime().Date;
                    customer.IsDeleted     = false;
                    customer.VLCId         = customerDto.VLCId;
                    unitOfWork.CustomerRepository.Add(customer);
                    customerDto = CustomerConvertor.ConvertToCustomerDto(customer);
                    unitOfWork.SaveChanges();
                    responseDTO.Status  = true;
                    responseDTO.Message = String.Format("Customer Successfully Created");
                    responseDTO.Data    = customerDto;
                }
                else
                {
                    throw new PlatformModuleException("VLC Details Not Found");
                }
            }
            else
            {
                responseDTO.Message = "Customer with this Contact & Email already exists.Please enter unique contact & Email.";
                responseDTO.Status  = false;
            }
            return(responseDTO);
        }
Exemplo n.º 10
0
        public ResponseDTO GetCustomerDetailsByCustomerId(int customerId)
        {
            ResponseDTO responseDTO = new ResponseDTO();

            CustomerDetailsDTO customerDetailsDto = new CustomerDetailsDTO();
            var customer = unitOfWork.CustomerRepository.GetById(customerId);

            if (customer != null)
            {
                customerDetailsDto.customerProfileDetails = CustomerConvertor.ConvertToCustomerDto(customer);
                if (customer.CustomerBanks != null)
                {
                    customerDetailsDto.customerBankDetails = CustomerBankConvertor.ConvertTocustomerBankDto(customer.CustomerBanks.FirstOrDefault());
                }
                else
                {
                    customerDetailsDto.customerBankDetails = new CustomerBankDTO();
                }
                if (customer.CustomerAgricultures != null)
                {
                    customerDetailsDto.customerAgricultureDetails = CustomerAgricultureConvertor.ConvertToCustomerAgriCultureDto(customer.CustomerAgricultures.FirstOrDefault());
                }
                else
                {
                    customerDetailsDto.customerAgricultureDetails = new CustomerAgricultureDTO();
                }
                responseDTO.Status  = true;
                responseDTO.Message = "Customer Profile Details";
                responseDTO.Data    = customerDetailsDto;
            }
            else
            {
                throw new PlatformModuleException("Customer  Details Not Found with given Customer Id");
            }
            return(responseDTO);
        }