public List <CatPlaceImportModel> CheckValidImport(List <CatPlaceImportModel> list, CatPlaceTypeEnum placeType) { string placeTypeName = PlaceTypeEx.GetPlaceType(placeType); List <CatPlaceImportModel> results = null; switch (placeType) { case CatPlaceTypeEnum.Warehouse: results = CheckWarehouseValidImport(list, placeTypeName); break; case CatPlaceTypeEnum.Port: results = CheckPortIndexValidImport(list, placeTypeName); break; case CatPlaceTypeEnum.Province: results = CheckProvinceValidImport(list, placeTypeName); break; case CatPlaceTypeEnum.District: results = CheckDistrictValidImport(list, placeTypeName); break; case CatPlaceTypeEnum.Ward: results = CheckWardValidImport(list, placeTypeName); break; } return(results); }
private IQueryable <sp_GetCatPlace> QueryCriteria(CatPlaceCriteria criteria) { string placetype = PlaceTypeEx.GetPlaceType(criteria.PlaceType); var list = GetBy(placetype); if (criteria.All == null) { list = list.Where(x => ((x.Code ?? "").IndexOf(criteria.Code ?? "", StringComparison.OrdinalIgnoreCase) > -1) && ((x.NameEn ?? "").IndexOf(criteria.NameEn ?? "", StringComparison.OrdinalIgnoreCase) > -1) && ((x.NameVn ?? "").IndexOf(criteria.NameVn ?? "", StringComparison.OrdinalIgnoreCase) > -1) && ((x.CountryNameEN ?? "").IndexOf(criteria.CountryNameEN ?? "", StringComparison.OrdinalIgnoreCase) > -1) && ((x.CountryNameVN ?? "").IndexOf(criteria.CountryNameVN ?? "", StringComparison.OrdinalIgnoreCase) > -1) && ((x.DistrictNameEN ?? "").IndexOf(criteria.DistrictNameEN ?? "", StringComparison.OrdinalIgnoreCase) > -1) && ((x.DistrictNameVN ?? "").IndexOf(criteria.DistrictNameVN ?? "", StringComparison.OrdinalIgnoreCase) > -1) && (x.CountryID == criteria.CountryId || criteria.CountryId == null) && (x.ProvinceID == criteria.ProvinceId || criteria.ProvinceId == null) && (x.DistrictID == criteria.DistrictId || criteria.DistrictId == null) && ((x.ProvinceNameEN ?? "").IndexOf(criteria.ProvinceNameEN ?? "", StringComparison.OrdinalIgnoreCase) > -1) && ((x.ProvinceNameVN ?? "").IndexOf(criteria.ProvinceNAmeVN ?? "", StringComparison.OrdinalIgnoreCase) > -1) && ((x.Address ?? "").IndexOf(criteria.Address ?? "", StringComparison.OrdinalIgnoreCase) >= 0) && ((x.ModeOfTransport ?? "").IndexOf(criteria.ModeOfTransport ?? "", StringComparison.OrdinalIgnoreCase) > -1) && (x.AreaNameEN ?? "").IndexOf(criteria.AreaNameEN ?? "", StringComparison.OrdinalIgnoreCase) > -1 && (x.AreaNameVN ?? "").IndexOf(criteria.AreaNameVN ?? "", StringComparison.OrdinalIgnoreCase) > -1 && (x.FlightVesselNo ?? "").Contains(criteria.FlightVesselNo ?? "", StringComparison.OrdinalIgnoreCase) == true && (x.Active == criteria.Active || criteria.Active == null) )?.AsQueryable(); } else { list = list.Where(x => ( ((x.Code ?? "").IndexOf(criteria.All ?? "", StringComparison.OrdinalIgnoreCase) > -1) || ((x.NameEn ?? "").IndexOf(criteria.All ?? "", StringComparison.OrdinalIgnoreCase) > -1) || ((x.NameVn ?? "").IndexOf(criteria.All ?? "", StringComparison.OrdinalIgnoreCase) > -1) || ((x.CountryNameEN ?? "").IndexOf(criteria.All ?? "", StringComparison.OrdinalIgnoreCase) > -1) || ((x.CountryNameVN ?? "").IndexOf(criteria.All ?? "", StringComparison.OrdinalIgnoreCase) > -1) || ((x.DistrictNameEN ?? "").IndexOf(criteria.All ?? "", StringComparison.OrdinalIgnoreCase) > -1) || ((x.DistrictNameVN ?? "").IndexOf(criteria.All ?? "", StringComparison.OrdinalIgnoreCase) > -1) || ((x.ProvinceNameEN ?? "").IndexOf(criteria.All ?? "", StringComparison.OrdinalIgnoreCase) > -1) || ((x.ProvinceNameVN ?? "").IndexOf(criteria.All ?? "", StringComparison.OrdinalIgnoreCase) > -1) || ((x.Address ?? "").IndexOf(criteria.All ?? "", StringComparison.OrdinalIgnoreCase) > -1) || (x.AreaNameEN ?? "").IndexOf(criteria.All ?? "", StringComparison.OrdinalIgnoreCase) > -1 || (x.AreaNameVN ?? "").IndexOf(criteria.All ?? "", StringComparison.OrdinalIgnoreCase) > -1 || ((x.ModeOfTransport ?? "").IndexOf(criteria.All ?? "", StringComparison.OrdinalIgnoreCase) > -1) || (x.FlightVesselNo ?? "").Contains(criteria.All ?? "", StringComparison.OrdinalIgnoreCase) == true ) && (x.Active == criteria.Active || criteria.Active == null) )?.AsQueryable(); } return(list); }
public IQueryable <sp_GetCatPlace> Get(CatPlaceCriteria criteria) { var countries = countryRepository.Get(); string placetype = PlaceTypeEx.GetPlaceType(criteria.PlaceType); // Join left với country. var places = from x in DataContext.Get(x => (x.PlaceTypeId == placetype || string.IsNullOrEmpty(placetype) && (x.Active == criteria.Active || criteria.Active == null)) && (x.ModeOfTransport.IndexOf(criteria.ModeOfTransport, StringComparison.OrdinalIgnoreCase) > -1) || string.IsNullOrEmpty(criteria.ModeOfTransport)) join coun in countries on x.CountryId equals coun.Id into coun2 from coun in coun2.DefaultIfEmpty() select new sp_GetCatPlace { ID = x.Id, Code = x.Code, NameVn = x.NameVn, NameEn = x.NameEn, DisplayName = x.DisplayName, Address = x.Address, DistrictID = x.DistrictId, DistrictNameEN = string.Empty, DistrictNameVN = string.Empty, ProvinceID = x.ProvinceId, ProvinceNameEN = string.Empty, ProvinceNameVN = string.Empty, CountryNameEN = coun.NameEn, CountryNameVN = coun.NameVn, CountryID = x.CountryId, AreaID = x.AreaId, LocalAreaID = x.LocalAreaId, ModeOfTransport = x.ModeOfTransport, PlaceTypeID = x.PlaceTypeId, Note = x.Note, UserCreated = x.UserCreated, DatetimeCreated = x.DatetimeCreated, UserModified = x.UserModified, DatetimeModified = x.DatetimeModified, Active = x.Active }; return(places); }
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); }
private List <CatPlaceImportModel> CheckWarehouseValidImport(List <CatPlaceImportModel> list, string placeTypeName) { var countries = countryRepository.Get().ToList(); var provinces = DataContext.Get(x => x.PlaceTypeId == PlaceTypeEx.GetPlaceType(CatPlaceTypeEnum.Province)).ToList(); var districts = DataContext.Get(x => x.PlaceTypeId == PlaceTypeEx.GetPlaceType(CatPlaceTypeEnum.District)).ToList(); var warehouses = DataContext.Get(x => x.PlaceTypeId == placeTypeName).ToList(); var results = new List <CatPlaceImportModel>(); foreach (var item in list) { var result = CheckCatplaceValidImport(warehouses, results, item); result.PlaceTypeId = placeTypeName; if (string.IsNullOrEmpty(item.Address)) { result.AddressError = stringLocalizer[CatalogueLanguageSub.MSG_PLACE_ADDRESS_EMPTY]; result.IsValid = false; } else { result.Address = item.Address; } if (string.IsNullOrEmpty(item.CountryName)) { result.CountryNameError = stringLocalizer[CatalogueLanguageSub.MSG_PLACE_COUNTRY_NAME_EMPTY]; result.IsValid = false; } else { var country = countries.FirstOrDefault(i => i.NameEn.ToLower() == item.CountryName.ToLower()); if (country == null) { result.CountryNameError = string.Format(stringLocalizer[CatalogueLanguageSub.MSG_PLACE_COUNTRY_NOT_FOUND], item.CountryName); result.IsValid = false; } else { result.CountryId = country.Id; if (!string.IsNullOrEmpty(item.ProvinceName)) { var province = provinces.FirstOrDefault(i => i.NameEn.ToLower() == item.ProvinceName.ToLower() && (i.CountryId == country.Id || country == null)); if (province == null) { result.ProvinceNameError = string.Format(stringLocalizer[CatalogueLanguageSub.MSG_PLACE_PROVINCE_NOT_FOUND], item.ProvinceName, item.CountryName); result.IsValid = false; } else { result.ProvinceId = province.Id; if (!string.IsNullOrEmpty(item.DistrictName)) { var district = districts.FirstOrDefault(i => i.NameEn.ToLower() == item.DistrictName.ToLower() && (i.ProvinceId == province.Id || province == null)); if (district == null) { result.DistrictNameError = string.Format(stringLocalizer[CatalogueLanguageSub.MSG_PLACE_DISTRICT_NOT_FOUND], item.DistrictName, item.ProvinceName); result.IsValid = false; } else { result.DistrictId = district.Id; } } } } } } result.PlaceTypeId = placeTypeName; results.Add(result); } return(results); }
private List <CatPlaceImportModel> CheckDistrictValidImport(List <CatPlaceImportModel> list, string placeTypeName) { var countries = countryRepository.Get(); var places = Get(); var provinces = places.Where(x => x.PlaceTypeId == PlaceTypeEx.GetPlaceType(CatPlaceTypeEnum.Province)).ToList(); var districts = places.Where(x => x.PlaceTypeId == placeTypeName).ToList(); list.ForEach(item => { item.PlaceTypeId = placeTypeName; if (string.IsNullOrEmpty(item.Code)) { item.CodeError = stringLocalizer[CatalogueLanguageSub.MSG_PLACE_CODE_EMPTY]; item.IsValid = false; } if (string.IsNullOrEmpty(item.NameEn)) { item.NameEnError = stringLocalizer[CatalogueLanguageSub.MSG_PLACE_NAME_EN_EMPTY]; item.IsValid = false; } if (string.IsNullOrEmpty(item.NameVn)) { item.NameVnError = stringLocalizer[CatalogueLanguageSub.MSG_PLACE_NAME_LOCAL_EMPTY]; item.IsValid = false; } if (string.IsNullOrEmpty(item.CountryName)) { item.CountryNameError = stringLocalizer[CatalogueLanguageSub.MSG_PLACE_COUNTRY_NAME_EMPTY]; item.IsValid = false; } if (string.IsNullOrEmpty(item.ProvinceName)) { item.ProvinceNameError = stringLocalizer[CatalogueLanguageSub.MSG_PLACE_PROVINCE_NAME_EMPTY]; item.IsValid = false; } else { if (!string.IsNullOrEmpty(item.CountryName)) { var country = countries.FirstOrDefault(i => i.NameEn.ToLower() == item.CountryName.ToLower()); if (country == null) { item.CountryNameError = string.Format(stringLocalizer[CatalogueLanguageSub.MSG_PLACE_COUNTRY_NOT_FOUND], item.CountryName); item.IsValid = false; } else { item.CountryId = country.Id; var province = provinces.FirstOrDefault(i => i.NameEn.ToLower() == item.ProvinceName.ToLower() && (i.CountryId == country.Id || country == null)); if (province == null) { item.ProvinceNameError = string.Format(stringLocalizer[CatalogueLanguageSub.MSG_PLACE_PROVINCE_NOT_FOUND], item.ProvinceName, item.CountryName); item.IsValid = false; } else { item.ProvinceId = province.Id; var district = districts.FirstOrDefault(i => i.Code.ToLower() == item.Code.ToLower()); if (district != null) { item.CodeError = string.Format(stringLocalizer[CatalogueLanguageSub.MSG_PLACE_CODE_EXISTED], item.Code); item.IsValid = false; } else { var countNew = list.Count(i => i.Code.ToLower() == item.Code.ToLower()); if (countNew > 1) { item.CodeError = string.Format(stringLocalizer[CatalogueLanguageSub.MSG_PLACE_CODE_DUPLICATE], item.Code); item.IsValid = false; } } } } } } }); return(list); }