Exemplo n.º 1
0
        public HttpResponseMessage PutCustomFieldTab(CustomFieldTabViewModel viewModel)
        {
            UpdateCustomFieldTabRequest request = new UpdateCustomFieldTabRequest()
            {
                CustomFieldTabViewModel = viewModel
            };
            UpdateCustomFieldTabResponse response = ModelState.IsValid ? customFieldService.UpdateCustomFieldTab(request) : null;

            return(Request.BuildResponse(response));
        }
Exemplo n.º 2
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());
        }