コード例 #1
0
        //insert new customer to DB
        private bool InsertCustomerToDb(DMCustomer customer, Guid userGuid)
        {
            var entity = MapCustomerToCoreCustomer(customer, userGuid);

            _customerService.Add(entity);
            return(true);
        }
コード例 #2
0
        private DMCustomer CustomerInputValidation(DMCustomer customer)
        {
            customer.IsValid = false;
            var mandatoryField = new
            {
                CustomerName = customer.CustomerName,
                Address      = customer.Address,
                ZipCode      = customer.ZipCode,
                Country      = customer.Country,
                State        = customer.State,
                CustomerType = customer.CustomerType
            };

            var isMandatoryValid = ValidationHelper.NullValidation(mandatoryField);

            if (!isMandatoryValid.IsValid)
            {
                customer.IsValid = false;
                customer.Reason += isMandatoryValid.Message;
                return(customer);
            }

            customer.IsValid = true;
            return(customer);
        }
コード例 #3
0
        //map DMCustomer to Entity customer
        private Core.Entities.Customer MapCustomerToCoreCustomer(DMCustomer customer, Guid userGuid)
        {
            customerEntity = new Entities.Customer();
            customerEntity.CustomerGuid        = Guid.NewGuid();
            customerEntity.CustomerName        = customer.CustomerName.Trim();
            customerEntity.CustomerTypeGuid    = customer.CustomerTypeGuid;
            customerEntity.Department          = customer.Department;
            customerEntity.Agency              = customer.Agency.Trim();
            customerEntity.CustomerDescription = customer.CustomerDescription;
            customerEntity.Address             = customer.Address;
            customerEntity.AddressLine1        = customer.AddressLine1;
            customerEntity.City          = customer.City;
            customerEntity.ZipCode       = customer.ZipCode;
            customerEntity.PrimaryPhone  = customer.PrimaryPhone;
            customerEntity.PrimaryEmail  = customer.PrimaryEmail;
            customerEntity.Abbreviations = customer.Abbreviations;
            customerEntity.Tags          = customer.Tags;
            customerEntity.CustomerCode  = customer.CustomerCode;
            customerEntity.Url           = customer.Url;
            customerEntity.StateId       = customer.StateId;
            customerEntity.CountryId     = customer.CountryId;
            customerEntity.CreatedOn     = DateTime.UtcNow;
            customerEntity.IsActive      = true;
            customerEntity.IsDeleted     = false;
            customerEntity.CreatedBy     = userGuid;
            customerEntity.UpdatedBy     = userGuid;
            customerEntity.UpdatedOn     = DateTime.UtcNow;

            customerEntity.CustomerTypeName    = customer.CustomerType;
            customerEntity.Department          = customer.Department;
            customerEntity.Agency              = customer.Agency;
            customerEntity.CustomerDescription = customer.CustomerDescription;
            return(customerEntity);
        }
コード例 #4
0
        private DMCustomer CheckDuplicateCustomer(DMCustomer customer)
        {
            var customerCount = _customerService.CheckDuplicateForImport(customer.CustomerName, customer.CustomerGuid);

            if (customerCount == 1)
            {
                customer.Reason = "Duplicate code";
            }
            return(customer);
        }
コード例 #5
0
        private void UpdateCustomerByOfficeForFederal(DMCustomer customer)
        {
            var usCustomerOffice = _usCustomerOfficeListService.GetCustomerOfficeByContractingOfficeName(customer.CustomerName);

            if (usCustomerOffice != null)
            {
                customer.Department   = usCustomerOffice.DepartmentName;
                customer.CustomerName = usCustomerOffice.ContractingOfficeName;
                customer.Agency       = usCustomerOffice.CustomerName;
                customer.City         = usCustomerOffice.AddressCity;
                customer.ZipCode      = usCustomerOffice.ZipCode;
                customer.Country      = usCustomerOffice.CountryCode;
                customer.State        = usCustomerOffice.AddressState;
                customer.CustomerCode = usCustomerOffice.ContractingOfficeCode;
            }
        }
コード例 #6
0
        private DMCustomer EnableDisableDeleteCustomer(DMCustomer customer, Guid customerGuid)
        {
            var action = customer.Action.ToLower();

            if (action == ImportAction.Delete.ToString().ToLower())
            {
                var result = DeleteCustomer(customerGuid);
                customer.Reason = "Deleted Successfully";
            }
            else if (action == ImportAction.Enable.ToString().ToLower())
            {
                var result = EnableDisableCustomer(true, customerGuid);
                customer.Reason = "Enable Successfully";
            }
            else
            {
                var result = EnableDisableCustomer(false, customerGuid);
                customer.Reason = "Disable Successfully";
            }

            customer.ImportStatus = Core.Entities.ImportStatus.Success.ToString();
            return(customer);
        }
コード例 #7
0
        private DMCustomer DataValidation(DMCustomer customer)
        {
            customer.IsValid = true;
            var customerObject = MapperHelper.CreateDataObjectFromObject(customer);

            foreach (var item in customerObject)
            {
                switch (item.Key)
                {
                case "State":
                    if (!string.IsNullOrEmpty(customer.State))
                    {
                        var state = _stateService.GetStateByStateName(customer.State);
                        if (state == null)
                        {
                            customer.Reason      += "Invalid state.";
                            customer.IsValid      = false;
                            customer.ImportStatus = ImportStatus.Fail.ToString();
                        }
                        else
                        {
                            customer.StateId = state.StateId;
                        }
                    }
                    break;

                case "Country":
                    if (!string.IsNullOrEmpty(customer.Country))
                    {
                        var country = _countryService.GetCountryByCountryName(customer.Country);
                        if (country == null)
                        {
                            customer.Reason      += "Invalid Country.";
                            customer.IsValid      = false;
                            customer.ImportStatus = ImportStatus.Fail.ToString();
                        }
                        else
                        {
                            customer.CountryId = country.CountryId;
                        }
                    }
                    break;

                case "CustomerType":
                    if (!string.IsNullOrWhiteSpace(customer.CustomerType))
                    {
                        var customerType = _customerTypeService.GetCustomerTypeByName(customer.CustomerType);
                        if (customerType == Guid.Empty)
                        {
                            customer.Reason      += "Invalid customer type.";
                            customer.IsValid      = false;
                            customer.ImportStatus = ImportStatus.Fail.ToString();
                        }
                        else
                        {
                            customer.CustomerTypeGuid = customerType;
                        }
                    }
                    break;
                }
            }
            return(customer);
        }