示例#1
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);
        }