示例#1
0
        private bool CloseCall(ApplicationUser applicationUser, Domain.Entities.DocumentDb.UserOrderHistory userOrderHistory, Badge badge, int startSeconds, int endSeconds, DateTime vendorClosingTime)
        {
            var closeCallBadge = applicationUser.Badges.FirstOrDefault(x => x.Id == badge.Id);

            if (CanEarnBadge(closeCallBadge, badge))
            {
                var diffInSeconds = vendorClosingTime.TimeOfDay - userOrderHistory.OrderTime.TimeOfDay;
                if (diffInSeconds.TotalSeconds > startSeconds && diffInSeconds.TotalSeconds <= endSeconds)
                {
                    if (closeCallBadge == null)
                    {
                        var closeCallBadgeMap = MapBadge(badge);
                        closeCallBadgeMap.TimesEarned += 1;
                        applicationUser.Badges.Add(closeCallBadgeMap);
                    }
                    else
                    {
                        closeCallBadge.TimesEarned += 1;
                    }
                    return(true);
                }
            }

            return(false);
        }
示例#2
0
        private void CalculateStatistics(ApplicationUser applicationUser, Domain.Entities.DocumentDb.UserOrderHistory userOrderHistory)
        {
            if (!userOrderHistory.StatisticsProcessed)
            {
                var monthlyTotal =
                    applicationUser.Statistics.MonthlyTotals.FirstOrDefault(x =>
                                                                            x.MonthDate == x.ParseMonth(userOrderHistory.OrderTime));
                if (monthlyTotal == null)
                {
                    monthlyTotal = new MonthlyTotal(userOrderHistory.OrderTime);
                    applicationUser.Statistics.MonthlyTotals.Add(monthlyTotal);
                }

                var yearlyTotal =
                    applicationUser.Statistics.YearlyTotals.FirstOrDefault(x =>
                                                                           x.YearDate == x.ParseYear(userOrderHistory.OrderTime));
                if (yearlyTotal == null)
                {
                    yearlyTotal = new YearlyTotal(userOrderHistory.OrderTime);
                    applicationUser.Statistics.YearlyTotals.Add(yearlyTotal);
                }

                var weeklyTotal =
                    applicationUser.Statistics.WeeklyTotals.FirstOrDefault(x =>
                                                                           x.WeekDate == x.ParseWeek(userOrderHistory.OrderTime));
                if (weeklyTotal == null)
                {
                    weeklyTotal = new WeeklyTotal(userOrderHistory.OrderTime);
                    applicationUser.Statistics.WeeklyTotals.Add(weeklyTotal);
                }

                var dailyTotal =
                    applicationUser.Statistics.DayTotals.FirstOrDefault(x =>
                                                                        x.DayDate == x.ParseDay(userOrderHistory.OrderTime));
                if (dailyTotal == null)
                {
                    dailyTotal = new DayTotal(userOrderHistory.OrderTime);
                    applicationUser.Statistics.DayTotals.Add(dailyTotal);
                }

                foreach (var entry in userOrderHistory.Entries)
                {
                    if (entry.Pasta)
                    {
                        yearlyTotal.PastaOrderCount += 1;
                    }
                    if (entry.Healthy)
                    {
                        weeklyTotal.HealthyOrderCount += 1;
                    }

                    yearlyTotal.OrderCount  += 1;
                    yearlyTotal.Amount      += entry.FinalPrice;
                    weeklyTotal.OrderCount  += 1;
                    weeklyTotal.Amount      += entry.FinalPrice;
                    monthlyTotal.OrderCount += 1;
                    monthlyTotal.Amount     += entry.FinalPrice;
                    dailyTotal.Amount       += entry.FinalPrice;
                    dailyTotal.OrderCount   += 1;
                }

                applicationUser.Statistics.AppTotalSpend += userOrderHistory.FinalPrice;
                userOrderHistory.StatisticsProcessed      = true;

                // cleanup old data
                var daysToDelete = applicationUser.Statistics.DayTotals.Where(x => x.DayDate != x.ParseDay(DateTime.UtcNow)).ToList();
                foreach (var dayToDelete in daysToDelete)
                {
                    applicationUser.Statistics.DayTotals.Remove(dayToDelete);
                }

                var weeksToDelete = applicationUser.Statistics.WeeklyTotals.Where(x => x.WeekDate != x.ParseWeek(DateTime.UtcNow)).ToList();
                foreach (var weekToDelete in weeksToDelete)
                {
                    applicationUser.Statistics.WeeklyTotals.Remove(weekToDelete);
                }

                var monthsToDelete = applicationUser.Statistics.MonthlyTotals.Where(x => x.MonthDate != x.ParseMonth(DateTime.UtcNow)).ToList();
                foreach (var monthToDelete in monthsToDelete)
                {
                    applicationUser.Statistics.MonthlyTotals.Remove(monthToDelete);
                }

                var yearsToDelete = applicationUser.Statistics.YearlyTotals.Where(x => x.YearDate != x.ParseYear(DateTime.UtcNow)).ToList();
                foreach (var yearToDelete in yearsToDelete)
                {
                    applicationUser.Statistics.YearlyTotals.Remove(yearToDelete);
                }
            }
        }
示例#3
0
        public List <string> ExtractOrderBadges(ApplicationUser applicationUser, Domain.Entities.DocumentDb.UserOrderHistory userOrderHistory, DateTime vendorClosingTime)
        {
            CalculateStatistics(applicationUser, userOrderHistory);

            var badgeAlerts = new List <string>();

            if (AssignFirstOrder(applicationUser))
            {
                badgeAlerts.Add(OrderBadgeMessage(Domain.Constants.Badges.FirstOrder));
            }
            if (HighRoller(applicationUser))
            {
                badgeAlerts.Add(OrderBadgeMessage(Domain.Constants.Badges.HighRoller));
            }
            if (DeepPockets(applicationUser))
            {
                badgeAlerts.Add(OrderBadgeMessage(Domain.Constants.Badges.DeepPockets));
            }
            if (Consumer(applicationUser))
            {
                badgeAlerts.Add(OrderBadgeMessage(Domain.Constants.Badges.Consumer));
            }
            if (Enjoyer(applicationUser))
            {
                badgeAlerts.Add(OrderBadgeMessage(Domain.Constants.Badges.Enjoyer));
            }
            if (DieHard(applicationUser))
            {
                badgeAlerts.Add(OrderBadgeMessage(Domain.Constants.Badges.DieHard));
            }
            if (Bankrupt(applicationUser))
            {
                badgeAlerts.Add(OrderBadgeMessage(Domain.Constants.Badges.Bankrupt));
            }
            if (Healthy(applicationUser))
            {
                badgeAlerts.Add(OrderBadgeMessage(Domain.Constants.Badges.Healthy));
            }
            if (PastaAddict(applicationUser))
            {
                badgeAlerts.Add(OrderBadgeMessage(Domain.Constants.Badges.PastaAddict));
            }

            if (CloseCall(applicationUser, userOrderHistory, Domain.Constants.Badges.CloseCall15, 0, 15, vendorClosingTime))
            {
                badgeAlerts.Add(OrderBadgeMessage(Domain.Constants.Badges.CloseCall15));
            }
            ;
            if (CloseCall(applicationUser, userOrderHistory, Domain.Constants.Badges.CloseCall30, 15, 30, vendorClosingTime))
            {
                badgeAlerts.Add(OrderBadgeMessage(Domain.Constants.Badges.CloseCall30));
            }
            ;
            if (CloseCall(applicationUser, userOrderHistory, Domain.Constants.Badges.CloseCall45, 30, 45, vendorClosingTime))
            {
                badgeAlerts.Add(OrderBadgeMessage(Domain.Constants.Badges.CloseCall45));
            }
            ;
            if (CloseCall(applicationUser, userOrderHistory, Domain.Constants.Badges.CloseCall60, 45, 60, vendorClosingTime))
            {
                badgeAlerts.Add(OrderBadgeMessage(Domain.Constants.Badges.CloseCall60));
            }
            ;

            // calculation needs to be done over previously earned badges
            if (BadgeCollector(applicationUser))
            {
                badgeAlerts.Add(OrderBadgeMessage(Domain.Constants.Badges.BadgeCollector));
            }
            ;

            return(badgeAlerts);
        }