Пример #1
0
        private async Task <ShiftAssignerVM> CreateVM_BDS(DateTime now)
        {
            //BDS can see his POSs' schedules
            var vm = new ShiftAssignerVM()
            {
                //Get all ids under management
                Users = await DbContext.AppUser
                        .Where(u => u.ManagerId == UserId)
                        .Select(u => new AppUserDTO(u)).ToListAsync(),
                //Get all POS under management
                POSs = await DbContext.Pos.Where(p => p.UserId == UserId)
                       .Select(p => new PosDTO(p)
                {
                    Shifts = p.PosShift
                             .Select(ps => ps.Shift)
                             .Select(s => new ShiftDTO(s)),
                    PreviousMonthSchedules = p.PosSchedule
                                             .OrderByDescending(g => g.MonthYear.Year)
                                             .ThenByDescending(g => g.MonthYear.Month)
                                             .Take(NearestMonthScheduleTake)
                                             .Select(g => new PosScheduleDTO()
                    {
                        PosScheduleId = g.PosScheduleId,
                        MonthYear     = g.MonthYear
                    }),
                    HasCurrentMonthSchedule = p.PosSchedule.Any(ps => ps.MonthYear.Year == now.Year && ps.MonthYear.Month == now.Month)
                }).AsNoTracking().ToListAsync(),
                //Current SYS Month/Year
                SystemMonthYear = now,
                AllowCreate     = AllowCreate(now)
            };

            return(vm);
        }
Пример #2
0
        private async Task <ShiftAssignerVM> CreateVM_CA(DateTime now)
        {
            //CA can see his manager POSs' schedules
            var manId = await DbContext.AppUser
                        .Where(u => u.UserId == UserId)
                        .Select(u => u.ManagerId ?? -1).FirstOrDefaultAsync();

            //manId == 1 results in empty POSs, prev schedules vm
            var vm = new ShiftAssignerVM()
            {
                //CA cant have anyone under his management
                Users = new AppUserDTO[] { },
                //Get all POS under management
                POSs = await DbContext.Pos.Where(u => u.UserId == manId)
                       .Select(p => new PosDTO(p)
                {
                    Shifts = p.PosShift
                             .Select(ps => ps.Shift)
                             .Select(s => new ShiftDTO(s)),
                    PreviousMonthSchedules = p.PosSchedule
                                             .OrderByDescending(g => g.MonthYear.Year)
                                             .ThenByDescending(g => g.MonthYear.Month)
                                             .Take(NearestMonthScheduleTake)
                                             .Select(g => new PosScheduleDTO()
                    {
                        PosScheduleId = g.PosScheduleId,
                        MonthYear     = g.MonthYear
                    }),
                    HasCurrentMonthSchedule = p.PosSchedule.Any(ps => ps.MonthYear.Year == now.Year &&
                                                                ps.MonthYear.Month == now.Month)
                }).ToListAsync(),
                //Current SYS Month/Year
                SystemMonthYear = now,
                AllowCreate     = AllowCreate(now)
            };

            return(vm);
        }