public GetLeadAdapterCustomFieldResponse GetLeadAdapterCustomFieldsByType(GetLeadAdapterCustomFieldRequest request) { GetLeadAdapterCustomFieldResponse response = new GetLeadAdapterCustomFieldResponse(); IEnumerable <CustomField> customFields = customFieldRepository.GetLeadAdapterCustomFields(request.LeadAdapterType, request.AccountId); var customfieldviewmodel = customFields.Select(x => new CustomFieldViewModel() { AccountID = request.AccountId, DisplayName = x.Title, FieldInputTypeId = x.FieldInputTypeId, IsCustomField = true, IsLeadAdapterField = true, IsDropdownField = false, LeadAdapterType = (byte)request.LeadAdapterType, Title = x.Title, StatusId = Entities.FieldStatus.Active, SortId = x.SortId }); response.CustomFields = customfieldviewmodel; return(response); }
public InsertLeadAdapterResponse InsertLeadAdapter(InsertLeadAdapterRequest request) { Logger.Current.Verbose("Request received to insert a lead adapter."); InsertLeadAdapterResponse response = new InsertLeadAdapterResponse(); FTPAgent agent = new FTPAgent(); LeadAdapterViewModel vm = request.LeadAdapterViewModel; int AccountID = vm.AccountID; bool isDuplicate = leadAdaptersRepository.IsDuplicateLeadAdapter(vm.LeadAdapterType, AccountID, vm.LeadAdapterAndAccountMapId); if (isDuplicate) { throw new UnsupportedOperationException("[|LeadAdapter already exists.|]"); } string leadAdapterPhysicalPath = ConfigurationManager.AppSettings["LEADADAPTER_PHYSICAL_PATH"].ToString(); vm.ArchivePath = Path.Combine(leadAdapterPhysicalPath, AccountID.ToString(), vm.LeadAdapterType.ToString(), "Archive"); vm.LocalFilePath = Path.Combine(leadAdapterPhysicalPath, AccountID.ToString(), vm.LeadAdapterType.ToString(), "Local"); vm.RequestGuid = agent.FTPRegistration(vm.UserName, vm.Password, vm.Url, vm.Port, vm.EnableSSL, vm.RequestGuid); //Create folders if (!Directory.Exists(vm.LocalFilePath)) { Directory.CreateDirectory(vm.LocalFilePath); } if (!Directory.Exists(vm.ArchivePath)) { Directory.CreateDirectory(vm.ArchivePath); } LeadAdapterAndAccountMap leadAdapter = Mapper.Map <LeadAdapterViewModel, LeadAdapterAndAccountMap>(vm); bool isLeadAdapterAlreadyConfiguredForAccount = leadAdaptersRepository.isLeadAdapterAlreadyConfigured(AccountID, vm.LeadAdapterType); leadAdaptersRepository.Insert(leadAdapter); LeadAdapterAndAccountMap newLeadAdapter = unitOfWork.Commit() as LeadAdapterAndAccountMap; if (!isLeadAdapterAlreadyConfiguredForAccount) { CustomFieldTab customfieldtab = customfieldRepository.GetLeadAdapterCustomFieldTab(AccountID); if (customfieldtab == null) { InsertCustomFieldTabRequest customfieldtabrequest = new InsertCustomFieldTabRequest(); CustomFieldTabViewModel tab = new CustomFieldTabViewModel(); CustomFieldSectionViewModel section = new CustomFieldSectionViewModel(); GetLeadAdapterCustomFieldRequest getleadadaptercustomfieldsrequest = new GetLeadAdapterCustomFieldRequest(); getleadadaptercustomfieldsrequest.AccountId = AccountID; getleadadaptercustomfieldsrequest.LeadAdapterType = vm.LeadAdapterType; GetLeadAdapterCustomFieldResponse getleadadaptercustomfieldsresponse = customfieldService.GetLeadAdapterCustomFieldsByType(getleadadaptercustomfieldsrequest); section.CustomFields = getleadadaptercustomfieldsresponse.CustomFields.ToList(); section.Name = vm.LeadAdapterType.ToString(); section.StatusId = CustomFieldSectionStatus.Active; tab.AccountId = AccountID; tab.Name = "Lead Adapter Custom Fields"; tab.IsLeadAdapterTab = true; tab.Sections = new List <CustomFieldSectionViewModel>(); tab.Sections.Add(section); tab.StatusId = CustomFieldTabStatus.Active; customfieldtabrequest.CustomFieldTabViewModel = tab; customfieldService.InsertCustomFieldTab(customfieldtabrequest); } else { UpdateCustomFieldTabRequest customfieldtabrequest = new UpdateCustomFieldTabRequest(); CustomFieldTabViewModel tab = Mapper.Map <CustomFieldTab, CustomFieldTabViewModel>(customfieldtab); CustomFieldSectionViewModel section = new CustomFieldSectionViewModel(); GetLeadAdapterCustomFieldRequest getleadadaptercustomfieldsrequest = new GetLeadAdapterCustomFieldRequest(); getleadadaptercustomfieldsrequest.AccountId = AccountID; getleadadaptercustomfieldsrequest.LeadAdapterType = vm.LeadAdapterType; GetLeadAdapterCustomFieldResponse getleadadaptercustomfieldsresponse = customfieldService.GetLeadAdapterCustomFieldsByType(getleadadaptercustomfieldsrequest); section.CustomFields = getleadadaptercustomfieldsresponse.CustomFields.ToList(); section.Name = vm.LeadAdapterType.ToString(); section.StatusId = CustomFieldSectionStatus.Active; tab.Sections.Add(section); tab.StatusId = CustomFieldTabStatus.Active; customfieldtabrequest.CustomFieldTabViewModel = tab; customfieldService.UpdateCustomFieldTab(customfieldtabrequest); } } foreach (Tag tag in leadAdapter.Tags.Where(t => t.Id == 0)) { Tag savedTag = tagRepository.FindBy(tag.TagName, leadAdapter.AccountID); indexingService.IndexTag(savedTag); accountRepository.ScheduleAnalyticsRefresh(savedTag.Id, (byte)IndexType.Tags); } response.LeadAdapterViewModel = Mapper.Map <LeadAdapterAndAccountMap, LeadAdapterViewModel>(newLeadAdapter); Logger.Current.Informational("Leadadapter inserted successfully."); return(new InsertLeadAdapterResponse()); }
public InsertLeadAdapterResponse InsertFacebookLeadAdapter(InsertLeadAdapterRequest request) { Logger.Current.Verbose("Request received to insert Facebook lead adapter."); InsertLeadAdapterResponse response = new InsertLeadAdapterResponse(); int newLeadAdapterID = 0; try { LeadAdapterViewModel vm = request.LeadAdapterViewModel; int AccountID = vm.AccountID; bool isDuplicate = leadAdaptersRepository.IsDuplicateFacebookAdapter(AccountID, vm.LeadAdapterAndAccountMapId, vm.FacebookLeadAdapterName); if (isDuplicate) { throw new UnsupportedOperationException("[|LeadAdapter with same name already exists.|]"); } LeadAdapterAndAccountMap leadAdapter = Mapper.Map <LeadAdapterViewModel, LeadAdapterAndAccountMap>(vm); leadAdaptersRepository.Insert(leadAdapter); LeadAdapterAndAccountMap newLeadAdapter = unitOfWork.Commit() as LeadAdapterAndAccountMap; newLeadAdapterID = newLeadAdapter.Id; leadAdapter.FacebookLeadAdapter.LeadAdapterAndAccountMapID = newLeadAdapter.Id; GetFacebookAppResponse fbResponse = this.GetFacebookApp(new GetFacebookAppRequest() { AccountId = AccountID }); string extendedToken = this.GetExtendedPageAccessToken(leadAdapter.FacebookLeadAdapter.UserAccessToken, leadAdapter.FacebookLeadAdapter.PageID, fbResponse.FacebookAppID, fbResponse.FacebookAppSecret); leadAdapter.FacebookLeadAdapter.PageAccessToken = !string.IsNullOrEmpty(extendedToken) ? extendedToken : leadAdapter.FacebookLeadAdapter.PageAccessToken; leadAdaptersRepository.InsertFacebookLeadAdapter(leadAdapter.FacebookLeadAdapter); var hasFacebookFields = leadAdaptersRepository.HasFacebookFields(AccountID); if (!hasFacebookFields) { CustomFieldTab customfieldtab = customfieldRepository.GetLeadAdapterCustomFieldTab(AccountID); if (customfieldtab == null) { InsertCustomFieldTabRequest customfieldtabrequest = new InsertCustomFieldTabRequest(); CustomFieldTabViewModel tab = new CustomFieldTabViewModel(); CustomFieldSectionViewModel section = new CustomFieldSectionViewModel(); GetLeadAdapterCustomFieldRequest getleadadaptercustomfieldsrequest = new GetLeadAdapterCustomFieldRequest(); getleadadaptercustomfieldsrequest.AccountId = AccountID; getleadadaptercustomfieldsrequest.LeadAdapterType = vm.LeadAdapterType; GetLeadAdapterCustomFieldResponse getleadadaptercustomfieldsresponse = customfieldService.GetLeadAdapterCustomFieldsByType(getleadadaptercustomfieldsrequest); section.CustomFields = getleadadaptercustomfieldsresponse.CustomFields.ToList(); section.Name = vm.LeadAdapterType.ToString(); section.StatusId = CustomFieldSectionStatus.Active; tab.AccountId = AccountID; tab.Name = "Lead Adapter Custom Fields"; tab.IsLeadAdapterTab = true; tab.Sections = new List <CustomFieldSectionViewModel>(); tab.Sections.Add(section); tab.StatusId = CustomFieldTabStatus.Active; customfieldtabrequest.CustomFieldTabViewModel = tab; customfieldService.InsertCustomFieldTab(customfieldtabrequest); } else { UpdateCustomFieldTabRequest customfieldtabrequest = new UpdateCustomFieldTabRequest(); CustomFieldTabViewModel tab = Mapper.Map <CustomFieldTab, CustomFieldTabViewModel>(customfieldtab); CustomFieldSectionViewModel section = new CustomFieldSectionViewModel(); GetLeadAdapterCustomFieldRequest getleadadaptercustomfieldsrequest = new GetLeadAdapterCustomFieldRequest(); getleadadaptercustomfieldsrequest.AccountId = AccountID; getleadadaptercustomfieldsrequest.LeadAdapterType = vm.LeadAdapterType; GetLeadAdapterCustomFieldResponse getleadadaptercustomfieldsresponse = customfieldService.GetLeadAdapterCustomFieldsByType(getleadadaptercustomfieldsrequest); section.CustomFields = getleadadaptercustomfieldsresponse.CustomFields.ToList(); section.Name = vm.LeadAdapterType.ToString(); section.StatusId = CustomFieldSectionStatus.Active; tab.Sections.Add(section); tab.StatusId = CustomFieldTabStatus.Active; customfieldtabrequest.CustomFieldTabViewModel = tab; customfieldService.UpdateCustomFieldTab(customfieldtabrequest); } } foreach (Tag tag in leadAdapter.Tags.Where(t => t.Id == 0)) { Tag savedTag = tagRepository.FindBy(tag.TagName, leadAdapter.AccountID); indexingService.IndexTag(savedTag); accountRepository.ScheduleAnalyticsRefresh(savedTag.Id, (byte)IndexType.Tags); } response.LeadAdapterViewModel = Mapper.Map <LeadAdapterAndAccountMap, LeadAdapterViewModel>(newLeadAdapter); } catch (Exception ex) { Logger.Current.Error("An error occured while creating Facebook LeadAdapter", ex); if (newLeadAdapterID != 0) { this.DeleteLeadAdapter(new DeleteLeadAdapterRequest(newLeadAdapterID)); } throw; } Logger.Current.Informational("Facebook Leadadapter inserted successfully."); return(new InsertLeadAdapterResponse()); }