예제 #1
0
        protected override async Task ApplyUserUpdates(BrideForeverDataContext context, User user, DateTime currentDay)
        {
            var bonuses = await _brideForeverService.GetUserBonuses(new[] { user }, currentDay);

            var existingRecord = await context.UserBonuses.FirstOrDefaultAsync(b =>
                                                                               b.User.ID == user.ID && b.Date == currentDay);

            context.UserBonuses.AddOrUpdate(u => u.Id, new UserBonuses
            {
                Id      = existingRecord?.Id ?? Guid.NewGuid(),
                User    = user,
                Date    = currentDay,
                Bonuses = bonuses.ToBytes()
            });
        }
        public async Task <IEnumerable <UserBonusModel> > GetUserBonusToday(DateTime date, [FromUri] string[] userNames)
        {
            var users = await GetUsefulUsers(userNames);

            var userBonuses = await _brideForeverService.GetUserBonuses(users.ToArray(), date);

            //TODO user automapper
            return(userBonuses.Select(bonus => new UserBonusModel
            {
                User = new UserModel
                {
                    Title = bonus.User.Name
                },

                Bonus = new BonusModel
                {
                    Daily = bonus.Today,
                    Monthly = bonus.LastMonth
                }
            }));
        }