Ejemplo n.º 1
0
        public GetLeadAdapterResponse GetLeadAdapter(GetLeadAdapterRequest request)
        {
            GetLeadAdapterResponse response = new GetLeadAdapterResponse();

            Logger.Current.Verbose("Request to fetch LeadAdapter based on leadAdapterId" + request.Id);
            LeadAdapterAndAccountMap leadAdapter = leadAdaptersRepository.FindBy(request.Id);

            if (leadAdapter == null)
            {
                response.Exception = GetLeadAdapterNotFoundException();
            }
            else
            {
                if (leadAdapter.LeadAdapterTypeID != LeadAdapterTypes.Facebook)
                {
                    FTPAgent agent      = new FTPAgent();
                    var      ftpDetails = agent.GetFtpRegistration(leadAdapter.RequestGuid);
                    if (ftpDetails != null)
                    {
                        leadAdapter.Url       = ftpDetails.Host;
                        leadAdapter.UserName  = ftpDetails.UserName;
                        leadAdapter.Password  = ftpDetails.Password;
                        leadAdapter.EnableSsl = ftpDetails.EnableSsl;
                        leadAdapter.Port      = ftpDetails.Port;
                    }
                }
                LeadAdapterViewModel leadAdapterViewModel = Mapper.Map <LeadAdapterAndAccountMap, LeadAdapterViewModel>(leadAdapter);
                response.LeadAdapterViewModel = leadAdapterViewModel;
            }
            return(response);
        }
Ejemplo n.º 2
0
        public UpdateLeadAdapterResponse UpdateLeadAdapter(UpdateLeadAdapterRequest request)
        {
            Logger.Current.Verbose("Request received to update a lead adapter.");
            FTPAgent agent = new FTPAgent();

            LeadAdapterAndAccountMap leadAdapter = Mapper.Map <LeadAdapterViewModel, LeadAdapterAndAccountMap>(request.LeadAdapterViewModel);
            bool isDuplicate = leadAdaptersRepository.IsDuplicateLeadAdapter(leadAdapter.LeadAdapterTypeID, leadAdapter.AccountID, leadAdapter.Id);

            if (isDuplicate)
            {
                throw new UnsupportedOperationException("[|LeadAdapter already exists.|]");
            }
            string leadAdapterPhysicalPath = ConfigurationManager.AppSettings["LEADADAPTER_PHYSICAL_PATH"].ToString();

            request.LeadAdapterViewModel.ArchivePath = Path.Combine(leadAdapterPhysicalPath, request.LeadAdapterViewModel.AccountID.ToString(),
                                                                    request.LeadAdapterViewModel.LeadAdapterType.ToString(), "Archive");
            request.LeadAdapterViewModel.LocalFilePath = Path.Combine(leadAdapterPhysicalPath, request.LeadAdapterViewModel.AccountID.ToString(),
                                                                      request.LeadAdapterViewModel.LeadAdapterType.ToString(), "Local");
            if (agent.UpdateFtpRegistration(request.LeadAdapterViewModel.UserName, request.LeadAdapterViewModel.Password, request.LeadAdapterViewModel.Url,
                                            request.LeadAdapterViewModel.Port, request.LeadAdapterViewModel.EnableSSL, request.LeadAdapterViewModel.RequestGuid) && leadAdapter != null)
            {
                leadAdaptersRepository.Update(leadAdapter);
                unitOfWork.Commit();
                Logger.Current.Informational("Leadadapter updated successfully.");
            }
            return(new UpdateLeadAdapterResponse());
        }
Ejemplo n.º 3
0
        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());
        }