Exemplo n.º 1
0
        public SaveNoteResponse InsertNote(SaveNoteRequest request)
        {
            Logger.Current.Verbose("Request for inserting Note");
            Logger.Current.Informational("Note details:" + request.NoteViewModel.NoteDetails);
            Note note = Mapper.Map <NoteViewModel, Note>(request.NoteViewModel);

            isNoteValid(note);
            noteRepository.Insert(note);
            Note newNote = unitOfWork.Commit() as Note;

            foreach (Tag tag in note.Tags.Where(t => t.Id == 0))
            {
                if (tag.Id == 0)
                {
                    Tag savedTag = tagRepository.FindBy(tag.TagName, request.AccountId);
                    indexingService.IndexTag(savedTag);
                    accountService.ScheduleAnalyticsRefresh(savedTag.Id, (byte)IndexType.Tags);
                }
            }

            note.Id = newNote.Id;
            if (request.NoteViewModel.Contacts != null && request.NoteViewModel.Contacts.Count() > 0)
            {
                var noteContactIds = request.NoteViewModel.Contacts.Select(c => c.Id).ToList();
                List <LastTouchedDetails> details = new List <LastTouchedDetails>();
                foreach (var id in noteContactIds)
                {
                    LastTouchedDetails detail = new LastTouchedDetails();
                    detail.ContactID       = id;
                    detail.LastTouchedDate = DateTime.UtcNow;
                    details.Add(detail);
                }
                updateLastTouchedInformation(details);
                contactService.ContactIndexing(new ContactIndexingRequest()
                {
                    ContactIds = noteContactIds, Ids = noteContactIds.ToLookup(o => o, o => { return(true); })
                });
            }

            if (note.SelectAll == false)
            {
                this.addToTopic(note, request.AccountId);
            }

            return(new SaveNoteResponse()
            {
                NoteViewModel = new NoteViewModel()
                {
                    NoteId = newNote.Id
                }
            });
        }
Exemplo n.º 2
0
 private void ReIndexLeadScoreTags(IEnumerable <Tag> Tags)
 {
     foreach (Tag tag in Tags)
     {
         //tag.TagNameAutoComplete.Output += " *";
         indexingService.IndexTag(tag);
     }
 }
Exemplo n.º 3
0
        public SaveTagResponse SaveTag(SaveTagRequest request)
        {
            Logger.Current.Verbose("Request to save the tag.");
            Tag tag = Mapper.Map <TagViewModel, Tag>(request.TagViewModel);

            isTagValid(tag);

            if (tag.Id == 0 && request.TagViewModel.ContactId == 0)
            {
                IsDuplicateTag(tag);
            }
            Tag persistedTag = tagRepository.SaveContactTag(request.TagViewModel.ContactId,
                                                            request.TagViewModel.TagName, request.TagViewModel.TagID, request.TagViewModel.AccountID, request.TagViewModel.CreatedBy);

            unitOfWork.Commit();

            addToTopic(persistedTag.Id, request.TagViewModel.AccountID, request.TagViewModel.ContactId, request.TagViewModel.CreatedBy, true);

            if (request.TagViewModel.ContactId != 0)
            {
                contactService.ContactIndexing(new ContactIndexingRequest()
                {
                    ContactIds = new List <int>()
                    {
                        request.TagViewModel.ContactId
                    }, Ids = new Dictionary <int, bool>()
                    {
                        { request.TagViewModel.ContactId, true }
                    }.ToLookup(o => o.Key, o => o.Value)
                });
            }
            //persistedTag.TagNameAutoComplete.Output = persistedTag.LeadScoreTag == true ? persistedTag.TagName + " *" : persistedTag.TagName;
            indexingService.IndexTag(persistedTag);

            request.TagViewModel.TagID = persistedTag.Id;

            SaveTagResponse response = new SaveTagResponse();

            response.TagViewModel = request.TagViewModel;
            return(response);
        }
Exemplo n.º 4
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());
        }