private async Task<CreditsHero.Subscribers.Dtos.GetSubscribersInput> BuildCreditsHeroSubscriberInput(Users.User appUser)
        {
            //Build the Credits Hero Subscriber/User input object.  This object is used throughout the site in order
            //  to retrieve CreditsHeros' version of the user/subscriber
            CreditsHero.Subscribers.Dtos.GetSubscribersInput input = new CreditsHero.Subscribers.Dtos.GetSubscribersInput()
            {
                SubscribersId = Int32.Parse(appUser.Id.ToString()),
                CompanyId = Guid.Parse(System.Web.Configuration.WebConfigurationManager.AppSettings["creditsHero:APIKey"]),
                SubscribersEmail = appUser.EmailAddress,
                SubscribersName = appUser.UserName
            };

            var creditsHeroSubscriber = _memberAppService.GetMember(input);
            input.SubscribersId = creditsHeroSubscriber.Id;

            return input;
        }
        public Dtos.SubscriberQuotesDto GetSubscriberQuotes(GetSubscribersInput input)
        {
            var subscriberQuotes = _subscriberQuoteRepository.GetSubscriberQuotes(input.SubscribersId.Value);
            Dtos.SubscriberQuotesDto results = new Dtos.SubscriberQuotesDto();
            results.SubscriberQuotesList = new List<Dtos.SubscriberQuoteDto>();

            foreach (var item in subscriberQuotes)
                results.SubscriberQuotesList.Add(new Dtos.SubscriberQuoteDto
                {
                    CriteriaName = item.CriteriaName,
                    CriteriaValue = item.CriteriaValue,
                    InquiryCreationTime = item.InquiryCreationTime,
                    InquiryId = item.InquiryId,
                    QuoteCost = item.QuoteCost.ToString(),
                    QuoteId = item.QuoteId,
                    QuoteMessage = item.QuoteMessage,
                    QuotesSubmitted = item.QuotesSubmitted,
                    RequestComment = item.RequestComment,
                    RequestEmail = item.RequestEmail,
                    RequestFullName = item.RequestFullName,
                    RequestSmsNumber = item.RequestSmsNumber,
                    SubscriberId = item.SubscriberId,
                    RequestId = item.RequestId
                });

            return results;
        }
        public ReportRequestDetailsOutput ReportRequestDetails(ReportRequestsInput input)
        {
            ReportRequestDetailsOutput results = new ReportRequestDetailsOutput();

            //Get Request Header
            var leadHeader = (ReportRequestsOutput)_creditsHeroConnect.CallCreditsHeroService<ReportRequestsOutput>(results, input,
                "api/services/app/Requests/ReportRequests");

            //Get Subscribers for the Request
            GetSubscribersInput inputSubscriber = new GetSubscribersInput() { CompanyId = input.CompanyRefId, RequestId = input.RequestRefId };
            var subscribers = _creditsHeroConnect.CallCreditsHeroService<GetSubscribersOutput>(results, inputSubscriber,
                "api/services/app/Subscriber/GetSubscribersByCompany");

            //Get the Request Details
            var details = _creditsHeroConnect.CallCreditsHeroService<ReportRequestDetailsOutput>(results, input,
                "api/services/app/Requests/ReportRequestDetails");

            results.Header = leadHeader;
            results.Details = ((ReportRequestDetailsOutput)details).Details;
            results.Subscribers = ((GetSubscribersOutput)subscribers).Subscribers;

            return results;
        }
        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)
                    };
                }
            }
        }
 public SubscribersCreditsDto GetMemberCredits(GetSubscribersInput input)
 {
     SubscribersCreditsDto results = new SubscribersCreditsDto();
     return (SubscribersCreditsDto)_creditsHeroConnect.CallCreditsHeroService<SubscribersCreditsDto>(results, input,
         "api/services/app/Subscriber/GetSubscriberCredits");
 }
 public CreditsHero.Messaging.Dtos.SubscriberQuotesDto GetMemberQuotes(GetSubscribersInput input)
 {
     GetQuotesInput inputQuote = new GetQuotesInput()
     {
         CompanyId = input.CompanyId.Value,
         SubscriberRefId = input.SubscribersId.Value,
         QuoteStatus = ""
     };
     CreditsHero.Messaging.Dtos.SubscriberQuotesDto results = new CreditsHero.Messaging.Dtos.SubscriberQuotesDto();
     return (CreditsHero.Messaging.Dtos.SubscriberQuotesDto)_creditsHeroConnect.CallCreditsHeroService<SubscriberQuotesDto>(results, inputQuote,
         "api/services/app/Quotes/GetSubscriberQuotesByStatus");
 }
 public CreditsHero.Subscribers.Dtos.SubscribersRequestsDto GetMemberRequests(GetSubscribersInput input)
 {
     CreditsHero.Subscribers.Dtos.SubscribersRequestsDto results = new CreditsHero.Subscribers.Dtos.SubscribersRequestsDto();
     return (CreditsHero.Subscribers.Dtos.SubscribersRequestsDto)_creditsHeroConnect.CallCreditsHeroService<SubscribersRequestsDto>(results, input,
         "api/services/app/Subscriber/GetSubscribersRequests");
 }
 public SubscribersSkillsDto GetMemberSubscriptions(GetSubscribersInput input)
 {
     CreditsHero.Subscribers.Dtos.SubscribersSkillsDto results = new SubscribersSkillsDto();
     return (CreditsHero.Subscribers.Dtos.SubscribersSkillsDto)_creditsHeroConnect.CallCreditsHeroService<SubscribersSkillsDto>(results, input,
         "api/services/app/Subscriber/GetSubscribersSkills");
 }
 public CreditsHero.Common.Dtos.GetCriteriaOutput GetCriteria(GetSubscribersInput input)
 {
     CreditsHero.Common.Dtos.GetCriteriaOutput results = new CreditsHero.Common.Dtos.GetCriteriaOutput();
     return (CreditsHero.Common.Dtos.GetCriteriaOutput)_creditsHeroConnect.CallCreditsHeroService<CreditsHero.Common.Dtos.GetCriteriaOutput>(results, input,
         "api/services/app/Criteria/GetCriteria");
 }
        public Dtos.GetMembersOutput GetRequestMembers(Dtos.GetMemberInput input)
        {
            if (input.RequestId != null && input.CompanyId != null)
            {
                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/GetSubscribersByCompany");

                return new Dtos.GetMembersOutput
                {
                    Members = Mapper.Map<List<Dtos.MemberDto>>(membersCreditsHero)
                };
            }
            else
            {
                return new Dtos.GetMembersOutput
                {
                    Members = new List<MemberDto>()
                };
            }
        }
        public async Task<ActionResult> Quote(string requestId)
        {
            requestId = requestId == null ? Request.Form["PassRequestId"] : requestId;
            Models.Member.MemberRequestDetailViewModel results = new Models.Member.MemberRequestDetailViewModel();
            //Get the subscribers email to pass into CreditsHero in order to retreive summary
            var user = await _userManager.GetUserByIdAsync(AbpSession.UserId.Value);

            CreditsHero.Subscribers.Dtos.GetSubscribersInput input = new CreditsHero.Subscribers.Dtos.GetSubscribersInput()
            {
                SubscribersId = Int32.Parse(user.Id.ToString()),
                CompanyId = Guid.Parse(System.Web.Configuration.WebConfigurationManager.AppSettings["creditsHero:APIKey"]),
                SubscribersEmail = user.EmailAddress,
                SubscribersName = user.UserName
            };

            CreditsHero.Subscribers.Dtos.GetSubscribersRequestDetailInput inputRequest = new CreditsHero.Subscribers.Dtos.GetSubscribersRequestDetailInput()
            {
                SubscribersId = Int32.Parse(user.Id.ToString()),
                CompanyId = Guid.Parse(System.Web.Configuration.WebConfigurationManager.AppSettings["creditsHero:APIKey"]),
                SubscribersEmail = user.EmailAddress,
                SubscribersName = user.UserName,
                RequestId = requestId != null ? Int32.Parse(requestId) : 0
            };

            var creditsHeroSubscriber = _memberAppService.GetMember(input);
            input.SubscribersId = creditsHeroSubscriber.Id;
            inputRequest.SubscribersId = creditsHeroSubscriber.Id;

            //Get Members credits
            var creditsHeroSubscriberCredits = _memberAppService.GetMemberCredits(input);
            ViewBag.MemberCreditsRemaining = Math.Round(creditsHeroSubscriberCredits.TotalCredits);

            if (Request.Form.Keys[0] != null && Request.Form.Keys[0] == "PassRequestId")
            {
                _memberAppService.UpdateSubscriberRequestState(
                    new CreateSubscriberRequestStateInput()
                    {
                        CompanyId = Guid.Parse(System.Web.Configuration.WebConfigurationManager.AppSettings["creditsHero:APIKey"]),
                        RequestId = Int32.Parse(requestId),
                        SubscribersId = input.SubscribersId,
                        Status = "Pass"
                    });
                return Redirect(Url.Action("Index", "Home"));
            }
            else
            {
                List<SubscribersRequestDetailDto> subscriberRequestDetails = _memberAppService.GetMemberRequestDetails(inputRequest).SubscriberRequestDetailsList;
                results.SubscriberRequestDetails = new List<SubscribersRequestDetailDto>();

                results.SubscriberRequestDetails = subscriberRequestDetails;
                results.RequestId = Int32.Parse(requestId);
                results.SubscriberId = creditsHeroSubscriber.Id;
                return View(results);
            }
        }
 public CreditsHero.Subscribers.Dtos.SubscribersInquiriesDto GetCustomerInquiries(GetSubscribersInput input)
 {
     CreditsHero.Subscribers.Dtos.SubscribersInquiriesDto results = new CreditsHero.Subscribers.Dtos.SubscribersInquiriesDto();
     return (CreditsHero.Subscribers.Dtos.SubscribersInquiriesDto)_creditsHeroConnect.CallCreditsHeroService<SubscribersInquiriesDto>(results, input,
         "api/services/app/Subscriber/GetSubscribersInquiries");
 }
        public async Task<ActionResult> Index()
        {
            var identity = (ClaimsIdentity)User.Identity;
            IEnumerable<Claim> claims2 = identity.Claims;
            if (!identity.IsAuthenticated)
            {
                return View();
                //return RedirectToAction("PublicIndex", "Home");
            }
            else
            {
                var role = identity.FindFirst(ClaimTypes.Role).Value;

                if (role == "Member")
                {
                    //Get the subscribers email to pass into CreditsHero in order to retreive summary
                    var user = await _userManager.GetUserByIdAsync(AbpSession.UserId.Value);

                    CreditsHero.Subscribers.Dtos.GetSubscribersInput input = new CreditsHero.Subscribers.Dtos.GetSubscribersInput()
                    {
                        SubscribersId = Int32.Parse(user.Id.ToString()),
                        CompanyId = Guid.Parse(System.Web.Configuration.WebConfigurationManager.AppSettings["creditsHero:APIKey"]),
                        SubscribersEmail = user.EmailAddress,
                        SubscribersName = user.UserName
                    };

                    var creditsHeroSubscriber = _memberAppService.GetMember(input);
                    input.SubscribersId = creditsHeroSubscriber.Id;

                    Models.Member.MemberSummaryViewModel results = new Models.Member.MemberSummaryViewModel();
                    Models.Member.MemberQuotesViewModel resultsQuotes = new Models.Member.MemberQuotesViewModel();
                    List<SubscribersInquiryDto> subscriberInquiries = _memberAppService.GetMemberInquiries(input).SubscriberInquiryList;
                    List<SubscribersRequestDto> subscriberRequests = _memberAppService.GetMemberRequests(input).SubscriberRequestList;
                    List<SubscriberQuoteDto> subscriberQuotes = _memberAppService.GetMemberQuotes(input).SubscriberQuotesList;
                    SubscribersCreditsDto subscriberCredits = _memberAppService.GetMemberCredits(input);

                    results.SubscriberInquiries.SubscriberInquiryList = new List<SubscribersInquiryDto>();

                    results.CreditsRemainingCount = subscriberCredits.TotalCredits;
                    results.SubscriberInquiriesCount = subscriberInquiries.Count;
                    //Build Inquiry Model
                    results.SubscriberInquiries.SubscriberInquiryList = subscriberInquiries;
                    //Build Requests Model
                    results.SubscriberRequests = subscriberRequests;
                    foreach (var item in subscriberQuotes)
                    {
                        var subscriberRequestItem = results.SubscriberRequests.Find(x => x.RequestId == item.RequestId);
                        if (subscriberRequestItem != null)
                        {
                            results.SubscriberRequests.Remove(subscriberRequestItem);
                        }
                    }
                    //Build Quotes Model
                    resultsQuotes.SubscriberQuotes = subscriberQuotes;
                    results.SubscriberQuotes = resultsQuotes;

                    return RedirectToAction("PublicIndex", "Home", results);
                }
                else if (role == "Customer")
                {
                    return View();
                }
                else
                {
                    GetMemberInput memberInput = new GetMemberInput() { CompanyId = Guid.Parse(System.Web.Configuration.WebConfigurationManager.AppSettings["creditsHero:APIKey"]) };
                    GetMembersOutput subscribersOutput = _memberAppService.GetMembers(memberInput);
                    Models.Member.MemberSummaryViewModel member = new Models.Member.MemberSummaryViewModel();

                    Decimal totalSpend = 0.0M;
                    Decimal totalCredits = 0.0M;
                    foreach (var item in subscribersOutput.Members)
                    {
                        totalSpend += item.SubscriberExt.TotalSpend.HasValue ? item.SubscriberExt.TotalSpend.Value : 0.0M;
                        totalCredits += item.SubscriberExt.TotalCredits.HasValue ? item.SubscriberExt.TotalCredits.Value : 0.0M;
                    }

                    member.TotalCredits = totalCredits;
                    member.TotalSpend = totalSpend;
                    member.TotalMembers = subscribersOutput.Members.Count;

                    return RedirectToAction("PublicIndex", "Home", new Models.Member.MemberSummaryViewModel
                    {
                        TotalCredits = member.TotalCredits,
                        TotalSpend = member.TotalSpend,
                        TotalMembers = member.TotalMembers
                    });
                }
            }
        }