public CreditsHero.Subscribers.Dtos.SubscribersDto GetMember(GetSubscribersInput input)
 {
     CreditsHero.Subscribers.Dtos.SubscribersDto results = new CreditsHero.Subscribers.Dtos.SubscribersDto();
     return (CreditsHero.Subscribers.Dtos.SubscribersDto)_creditsHeroConnect.CallCreditsHeroService<SubscribersDto>(results, input,
         "api/services/app/Subscriber/GetSubscriber");
 }
        public Dtos.GetMembersOutput GetMembers(Dtos.GetMemberInput input)
        {
            if (input.MemberId != null)
            {
                var members = _memberRepository.GetMembersWithCompany(input.MemberId.Value);

                return new Dtos.GetMembersOutput
                {
                    Members = Mapper.Map<List<Dtos.MemberDto>>(members)
                };
            }
            else
            {
                if (input.CompanyId.HasValue)
                {
                    CreditsHero.Subscribers.Dtos.GetSubscribersInput inputSubscriber = new GetSubscribersInput() { CompanyId = input.CompanyId };

                    CreditsHero.Subscribers.Dtos.GetSubscribersOutput results = new GetSubscribersOutput();
                    var membersCreditsHero = (GetSubscribersOutput)_creditsHeroConnect.CallCreditsHeroService<GetSubscribersOutput>(results, inputSubscriber,
                        "api/services/app/Subscriber/GetSubscribers");

                    var membersLocal = _memberRepository.GetMembersWithCompany();

                    Dtos.GetMembersOutput members = new Dtos.GetMembersOutput();
                    members.Members = new List<Dtos.MemberDto>();

                    foreach (var item in membersCreditsHero.Subscribers)
                    {
                        SubscribersDto subscriberExt = new SubscribersDto()
                        {
                            Email = item.Email,
                            FullName = item.FullName,
                            Id = item.Id,
                            SmsNumber = item.SmsNumber,
                            SubscriberId = item.SubscriberId,
                            TotalCredits = item.TotalCredits,
                            TotalSpend = item.TotalSpend
                        };
                        var member = membersLocal.Find(c => c.Email == item.Email);
                        if (member != null)
                        {
                            Dtos.MemberDto subscriber = new Dtos.MemberDto()
                            {
                                SubscriberExt = subscriberExt,
                                FullName = member != null ? member.FullName : "",
                                Id = member != null ? member.Id : 0,
                                CellPhone = member != null ? member.CellPhone : "",
                                Company = member.Company != null ? Mapper.Map<Companies.Dtos.CompanyDto>(member.Company) : new Companies.Dtos.CompanyDto(),
                                CompanyRefId = member != null ? member.CompanyRefId : 0,
                                Email = member != null ? member.Email : "",
                                Fax = member != null ? member.Fax : "",
                                JobTitle = member != null ? member.JobTitle : "",
                                Phone = member != null ? member.Phone : "",
                                UserRefId = member != null ? member.UserRefId : 0
                            };
                            members.Members.Add(subscriber);
                        }
                    }
                    return members;
                }
                else {
                    var members = _memberRepository.GetMembersWithCompany();

                    return new Dtos.GetMembersOutput
                    {
                        Members = Mapper.Map<List<Dtos.MemberDto>>(members)
                    };
                }
            }
        }
Exemplo n.º 3
0
        public Dtos.GetInquiryResults MakeInquiry(Dtos.GetInquiryInput input)
        {
            List<CriteriaValues> searchResults = new List<CriteriaValues>();
            Dtos.GetInquiryResults returnResults = new Dtos.GetInquiryResults();
            List<SubscribersDto> searchSubscribers = new List<SubscribersDto>();

            try
            {
                var criteriaValues = _criteriaValuesRepository.GetAllCriteriaValues(input.CompanyId);
                List<CriteriaValues> criteriaValueMatch = new List<CriteriaValues>();

                foreach (KeyValuePair<string, string> item in input.QueryRequest)
                {
                    //criteriaValueMatch = criteriaValues.Where(c => c.Criteria.Name == item.Key && c.Name == item.Value).ToList<CriteriaValues>();
                    criteriaValueMatch.Add(criteriaValues.Where(c => c.Criteria.Name == item.Key && c.Name == item.Value).FirstOrDefault<CriteriaValues>());
                }

                //searchResults = criteriaValues.ToList<CriteriaValues>();
                returnResults.Results = new List<KeyValuePair<string, List<SubscribersDto>>>();
                searchResults = criteriaValueMatch;

                //If there is a match (criteraValues is not empty) then create an Inquiry
                if (searchResults.Count > 0)
                {
                    //Create Inquiry container
                    int inquiryId = _inquiryRepository.InsertAndGetId(new Inquiry(){CompanyRefId = input.CompanyId});
                    returnResults.InquiryId = inquiryId;

                    foreach (CriteriaValues item in searchResults)
                    {
                        searchSubscribers = new List<SubscribersDto>();

                        if (item != null)
                        {
                            //Create Inquiry Criteria items per Match Value
                            int inquiryExtId = _inquiryExtRepository.InsertAndGetId(new InquiryExt()
                            {
                                InquiryRefId = inquiryId,
                                CriteriaRefId = item.CriteriaRefId,
                                CriteriaValueRefId = item.Id
                            });

                            //Get a list of Subscribers associated to the criteriaValues (in SubscriptionCriteria)
                            var subscriberCritera = _subscriberCriteriaRepository.GetMatchingSubscribers(
                                item.Name, input.CompanyId, input.Latitude, input.Longitude, input.SearchDistance);
                            foreach (SubscriberCriteria subscriberItem in subscriberCritera)
                            {
                                SubscribersDto subscriber = new SubscribersDto
                                {
                                    Id = subscriberItem.Subscriber.Id,
                                    Email = subscriberItem.Subscriber.Email,
                                    FullName = subscriberItem.Subscriber.FullName,
                                    SmsNumber = subscriberItem.Subscriber.SmsNumber
                                };

                                if (!searchSubscribers.Exists(s => s.Id == subscriber.Id))
                                {
                                    searchSubscribers.Add(subscriber);

                                    ////Send text message
                                    //NotificationAppService notificationService = new NotificationAppService(_notificationRepository);
                                    //notificationService.SendNotification(new Messaging.Dtos.NotificationInput()
                                    //{
                                    //    EmailFrom = "*****@*****.**",
                                    //    EmailMessage = String.Format("Need {0}", subscriberItem.CriteriaValues.Name),
                                    //    EmailSubject = String.Format("Hello {0}: Customer needs the following: {1}", subscriber.FullName, subscriberItem.CriteriaValues.Name),
                                    //    EmailTo = subscriber.SmsNumber
                                    //});

                                    ////Send send email message
                                    ////NotificationAppService notificationService = new NotificationAppService(_notificationRepository);
                                    //notificationService.SendEmailNotification(new Messaging.Dtos.NotificationInput()
                                    //{
                                    //    EmailFrom = "*****@*****.**",
                                    //    EmailMessage = String.Format("Need {0}", subscriberItem.CriteriaValues.Name),
                                    //    EmailSubject = String.Format("Hello {0}: Customer needs the following: {1}", subscriber.FullName, subscriberItem.CriteriaValues.Name),
                                    //    EmailTo = subscriber.Email
                                    //});
                                }
                            }

                            KeyValuePair<string, List<SubscribersDto>> resultsCriteria =
                                new KeyValuePair<string, List<SubscribersDto>>(item.Name, searchSubscribers);
                            returnResults.Results.Add(resultsCriteria);
                        }
                    }

                    return returnResults;
                }
                returnResults.ResponseMessage = "There were no matching Subscribers for the Criteria.";
                return returnResults;
            }
            catch (System.Exception exc)
            {
                returnResults.ResponseMessage = exc.InnerException.Message;
                return returnResults;
            }
        }
Exemplo n.º 4
0
        public Dtos.RequestsDto CreateRequests(Dtos.CreateRequestsInput input)
        {
            int subscriberCount = 0;
            //We can use Logger, it's defined in ApplicationService class.
            //ERROR:  Logger.Info("Creating a task for input: " + input);

            var companyConfig = _companyConfigRepository.GetCompanyConfigurations(input.CompanyId);

            //Creating a new Task entity with given input's properties
            var Requests = new Request
            {
                FullName = input.FullName,
                SmsNumber = input.SmsNumber,
                Email = input.Email,
                Comment = input.Comment,
                InquiryRefId = input.InquiryId
            };

            //Saving entity with standard Insert method of repositories.
            int RequestsId = _requestsRepository.InsertAndGetId(Requests);
            Requests.Id = RequestsId;

            //Get Criteria/CriteriaValues for Company
            try
            {
                var criteriaValues = _criteriaValuesRepository.GetAllCriteriaValues(input.CompanyId);
                var inquiryCriteriavalues = _inquiryExtRepository.GetAllCriteriaValues(input.InquiryId);
                List<CriteriaValues> searchResults = new List<CriteriaValues>();
                List<SubscribersDto> searchSubscribers = new List<SubscribersDto>();
                List<CriteriaValues> criteriaValueMatch = new List<CriteriaValues>();
                List<KeyValuePair<string, string>> inquiryCriteriaValues = new List<KeyValuePair<string, string>>();

                //Get the Inquiry CriteriaValues
                var _inquiryCriteriaValues = _inquiryExtRepository.GetAllCriteriaValues(input.InquiryId);

                foreach (InquiryExt inquiry in _inquiryCriteriaValues)
                {
                    //criteriaValueMatch = criteriaValues.Where(c => c.Criteria.Name == item.Key && c.Name == item.Value).ToList<CriteriaValues>();
                    criteriaValueMatch.Add(criteriaValues.Where(c => c.Criteria.Name == inquiry.Criteria.Name && c.Name == inquiry.CriteriaValue.Name).FirstOrDefault<CriteriaValues>());
                }

                //searchResults = criteriaValues.ToList<CriteriaValues>();
                //returnResults.Results = new List<KeyValuePair<string, List<SubscribersDto>>>();
                searchResults = criteriaValueMatch;

                //If there is a match (criteraValues is not empty) then create an Inquiry
                if (searchResults.Count > 0)
                {
                    foreach (CriteriaValues item in searchResults)
                    {
                        searchSubscribers = new List<SubscribersDto>();

                        if (item != null)
                        {
                            //Get a list of Subscribers associated to the criteriaValues (in SubscriptionCriteria)
                            var subscriberCritera = _subscriberCriteriaRepository.GetMatchingSubscribers(
                                item.Name, input.CompanyId, input.Latitude, input.Longitude, 0.0M);
                            foreach (SubscriberCriteria subscriberItem in subscriberCritera)
                            {
                                SubscribersDto subscriber = new SubscribersDto
                                {
                                    Id = subscriberItem.Subscriber.Id,
                                    Email = subscriberItem.Subscriber.Email,
                                    FullName = subscriberItem.Subscriber.FullName,
                                    SmsNumber = subscriberItem.Subscriber.SmsNumber
                                };

                                if (!searchSubscribers.Exists(s => s.Id == subscriber.Id))
                                {
                                    searchSubscribers.Add(subscriber);

                                    //Send text message
                                    NotificationAppService notificationService = new NotificationAppService(_notificationRepository, _companyConfigRepository);
                                    if (subscriber.SmsNumber != null)
                                    {
                                        notificationService.SendNotification(new Messaging.Dtos.NotificationInput()
                                        {
                                            CompanyId = input.CompanyId,
                                            NotificationType = input.NotificationType,
                                            EmailFrom = input.ReplyToEmail, //"*****@*****.**",
                                            SubscriberCriteria = subscriberItem,
                                            InquiryExt = _inquiryCriteriaValues,
                                            Request = input,
                                            EmailMessage = String.Format("Need {0}", subscriberItem.CriteriaValues.Name),
                                            EmailSubject = String.Format("Hello {0}: {1} needs the following: {2}",
                                                subscriber.FullName,
                                                Requests.FullName,
                                                subscriberItem.CriteriaValues.Name),
                                            EmailTo = subscriber.SmsNumber
                                        });
                                    }

                                    //Send send email message
                                    //NotificationAppService notificationService = new NotificationAppService(_notificationRepository);
                                    if (subscriber.Email != null)
                                    {
                                        string isActive = companyConfig.Find(cc => cc.Name.Equals(System.Configuration.ConfigurationSettings.AppSettings["creditsHero_SendGrid:IsActive"])).Value != null
                                        ? companyConfig.Find(cc => cc.Name.Equals(System.Configuration.ConfigurationSettings.AppSettings["creditsHero_SendGrid:IsActive"])).Value
                                        : "false";
                                        if (isActive == "true")
                                        {
                                            notificationService.SendEmailNotification(new Messaging.Dtos.NotificationInput()
                                            {
                                                CompanyId = input.CompanyId,
                                                NotificationType = input.NotificationType,
                                                EmailFrom = input.ReplyToEmail,
                                                SubscriberCriteria = subscriberItem,
                                                InquiryExt = _inquiryCriteriaValues,
                                                Request = input,
                                                EmailMessage = String.Format("Need {0}", subscriberItem.CriteriaValues.Name),
                                                EmailSubject = String.Format("Hello {0}: {1} needs the following: {2}",
                                                subscriber.FullName,
                                                Requests.FullName,
                                                subscriberItem.CriteriaValues.Name),
                                                EmailTo = subscriber.Email
                                            });
                                        }
                                    }

                                    subscriberCount++;
                                }
                            }

                            //KeyValuePair<string, List<SubscribersDto>> resultsCriteria =
                            //    new KeyValuePair<string, List<SubscribersDto>>(item.Name, searchSubscribers);
                            //returnResults.Results.Add(resultsCriteria);
                        }
                    }
                }
            }
            catch (System.Exception exc)
            {
                return new Dtos.RequestsDto
                {
                    FullName = exc.InnerException.Message,
                    SmsNumber = input.SmsNumber,
                    Email = input.Email,
                    Id = RequestsId,
                    SubscriberCount = -1
                };
            }

            return new Dtos.RequestsDto
            {
                FullName = input.FullName,
                SmsNumber = input.SmsNumber,
                Email = input.Email,
                Id = RequestsId,
                SubscriberCount = subscriberCount
            };
        }
        public Dtos.GetSubscribersOutput GetSubscribers(Dtos.GetSubscribersInput input)
        {
            try
            {
                if (input.CompanyId.HasValue)
                {
                    var subscribers = _subscribersRepository.GetSubscribersByCompany(input.CompanyId.Value);

                    List<SubscribersDto> subscriberList = new List<SubscribersDto>();

                    foreach (var item in subscribers)
                    {
                        SubscribersDto subscriber = new SubscribersDto();
                        subscriber.Email = item.Email;
                        subscriber.FullName = item.FullName;
                        subscriber.SmsNumber = item.SmsNumber;
                        subscriber.SubscriberId = item.SubscriberId;
                        subscriber.TotalCredits = item.TotalCredits;
                        subscriber.TotalSpend = item.TotalSpend;
                        subscriberList.Add(subscriber);
                    }

                    return new Dtos.GetSubscribersOutput
                    {
                        Subscribers = subscriberList
                    };
                }
                else {
                    //Called specific GetAllWithPeople method of task repository.
                    var subscribers = _subscribersRepository.GetAll();

                    if (input.SubscribersId != null)
                    {
                        subscribers.Where(s => s.Id == input.SubscribersId);

                        List<Dtos.SubscribersDto> results = new List<SubscribersDto>();
                        Dtos.SubscribersDto subscriberDto = Mapper.Map<Dtos.SubscribersDto>(subscribers);
                        results.Add(subscriberDto);

                        //Get subscriber images from DocumentHero
                        #region Get Subscriber Image
                        var inputFileExt = new List<FileExtDto>();
                        var inputFileExtValue = new FileExtDto()
                        {
                            Key = "SubscriberId",
                            Value = input.SubscribersId.ToString(),
                            FileRefId = input.CompanyId.Value
                        };
                        inputFileExt.Add(inputFileExtValue);
                        GetFileInput fileInput = new GetFileInput();
                        fileInput.ApiKey = input.CompanyId;
                        fileInput.FileMetadata = inputFileExt;
                        //var _fileExtRepository = _iocResolver.Resolve<IFileExtRepository>();
                        //var fileService = IocManager.Instance.Resolve<FileAppService>();
                        //var imageUri = fileService.GetFiles(fileInput);

                        //DocumentHero.Files.FileAppService fileAppService = new FileAppService();
                        var resultsImage = _documentHeroService.GetAllByKeyValue(fileInput);
                        if (resultsImage.Files != null)
                        {
                            subscriberDto.ImageUri = resultsImage.Files[0].Uri;
                        }
                        #endregion

                        return new Dtos.GetSubscribersOutput
                        {
                            Subscribers = results
                        };
                    }
                    //Used AutoMapper to automatically convert List<Task> to List<TaskDto>.
                    //We must declare mappings to be able to use AutoMapper
                    return new Dtos.GetSubscribersOutput
                    {
                        Subscribers = Mapper.Map<List<Dtos.SubscribersDto>>(subscribers)
                    };
                }
            }
            catch (System.Exception exc)
            {
                Logger.Error("Error getting subscriber list", exc);
                return new Dtos.GetSubscribersOutput();
            }
        }
        public Dtos.SubscribersDto GetSubscriber(Dtos.GetSubscribersInput input)
        {
            //Get the Subscriber(s)  
            //NOTE:  If multiple subscribers come back than we need to filter based on subscribers associated to criteria for a company
            //NOTE:  May need to refactor by adding CompanyRefId to Subscriber
            List<Subscriber> subscribers = new List<Subscriber>();
            Subscriber subscriber = new Subscriber();
            SubscribersDto subscriberDto = new SubscribersDto();
            try
            {
                if (input.SubscribersEmail != string.Empty)
                {
                    subscribers = _subscribersRepository.GetSubscriberByEmail(input.SubscribersEmail);
                    if (subscribers.Count > 1)
                    {
                        int subscriberId = 0;
                        foreach (var item in subscribers)
                        {
                            List<SubscriberCriteria> scList =
                                _subscribersValuesRepository.GetSubscribersCriteriaValues(item.Id, input.CompanyId.Value);
                            if (scList != null)
                            {
                                if (scList.Count > 0)
                                {
                                    subscriberId = item.Id;
                                }
                            }
                        }
                        subscriber = subscribers.Where(s => s.Id == subscriberId).FirstOrDefault();
                        subscriberDto = subscriber.MapTo<SubscribersDto>();
                    }
                    else
                    {
                        subscriber = subscribers.FirstOrDefault();
                        subscriberDto = subscriber.MapTo<SubscribersDto>();
                        if (subscriber != null)
                        {
                            //Get subscriber images from DocumentHero
                            #region Get Subscriber Image
                            var inputFileExt = new List<FileExtDto>();
                            var inputFileExtValue = new FileExtDto()
                            {
                                Key = "SubscriberId",
                                Value = subscriber.Id.ToString(),
                                FileRefId = input.CompanyId.Value
                            };
                            inputFileExt.Add(inputFileExtValue);
                            GetFileInput fileInput = new GetFileInput();
                            fileInput.ApiKey = input.CompanyId;
                            fileInput.FileMetadata = inputFileExt;
                            //var _fileExtRepository = _iocResolver.Resolve<IFileExtRepository>();
                            //var fileService = IocManager.Instance.Resolve<FileAppService>();
                            //var imageUri = fileService.GetFiles(fileInput);

                            //DocumentHero.Files.FileAppService fileAppService = new FileAppService();
                            var resultsImage = _documentHeroService.GetAllByKeyValue(fileInput);
                            if (resultsImage.Files != null)
                            {
                                subscriberDto.ImageUri = resultsImage.Files[0].Uri;
                            }
                        }
                        #endregion

                    }
                }

                return subscriberDto;
            }
            catch(System.Exception exc)
            {
                Logger.ErrorFormat("CH_SAS_000", exc.StackTrace);
                throw exc;
            }
        }
        public Dtos.SubscribersSkillsDto GetSubscribersSkills(Dtos.GetSubscribersInput input)
        {
            //Get Subscribers Criteria to get Company
            var subscriberSkills = _subscribersValuesRepository.GetSubscribersCriteriaValues(input.SubscribersEmail, input.CompanyId.Value);
            Dtos.SubscribersSkillsDto results = new Dtos.SubscribersSkillsDto();
            results.SubscriberSkills = new List<KeyValuePair<Dtos.SubscribersDto, List<CriteriaValuesDto>>>();
            List<CriteriaValuesDto> subscriberValues = new List<CriteriaValuesDto>();
            Dtos.SubscribersDto subscribersDto = new Dtos.SubscribersDto();

            foreach(SubscriberCriteria subscriberSkill in subscriberSkills)
            {
                if (subscribersDto.Id == 0)
                {
                    subscribersDto = new Dtos.SubscribersDto { Email = subscriberSkill.Subscriber.Email, FullName = subscriberSkill.Subscriber.FullName, SmsNumber = subscriberSkill.Subscriber.SmsNumber, Id = subscriberSkill.Subscriber.Id };
                    subscriberValues = new List<CriteriaValuesDto>();
                }

                CriteriaValuesDto subscriberValuesDto = new CriteriaValuesDto{CreditCount = subscriberSkill.CriteriaValues.CreditCount, CriteriaRefId = subscriberSkill.CriteriaValues.CriteriaRefId, Name = subscriberSkill.CriteriaValues.Name, Id = subscriberSkill.CriteriaValues.Id};
                subscriberValues.Add(subscriberValuesDto);
            }

            KeyValuePair<Dtos.SubscribersDto, List<CriteriaValuesDto>> subscriberCriteria =
                        new KeyValuePair<Dtos.SubscribersDto, List<CriteriaValuesDto>>(subscribersDto, subscriberValues);

            results.SubscriberSkills.Add(subscriberCriteria);

            return results;
        }
        public Dtos.GetSubscribersOutput GetSubscribersByCompany(Dtos.GetSubscribersInput input)
        {
            try
            {
                if (input.CompanyId.HasValue && input.RequestId.HasValue)
                {
                    var subscribers = _subscribersRepository.GetSubscribersByRequest(input.CompanyId.Value, input.RequestId.Value);

                    List<SubscribersDto> subscriberList = new List<SubscribersDto>();

                    foreach (var item in subscribers)
                    {
                        SubscribersDto subscriber = new SubscribersDto();
                        subscriber.Email = item.Email;
                        subscriber.FullName = item.FullName;
                        subscriber.SmsNumber = item.SmsNumber;
                        subscriber.SubscriberId = item.SubscriberId;
                        subscriber.TotalCredits = item.TotalCredits;
                        subscriber.TotalSpend = item.TotalSpend;
                        subscriberList.Add(subscriber);
                    }

                    return new Dtos.GetSubscribersOutput
                    {
                        Subscribers = subscriberList
                    };
                }
                else {
                    return new Dtos.GetSubscribersOutput
                    {
                        Subscribers = new List<SubscribersDto>()
                    };
                }
            }
            catch (System.Exception exc)
            {
                Logger.Error("Error getting subscriber list", exc);
                return new Dtos.GetSubscribersOutput();
            }
        }
Exemplo n.º 9
0
 public CreditsHero.Subscribers.Dtos.SubscribersDto GetMember(GetSubscribersInput input)
 {
     CreditsHero.Subscribers.Dtos.SubscribersDto results = new CreditsHero.Subscribers.Dtos.SubscribersDto();
     return((CreditsHero.Subscribers.Dtos.SubscribersDto)_creditsHeroConnect.CallCreditsHeroService <SubscribersDto>(results, input,
                                                                                                                     "api/services/app/Subscriber/GetSubscriber"));
 }