public ConsumerResponseScheme(Response response, ConsumerPortfolio consumerPortfolio, ProviderPortfolio providerPortfolio)
        {
            this.Id = response.Id;
            this.ConsumerPortfolioId = response.ConsumerPortfolioId;
            this.ProviderPortfolioId = response.ProviderPortfolioId;
            this.Distance            = response.Distance;
            this.Quote       = response.Quote;
            this.DepositDue  = response.DepositDue;
            this.DepositPaid = response.DepositPaid;
            this.BalanceDue  = response.BalanceDue;
            this.BalancePaid = response.BalancePaid;

            this.Agreement = response.Agreement;
            this.Alternate = response.Alternate;

            this.Principal = (response.Current.IsAccepted ? providerPortfolio.Principal : new ProviderPrincipal());
            this.Profile   = (response.Current.IsAccepted ? providerPortfolio.Profile : new ProviderProfile()
            {
                BusinessEstablished = providerPortfolio.Profile.BusinessEstablished,
                FacilityAge = providerPortfolio.Profile.FacilityAge,
                FacilityStyle = providerPortfolio.Profile.FacilityStyle,
                FuneralDirectorExperience = providerPortfolio.Profile.FuneralDirectorExperience,
                TransportationFleetAge = providerPortfolio.Profile.TransportationFleetAge
            });

            this.Preference = consumerPortfolio.Preference;
            this.Schedule   = consumerPortfolio.Schedule;

            this.Created = response.Created;
            this.Current = response.Current;
            this.Pending = response.Pending;

            this.CanAccept = (consumerPortfolio.Request.IsAcceptAllowed && response.CanBecomeAccepted);
            this.CanReject = (consumerPortfolio.Request.IsRejectAllowed && response.CanBecomeRejected);
        }
        public ConsumerPortfolioScheme(ConsumerPortfolio consumerPortfolio)
        {
            this.Id            = consumerPortfolio.Id;
            this.AccountStatus = consumerPortfolio.AccountStatus;

            this.Principal  = consumerPortfolio.Principal;
            this.Preference = consumerPortfolio.Preference;
            this.Schedule   = consumerPortfolio.Schedule;

            this.Request = consumerPortfolio.Request;

            this.Payment = consumerPortfolio.Payment;

            this.Members = new List <ConsumerMember>();

            this.Created  = consumerPortfolio.Created;
            this.Modified = consumerPortfolio.Modified;
            this.Reminded = consumerPortfolio.Reminded;

            this.CanDelete = consumerPortfolio.CanDelete;
            this.CanSave   = consumerPortfolio.CanSave;
            this.CanSubmit = consumerPortfolio.CanSubmit;

            this.ChosenOptionsCount = consumerPortfolio.ChosenOptionsCount;
            this.PercentComplete    = consumerPortfolio.PercentComplete;
            this.TotalOptionsCount  = consumerPortfolio.TotalOptionsCount;
        }
        public bool HasChanged(ConsumerPortfolio portfolio)
        {
            if (this.Principal.HasChanged(portfolio.Principal))
            {
                return(true);
            }

            if (this.Preference.HasChanged(portfolio.Preference))
            {
                return(true);
            }

            if (this.Schedule.HasChanged(portfolio.Schedule))
            {
                return(true);
            }

            return(false);
        }
        public ConsumerMember AddMemberPortfolio(string memberId, ConsumerPortfolio portfolio)
        {
            // get the member
            var member = GetConsumerMember(memberId);

            if (!member.PortfolioIds.Contains(portfolio.Id))
            {
                // add the portfolio
                member.PortfolioIds.Add(portfolio.Id);

                // set as the current portfolio
                member.PortfolioId = portfolio.Id;

                // update in the DB
                Update(member);
            }

            return(member);
        }
        public List <Response> GenerateResponses(ConsumerPortfolio consumerPortfolio)
        {
            var responses = new List <Response>();

            // extract the longitude and latitude
            var longitude = consumerPortfolio.Preference.Proximity.Longitude.Value;
            var latitude  = consumerPortfolio.Preference.Proximity.Latitude.Value;

            // find all providers with an active account status
            var query = Query.EQ("AccountStatus", AccountStatus.Active);

            // get all providers within the specified area and using the maximum distance as specified by the consumer
            var geoResults = this.ProviderPortfolios.GeoNear(query, longitude, latitude, UNLIMITED_RESULTS, CreateGeoNearOptions(consumerPortfolio.Preference.MaxDistance));

            // iterate over each geo result hit
            foreach (var hit in geoResults.Hits)
            {
                // get the provider portfolio
                var providerPortfolio = hit.Document;

                if (!ResponseExists(consumerPortfolio, providerPortfolio))
                {
                    // generate a response for each consumer portfolio
                    var response = new Response(providerPortfolio.Id, consumerPortfolio.Id, null);

                    // set the calculated distance
                    response.Distance = Math.Round(hit.Distance, 1);

                    // save in the DB
                    this.Responses.Save(response);

                    // add this to the list of generated responses
                    responses.Add(response);
                }
            }

            return(responses);
        }
 public static IRuleBuilderOptions <T, string> IsCurrentConsumerPortfolio <T>(this IRuleBuilder <T, string> rule, ConsumerPortfolio instance)
 {
     return(rule.Must(id =>
     {
         using (var db = new MongoDbContext())
         {
             var portfolio = db.GetConsumerPortfolio(id);
             if (portfolio != null)
             {
                 // verify the modified timestamps match
                 if (instance.Modified.On == portfolio.Modified.On)
                 {
                     return true;
                 }
             }
         }
         return false;
     }));
 }
        public ProviderResponseScheme(Response response, ProviderPortfolio providerPortfolio, ConsumerPortfolio consumerPortfolio, ConsumerMember consumerMember = null)
        {
            this.Id = response.Id;
            this.ConsumerPortfolioId = response.ConsumerPortfolioId;
            this.ProviderPortfolioId = response.ProviderPortfolioId;

            this.Distance    = response.Distance;
            this.Quote       = response.Quote;
            this.DepositDue  = response.DepositDue;
            this.DepositPaid = response.DepositPaid;
            this.BalanceDue  = response.BalanceDue;
            this.BalancePaid = response.BalancePaid;

            this.Agreement = response.Agreement;
            this.Alternate = response.Alternate;

            this.Created = response.Created;
            this.Current = response.Current;
            this.Pending = response.Pending;

            this.Member     = GetConsumerMember(response, consumerMember);                                           // only show if winning bidder
            this.Principal  = (response.Current.IsAccepted ? consumerPortfolio.Principal : new ConsumerPrincipal()); // only show if winning bidder
            this.Preference = consumerPortfolio.Preference.Clone();
            this.Schedule   = consumerPortfolio.Schedule.Clone();
            this.Request    = consumerPortfolio.Request;

            this.CanBecomeAvailable = response.CanBecomeAvailable;
            this.CanBecomePending   = response.CanBecomePending;
            this.CanBecomeDismissed = response.CanBecomeDismissed;
        }
 public void Update(ConsumerPortfolio portfolio)
 {
     this.ConsumerPortfolios.Save(portfolio);
 }
 private bool ResponseExists(ConsumerPortfolio consumerPortfolio, ProviderPortfolio providerPortfolio)
 {
     return(this.Responses.FindAll().Any(item => (item.ConsumerPortfolioId == consumerPortfolio.Id && item.ProviderPortfolioId == providerPortfolio.Id)));
 }
        public List <Response> GetPendingResponses(ConsumerPortfolio consumerPortfolio)
        {
            var responses = GetResponsesForConsumerPortfolio(consumerPortfolio.Id);

            return(responses.Where(item => item.State == ResponseReceiptStates.Pending).ToList());
        }