Beispiel #1
0
        public async Task <IActionResult> Office()
        {
            UserInformer        informer            = new UserInformer(User, _context, _userManager);
            WorkerPageViewModel workerPageViewModel = await informer.GetWorkerPageDataAsync(UserInformerOption.New);

            if (workerPageViewModel == null)
            {
                return(NotFound());
            }
            return(View(workerPageViewModel));
        }
Beispiel #2
0
        public async Task <IActionResult> WorkerSettings()
        {
            UserInformer        informer            = new UserInformer(User, _context, _userManager);
            WorkerPageViewModel workerPageViewModel = await informer.GetWorkerPageDataAsync(UserInformerOption.Settings);

            if (workerPageViewModel == null)
            {
                return(NotFound());
            }
            return(PartialView("_WorkerSettingsPartial", workerPageViewModel));
        }
        public async Task <WorkerPageViewModel> GetWorkerPageDataAsync(UserInformerOption dataOption)
        {
            ApplicationUser userWorker = await GetUserWorkerAsync();

            if (userWorker == null)
            {
                return(null);
            }

            WorkerSetting workerSetting = await GetWorkerSetting(userWorker);

            List <Order> newOrders = null;

            if (dataOption == UserInformerOption.All || dataOption == UserInformerOption.New)
            {
                newOrders = await Context.Orders.Include(o => o.Location)
                            .Where(o => o.StatusId == (int)OrderStatus.Active
                                   //&& o.Date > DateTime.Now
                                   && o.Location.CityId == workerSetting.CityId &&
                                   workerSetting.DistrictIds.Contains(o.Location.DistrictId) &&
                                   workerSetting.CategoryIds.Contains(o.CategoryId))
                            .Include(o => o.OrderDetails)
                            .ToListAsync();

                newOrders.Sort();
            }

            List <Order> workOrders = null;

            if (dataOption == UserInformerOption.All || dataOption == UserInformerOption.Work)
            {
                workOrders = await Context.Orders
                             .Include(o => o.User).Include(o => o.Location)
                             .Where(o => o.WorkerId == userWorker.Worker.Id &&
                                    o.StatusId == (int)OrderStatus.InProgress)
                             .Include(o => o.OrderDetails)
                             .ToListAsync();

                workOrders.Sort();
            }

            City            workerCity       = null;
            List <District> workerDistricts  = null;
            List <Category> workerCategories = null;

            switch (dataOption)
            {
            case UserInformerOption.All:
                Context.Cities.Load();
                Context.Districts.Load();
                Context.Categories.Where(c => c.ParentId != null).Load();
                Context.Services.Load();
                var tmpConcat = newOrders.Concat(workOrders);
                workerDistricts  = tmpConcat.Select(o => o.Location.District).Distinct().ToList();
                workerCategories = tmpConcat.Select(o => o.Category).Distinct().ToList();
                break;

            case UserInformerOption.New:
                Context.Districts.Where(d => d.CityId == workerSetting.CityId).Load();
                Context.Categories.Where(c => c.ParentId != null && workerSetting.CategoryIds.Contains(c.Id)).Load();
                Context.Services.Where(s => workerSetting.CategoryIds.Contains(s.CategoryId)).Load();
                workerDistricts  = newOrders.Select(o => o.Location.District).Distinct().ToList();
                workerCategories = newOrders.Select(o => o.Category).Distinct().ToList();
                break;

            case UserInformerOption.Work:
                //Context.Districts.Where(d => d.CityId == workerSetting.CityId).Load();
                //Context.Categories.Where(c => c.ParentId != null && workerSetting.CategoryIds.Contains(c.Id)).Load();
                //Context.Services.Where(s => workerSetting.CategoryIds.Contains(s.CategoryId)).Load();
                Context.Cities.Load();
                Context.Districts.Load();
                Context.Categories.Where(c => c.ParentId != null).Load();
                Context.Services.Load();
                workerDistricts  = workOrders.Select(o => o.Location.District).Distinct().ToList();
                workerCategories = workOrders.Select(o => o.Category).Distinct().ToList();
                break;

            case UserInformerOption.Settings:
                workerCity = await Context.Cities
                             .Where(c => c.Id == workerSetting.CityId)
                             .Include(c => c.Districts)
                             .SingleOrDefaultAsync();

                workerCategories = await Context.Categories.ToListAsync();

                break;

            default:
                break;
            }

            WorkerPageViewModel workerPageData = new WorkerPageViewModel
            {
                UserId        = userWorker.Id,
                WorkerId      = userWorker.Worker.Id,
                WorkerSetting = workerSetting,
                Categories    = workerCategories,
                Districts     = workerDistricts,
                City          = workerCity,
                OrdersNew     = newOrders,
                OrdersInWork  = workOrders
            };

            return(workerPageData);
        }