public List <CatPartnerImportModel> CheckValidImport(List <CatPartnerImportModel> list) { var partners = Get().ToList(); var users = sysUserRepository.Get().ToList(); var countries = countryService.Get().ToList(); var provinces = placeService.Get(x => x.PlaceTypeId == PlaceTypeEx.GetPlaceType(CatPlaceTypeEnum.Province)).ToList(); var branchs = placeService.Get(x => x.PlaceTypeId == PlaceTypeEx.GetPlaceType(CatPlaceTypeEnum.Branch)).ToList(); var salemans = sysUserRepository.Get().ToList(); var offices = officeRepository.Get().ToList(); var regexItem = new Regex("^[a-zA-Z0-9-]+$"); var paymentTerms = new List <string> { "All", "Prepaid", "Collect" }; var services = API.Common.Globals.CustomData.Services; var allGroup = DataEnums.PARTNER_GROUP; var partnerGroups = allGroup.Split(";"); list.ForEach(item => { if (string.IsNullOrEmpty(item.TaxCode)) { item.TaxCodeError = string.Format(stringLocalizer[CatalogueLanguageSub.MSG_PARTNER_TAXCODE_EMPTY]); item.IsValid = false; } else { string taxCode = item.TaxCode.Replace(" ", ""); var asciiBytesCount = Encoding.ASCII.GetByteCount(taxCode); var unicodBytesCount = Encoding.UTF8.GetByteCount(taxCode); if (asciiBytesCount != unicodBytesCount || !regexItem.IsMatch(taxCode)) { item.TaxCodeError = string.Format(stringLocalizer[CatalogueLanguageSub.MSG_PARTNER_TAXCODE_INVALID], item.TaxCode); item.IsValid = false; } else if (list.Count(x => x.TaxCode == taxCode) > 1) { item.TaxCodeError = string.Format(stringLocalizer[CatalogueLanguageSub.MSG_PARTNER_TAXCODE_DUPLICATED]); item.IsValid = false; } else { if (partners.Any(x => x.TaxCode == taxCode)) { item.TaxCodeError = string.Format(stringLocalizer[CatalogueLanguageSub.MSG_PARTNER_TAXCODE_EXISTED], item.TaxCode); item.IsValid = false; } } } if (string.IsNullOrEmpty(item.PartnerGroup)) { item.PartnerGroupError = string.Format(stringLocalizer[CatalogueLanguageSub.MSG_PARTNER_GROUP_EMPTY]); item.IsValid = false; } else { item.PartnerGroup = item.PartnerGroup.ToUpper(); if (item.PartnerGroup == DataEnums.AllPartner) { item.PartnerGroup = allGroup; } else { var groups = item.PartnerGroup.Split(";").Select(x => x.Trim()); var group = partnerGroups.Intersect(groups); if (group == null) { item.PartnerGroupError = string.Format(stringLocalizer[CatalogueLanguageSub.MSG_PARTNER_GROUP_NOT_FOUND], item.PartnerGroup); item.IsValid = false; } else { item.PartnerGroup = String.Join(";", groups); } } item = GetSaleManInfo(item, salemans, offices, services); } if (string.IsNullOrEmpty(item.PartnerNameEn)) { item.PartnerNameEnError = string.Format(stringLocalizer[CatalogueLanguageSub.MSG_PARTNER_NAME_EN_EMPTY]); item.IsValid = false; } if (string.IsNullOrEmpty(item.PartnerNameVn)) { item.PartnerNameVnError = string.Format(stringLocalizer[CatalogueLanguageSub.MSG_PARTNER_NAME_VN_EMPTY]); item.IsValid = false; } if (string.IsNullOrEmpty(item.ShortName)) { item.ShortNameError = string.Format(stringLocalizer[CatalogueLanguageSub.MSG_PARTNER_SHORT_NAME_EMPTY]); item.IsValid = false; } if (string.IsNullOrEmpty(item.AddressEn)) { item.AddressEnError = stringLocalizer[CatalogueLanguageSub.MSG_PARTNER_ADDRESS_BILLING_EN_NOT_FOUND]; item.IsValid = false; } if (string.IsNullOrEmpty(item.AddressVn)) { item.AddressVnError = stringLocalizer[CatalogueLanguageSub.MSG_PARTNER_ADDRESS_BILLING_VN_NOT_FOUND]; item.IsValid = false; } if (string.IsNullOrEmpty(item.CountryBilling)) { if (!string.IsNullOrEmpty(item.CityBilling)) { item.CityBillingError = string.Format(stringLocalizer[CatalogueLanguageSub.MSG_PARTNER_PROVINCE_REQUIRED_COUNTRY], item.CityBilling); item.IsValid = false; } } else { string countryBilling = item.CountryBilling?.ToLower(); var country = countries.FirstOrDefault(i => i.NameEn.ToLower() == countryBilling); if (country != null) { item.CountryId = country.Id; if (!string.IsNullOrEmpty(item.CityBilling)) { string cityBilling = item.CityBilling.ToLower(); var province = provinces.FirstOrDefault(i => i.NameEn.ToLower() == cityBilling && i.CountryId == country.Id); if (province == null) { item.CityBillingError = string.Format(stringLocalizer[CatalogueLanguageSub.MSG_PARTNER_PROVINCE_BILLING_NOT_FOUND], item.CityBilling); item.IsValid = false; } else { item.ProvinceId = province.Id; } } } else { item.CountryBillingError = string.Format(stringLocalizer[CatalogueLanguageSub.MSG_PARTNER_COUNTRY_BILLING_NOT_FOUND], item.CountryBilling); item.IsValid = false; } } if (string.IsNullOrEmpty(item.CountryShipping)) { if (!string.IsNullOrEmpty(item.CityShipping)) { item.CityShippingError = string.Format(stringLocalizer[CatalogueLanguageSub.MSG_PARTNER_PROVINCE_REQUIRED_COUNTRY], item.CityShipping); item.IsValid = false; } } else { string countShipping = item.CountryShipping?.ToLower(); var country = countries.FirstOrDefault(i => i.NameEn.ToLower() == countShipping); if (country != null) { item.CountryShippingId = country.Id; if (!string.IsNullOrEmpty(item.CityShipping)) { string cityShipping = item.CityShipping.ToLower(); var province = provinces.FirstOrDefault(i => i.NameEn.ToLower() == cityShipping && i.CountryId == country.Id); if (province == null) { item.CityShippingError = string.Format(stringLocalizer[CatalogueLanguageSub.MSG_PARTNER_PROVINCE_SHIPPING_NOT_FOUND], item.CityShipping); item.IsValid = false; } else { item.ProvinceShippingId = province.Id; } } } else { item.CountryShippingError = string.Format(stringLocalizer[CatalogueLanguageSub.MSG_PARTNER_COUNTRY_SHIPPING_NOT_FOUND], item.CountryShipping); item.IsValid = false; } } }); return(list); }
public IActionResult Get(int id) { var result = catCountryService.Get(x => x.Id == id).FirstOrDefault(); return(Ok(result)); }