public async Task<IHttpActionResult> SearchClient(SearchModelDto searchModel) { string companyId = this.User.Identity.GetUserId(); if (searchModel.FetchCount == 0) { searchModel.FetchCount = AppSettings.Get<int>(ConfigConstants.DashboardLeadsDefaultCount); } if (!string.IsNullOrEmpty(searchModel.SubInterestName)) { List<string> parentBusinessType = this.youfferInterestService.GetAllParentBusinessTypes(); searchModel.InterestName = parentBusinessType.Single(x => x == searchModel.SubInterestName); searchModel.SubInterestName = string.Empty; } List<VTigerLead> lst = this.crmManagerService.SearchLeads(searchModel); OrganisationModel orgModel = this.crmManagerService.GetOrganisation(companyId); string orgCRMId = this.youfferContactService.GetOrgCRMId(companyId).CRMId; List<UserResultModel> lstUserResultModel = new List<UserResultModel>(); foreach (var item in lst) { bool isUserBlocked = this.crmManagerService.CheckIfUserBlocked(item.cf_773, orgCRMId); if (!isUserBlocked) { try { UserResultModel userResultModel = this.mapperFactory.GetMapper<VTigerLead, UserResultModel>().Map(item); userResultModel.Id = this.youfferContactService.GetMappingEntryByCrmLeadId(item.id).ContactId; string purchasedForInt = string.Empty; string[] mainInt = item.cf_769[0].Split(new string[] { " |##| " }, StringSplitOptions.None).Where(x => !string.IsNullOrEmpty(x)).ToArray(); string[] subInt = item.cf_771[0].Split(new string[] { " |##| " }, StringSplitOptions.None).Where(x => !string.IsNullOrEmpty(x)).ToArray(); List<LeadOpportunityMappingDto> lstLeadOppMapping = this.youfferLeadService.GetMappingEntryByLeadAndOrgCRMId(item.id.ToString(), orgCRMId); foreach (var itemLstLeadOppMapping in lstLeadOppMapping) { purchasedForInt = itemLstLeadOppMapping.Interest; subInt = subInt.Where(val => val != purchasedForInt).ToArray(); } string[] subIntArr = new string[] { }; if (!string.IsNullOrEmpty(searchModel.SubInterestName)) { subIntArr = subInt.FirstOrDefault(x => x.ToLower().Contains(searchModel.SubInterestName.ToLower())) == null ? new string[] { } : subInt.FirstOrDefault(x => x.ToLower().Contains(searchModel.SubInterestName.ToLower())).Split(',').ToArray(); } string[] mainIntArr = new string[] { }; if (!string.IsNullOrEmpty(searchModel.InterestName)) { mainIntArr = mainInt.FirstOrDefault(x => x.ToLower().Contains(searchModel.InterestName.ToLower())) == null ? new string[] { } : mainInt.FirstOrDefault(x => x.ToLower().Contains(searchModel.InterestName.ToLower())).Split(',').ToArray(); if (subInt.Contains(mainIntArr[0])) { subIntArr = mainIntArr; } else { string[] children = this.youfferInterestService.GetSubBusinessTypeFromMain(mainIntArr[0]).Select(x => x.BusinessTypeName).Distinct().ToArray(); var common = children.Intersect(subInt); subIntArr = common.ToArray(); } } if (subInt.Length > 0 && subIntArr.Length > 0) { userResultModel.CountryDetails = this.commonService.GetUserCountryDetailsFromName(item.country); userResultModel.Rank = this.crmManagerService.GetUserRank(item.cf_773); userResultModel.Availability = string.IsNullOrWhiteSpace(item.Availability.ToString()) ? Availability.Undefined : (Availability)Enum.Parse(typeof(Availability), item.Availability.ToString()); userResultModel.OSType = string.IsNullOrWhiteSpace(item.OSType.ToString()) ? OSType.Undefined : (OSType)Enum.Parse(typeof(OSType), item.OSType.ToString()); userResultModel.UserRole = Roles.Customer; userResultModel.IsActive = item.cf_767; userResultModel.MainInterest = new string[] { }; userResultModel.SubInterest = subIntArr; userResultModel.PaymentDetails = new PaymentModelDto() { PayPalId = item.cf_851, Mode = string.IsNullOrWhiteSpace(item.cf_849) ? PaymentMode.Undefined : (PaymentMode)Enum.Parse(typeof(PaymentMode), item.cf_849.ToString()) }; lstUserResultModel.Add(userResultModel); } } catch (Exception ex) { this.LoggerService.LogException("Search Client Looping : " + ex.Message); } } } this.LoggerService.LogException("Search Client:" + orgModel.AccountName + " -json-" + JsonConvert.SerializeObject(searchModel)); return this.Ok(lstUserResultModel); }
public async Task<IHttpActionResult> SearchClient1(SearchModelDto searchModel) { string companyId = this.User.Identity.GetUserId(); string orgCRMId = this.youfferContactService.GetOrgCRMId(companyId).CRMId; if (searchModel.FetchCount == 0) { searchModel.FetchCount = AppSettings.Get<int>(ConfigConstants.DashboardLeadsDefaultCount); } OrganisationModel orgModel = this.crmManagerService.GetOrganisation(companyId); if (!string.IsNullOrEmpty(searchModel.SubInterestName)) { List<string> parentBusinessType = this.youfferInterestService.GetAllParentBusinessTypes(); try { IEnumerable<string> interestNames = parentBusinessType.Where(x => x.ToLower() == searchModel.SubInterestName.ToLower()); if (!string.IsNullOrEmpty(interestNames.FirstOrDefault())) { searchModel.InterestName = interestNames.FirstOrDefault(); searchModel.SubInterestName = string.Empty; } } catch { } } List<VTigerDashBoardData> lst = this.crmManagerService.GetSearchedLeads(orgModel.Id, searchModel); List<UserResultModel> lstUserResultModel = new List<UserResultModel>(); string purchasedForInt = string.Empty; foreach (var item in lst) { try { string[] mainInt = item.cf_769.Split(new string[] { " |##| " }, StringSplitOptions.None).Where(x => !string.IsNullOrEmpty(x)).ToArray(); string[] subInt = item.cf_771.Split(new string[] { " |##| " }, StringSplitOptions.None).Where(x => !string.IsNullOrEmpty(x)).ToArray(); string[] subIntArr = new string[] { }; if (!string.IsNullOrEmpty(searchModel.SubInterestName)) { subIntArr = subInt.FirstOrDefault(x => x.ToLower().Contains(searchModel.SubInterestName.ToLower())) == null ? new string[] { } : subInt.FirstOrDefault(x => x.ToLower().Contains(searchModel.SubInterestName.ToLower())).Split(',').ToArray(); } string[] mainIntArr = new string[] { }; if (!string.IsNullOrEmpty(searchModel.InterestName)) { mainIntArr = mainInt.FirstOrDefault(x => x.ToLower().Contains(searchModel.InterestName.ToLower())) == null ? new string[] { } : mainInt.FirstOrDefault(x => x.ToLower().Contains(searchModel.InterestName.ToLower())).Split(',').ToArray(); if (subInt.Contains(mainIntArr[0])) { subIntArr = mainIntArr; } else { string[] children = this.youfferInterestService.GetSubBusinessTypeFromMain(mainIntArr[0]).Select(x => x.BusinessTypeName).Distinct().ToArray(); var common = children.Intersect(subInt); subIntArr = common.ToArray(); } } if (subIntArr.Length > 0) { UserResultModel userResultModel = this.mapperFactory.GetMapper<VTigerDashBoardData, UserResultModel>().Map(item); userResultModel.Id = this.youfferContactService.GetMappingEntryByCrmLeadId(AppSettings.Get<string>(ConfigConstants.LeadId) + item.leadid).ContactId; userResultModel.CountryDetails = this.commonService.GetUserCountryDetailsFromName(item.country); userResultModel.UserRole = Roles.Customer; userResultModel.Phone = userResultModel.Phone ?? string.Empty; userResultModel.MainInterest = new string[] { }; userResultModel.SubInterest = subIntArr; userResultModel.PaymentDetails = new PaymentModelDto() { PayPalId = item.cf_851, Mode = string.IsNullOrWhiteSpace(item.cf_849) ? PaymentMode.Undefined : (PaymentMode)Enum.Parse(typeof(PaymentMode), item.cf_849) }; lstUserResultModel.Add(userResultModel); } } catch (Exception ex) { this.LoggerService.LogException("Search Client Looping : " + ex.Message); } } this.LoggerService.LogException("Search Client:" + orgModel.AccountName + " -json-" + JsonConvert.SerializeObject(searchModel)); return this.Ok(lstUserResultModel); }