示例#1
0
        public async Task <int> GetDineCount()
        {
            int          dineCount = 0;
            List <Hotel> hotels    = await GetHotels();

            foreach (Hotel h in hotels)
            {
                HotelManager hotelManager = new HotelManager(h.ConnectionString);
                dineCount += await hotelManager.GetDineCount(DateTime.Now);
            }
            return(dineCount);
        }
示例#2
0
        public async Task <dynamic> GetUsers(Role role, int countPerPage = 0, int currPage = 0, bool withDineCount = false)
        {
            IQueryable <UserRole> linq = ctx.UserRoles.Where(p => p.Role == role).OrderByDescending(p => p.UserId);

            if (countPerPage != 0)
            {
                linq = linq.Skip(countPerPage * (currPage - 1)).Take(countPerPage);
            }

            var users = await linq.Select(p => new {
                p.User.Id,
                p.User.CreateDate,
                p.User.UserName,
                p.User.PhoneNumber,
                p.User.Email,
            }).ToListAsync();

            if (!withDineCount)
            {
                return(users);
            }

            Dictionary <string, int> userDineCounts = new Dictionary <string, int>();

            List <Hotel> hotels = await GetHotels();

            foreach (var h in hotels)
            {
                HotelManager hotelManager = new HotelManager(h.ConnectionString);
                foreach (var user in users)
                {
                    if (!userDineCounts.ContainsKey(user.Id))
                    {
                        userDineCounts[user.Id] = await hotelManager.GetDineCount(user.Id);
                    }
                    else
                    {
                        userDineCounts[user.Id] += await hotelManager.GetDineCount(user.Id);
                    }
                }
            }

            List <dynamic> userWithDineCounts = new List <dynamic>();

            foreach (var user in users)
            {
                userWithDineCounts.Add(DynamicsCombination.CombineDynamics(user, new {
                    DineCount = userDineCounts[user.Id]
                }));
            }

            return(userWithDineCounts);
        }
示例#3
0
        public async Task <List <dynamic> > GetDinePerHourCount(DateTime dateTime)
        {
            List <dynamic> list   = new List <dynamic>();
            List <Hotel>   hotels = await GetHotels();

            foreach (Hotel h in hotels)
            {
                HotelManager hotelManager = new HotelManager(h.ConnectionString);

                list.Add(new {
                    HotelName = h.Name,
                    Counts    = await hotelManager.GetDinePerHourCount(dateTime)
                });
            }
            return(list);
        }
示例#4
0
        /// <summary>
        /// 删除不是当天的未点单的匿名用户
        /// </summary>
        /// <returns></returns>
        public async Task DeleteNemoesHavenotDine()
        {
            List <User> nemoes = await ctx.UserRoles
                                 .Where(p => p.Role == Role.Nemo && SqlFunctions.DateDiff("day", p.User.CreateDate, DateTime.Now) != 0)
                                 .Select(p => p.User)
                                 .ToListAsync();

            Dictionary <string, int> userDineCounts = new Dictionary <string, int>();

            List <Hotel> hotels = await GetHotels();

            foreach (var h in hotels)
            {
                HotelManager hotelManager = new HotelManager(h.ConnectionString);
                foreach (User nemo in nemoes)
                {
                    if (!userDineCounts.ContainsKey(nemo.Id))
                    {
                        userDineCounts[nemo.Id] = await hotelManager.GetDineCount(nemo.Id);
                    }
                    else
                    {
                        userDineCounts[nemo.Id] += await hotelManager.GetDineCount(nemo.Id);
                    }
                }
            }

            foreach (User nemo in nemoes)
            {
                if (userDineCounts[nemo.Id] == 0)
                {
                    ctx.Users.Remove(nemo);
                }
            }
            await ctx.SaveChangesAsync();
        }