Ejemplo n.º 1
0
        public SortCheckViewModel(SortStateCheck sortOrder)
        {
            FailCountSort        = sortOrder == SortStateCheck.FailCountAsc ? SortStateCheck.FailCountDesc : SortStateCheck.FailCountAsc;
            CheckSubunitSort     = sortOrder == SortStateCheck.CheckSubunitAsc ? SortStateCheck.CheckSubunitDesc : SortStateCheck.CheckSubunitAsc;
            SectorSort           = sortOrder == SortStateCheck.SectorAsc ? SortStateCheck.SectorDesc : SortStateCheck.SectorAsc;
            CheckDateSort        = sortOrder == SortStateCheck.CheckDateAsc ? SortStateCheck.CheckDateDesc : SortStateCheck.CheckDateAsc;
            RegWorkerSort        = sortOrder == SortStateCheck.RegWorkerAsc ? SortStateCheck.RegWorkerDesc : SortStateCheck.RegWorkerAsc;
            ControlIndicatorSort = sortOrder == SortStateCheck.ControlIndicatorAsc ? SortStateCheck.ControlIndicatorDesc : SortStateCheck.ControlIndicatorAsc;
            FailDescriptionSort  = sortOrder == SortStateCheck.FailDescriptionAsc ? SortStateCheck.FailDescriptionDesc : SortStateCheck.FailDescriptionAsc;
            RegSubunitSort       = sortOrder == SortStateCheck.RegSubunitAsc ? SortStateCheck.RegSubunitDesc : SortStateCheck.RegSubunitAsc;
            DeleteReasonSort     = sortOrder == SortStateCheck.DeleteReasonAsc ? SortStateCheck.DeleteReasonDesc : SortStateCheck.DeleteReasonAsc;

            Current = sortOrder;
        }
        public async Task <IActionResult> Create(int?subunit, int?sector, string query, int page = 1, SortStateCheck sortOrder = SortStateCheck.FailCountAsc)
        {
            int pageSize = 10;
            IQueryable <Check> checks = db.Check.Include(c => c.RegWorkerNavigation)
                                        .Include(c => c.RegWorkerNavigation.Sector)
                                        .Include(c => c.RegWorkerNavigation.Sector.Subunit)
                                        .Include(c => c.Sector)
                                        .Include(c => c.Sector.Subunit)
                                        .Include(c => c.Shows);

            checks = checks.Where(c => c.IsActive && c.IsCorrect && c.IsFail && c.Shows.Count > 0);

            if (subunit != null && subunit != 0)
            {
                checks = checks.Where(c => c.Sector.SubunitId == subunit);

                if (sector != null && sector != 0)
                {
                    checks = checks.Where(c => c.SectorId == sector);
                }
            }

            if (!String.IsNullOrEmpty(query))
            {
                checks = checks.Where(c => c.FailCount.ToUpper().Contains(query.ToUpper()) ||
                                      c.RegWorkerNavigation.Family.ToUpper().Contains(query.ToUpper()) ||
                                      c.ControlIndicator.ToUpper().Contains(query.ToUpper()) ||
                                      c.FailDescription.ToUpper().Contains(query.ToUpper()) ||
                                      c.RegWorkerNavigation.Sector.Subunit.Name.ToUpper().Contains(query.ToUpper())
                                      );
            }

            switch (sortOrder)
            {
            case SortStateCheck.FailCountDesc:
                checks = checks.OrderByDescending(c => c.FailCount);
                break;

            case SortStateCheck.CheckSubunitAsc:
                checks = checks.OrderBy(c => c.Sector.Subunit.Name);
                break;

            case SortStateCheck.CheckSubunitDesc:
                checks = checks.OrderByDescending(c => c.Sector.Subunit.Name);
                break;

            case SortStateCheck.CheckDateAsc:
                checks = checks.OrderBy(c => c.CheckDate);
                break;

            case SortStateCheck.CheckDateDesc:
                checks = checks.OrderByDescending(c => c.CheckDate);
                break;

            case SortStateCheck.SectorAsc:
                checks = checks.OrderBy(c => c.Sector.SectorName);
                break;

            case SortStateCheck.SectorDesc:
                checks = checks.OrderByDescending(c => c.Sector.SectorName);
                break;

            case SortStateCheck.RegWorkerAsc:
                checks = checks.OrderBy(c => c.RegWorkerNavigation.Family);
                break;

            case SortStateCheck.RegWorkerDesc:
                checks = checks.OrderByDescending(c => c.RegWorkerNavigation.Family);
                break;

            case SortStateCheck.ControlIndicatorAsc:
                checks = checks.OrderBy(c => c.ControlIndicator);
                break;

            case SortStateCheck.ControlIndicatorDesc:
                checks = checks.OrderByDescending(c => c.ControlIndicator);
                break;

            case SortStateCheck.FailDescriptionAsc:
                checks = checks.OrderBy(c => c.FailDescription);
                break;

            case SortStateCheck.FailDescriptionDesc:
                checks = checks.OrderByDescending(c => c.FailDescription);
                break;

            case SortStateCheck.RegSubunitAsc:
                checks = checks.OrderBy(c => c.RegWorkerNavigation.Sector.Subunit.Name);
                break;

            case SortStateCheck.RegSubunitDesc:
                checks = checks.OrderByDescending(c => c.RegWorkerNavigation.Sector.Subunit.Name);
                break;

            default:
                checks = checks.OrderBy(c => c.FailCount);
                break;
            }

            var count = await checks.CountAsync();

            var items = await checks.Skip((page - 1) *pageSize).Take(pageSize).ToListAsync();

            CreateEventViewModel model = new CreateEventViewModel
            {
                PageViewModel   = new PageViewModel(count, page, pageSize),
                SortViewModel   = new SortCheckViewModel(sortOrder),
                FilterViewModel = new FilterCheckViewModel(db.Subunits.ToList(), db.Sectors.ToList(), subunit, sector, query),
                Checks          = items,
                DueDate         = DateTime.Now.Date
            };

            return(View(model));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Index(int?subunit, int?sector, string query, int page = 1, SortStateCheck sortOrder = SortStateCheck.FailCountAsc)
        {
            int pageSize = 10;
            IQueryable <Check> checks = db.Check.Include(c => c.RegWorkerNavigation)
                                        .Include(c => c.RegWorkerNavigation.Sector)
                                        .Include(c => c.RegWorkerNavigation.Sector.Subunit)
                                        .Include(c => c.Sector)
                                        .Include(c => c.Sector.Subunit)
                                        .Include(c => c.Events);

            checks = checks.Where(c => c.IsActive && c.IsCorrect);
            if (User.IsInRole("REG") && !User.IsInRole("CHECK_DETAIL") && !User.IsInRole("CONTROL"))
            {
                Worker worker = await _userManager.FindByNameAsync(User.Identity.Name);

                if (worker != null)
                {
                    checks = checks.Where(c => c.RegWorker == worker.Id);
                }
            }
            else if (User.IsInRole("CHECK_DETAIL") && !User.IsInRole("CONTROL"))
            {
                Worker worker = await _userManager.FindByNameAsync(User.Identity.Name);

                if (worker != null)
                {
                    db.Entry(worker).Reference(w => w.Sector).Load();
                    checks = checks.Where(c => c.Sector.SubunitId == worker.Sector.SubunitId || c.RegWorker == worker.Id);
                }
            }

            if (subunit != null && subunit != 0)
            {
                checks = checks.Where(c => c.Sector.SubunitId == subunit);

                if (sector != null && sector != 0)
                {
                    checks = checks.Where(c => c.SectorId == sector);
                }
            }
            if (!String.IsNullOrEmpty(query))
            {
                checks = checks.Where(c => c.FailCount.ToUpper().Contains(query.ToUpper()) ||
                                      c.RegWorkerNavigation.Family.ToUpper().Contains(query.ToUpper()) ||
                                      c.ControlIndicator.ToUpper().Contains(query.ToUpper()) ||
                                      c.FailDescription.ToUpper().Contains(query.ToUpper()) ||
                                      c.RegWorkerNavigation.Sector.Subunit.Name.ToUpper().Contains(query.ToUpper())
                                      );
            }

            checks = sortOrder switch
            {
                SortStateCheck.FailCountDesc => checks.OrderByDescending(c => c.FailCount),
                SortStateCheck.CheckSubunitAsc => checks.OrderBy(c => c.Sector.Subunit.Name),
                SortStateCheck.CheckSubunitDesc => checks.OrderByDescending(c => c.Sector.Subunit.Name),
                SortStateCheck.CheckDateAsc => checks.OrderBy(c => c.CheckDate),
                SortStateCheck.CheckDateDesc => checks.OrderByDescending(c => c.CheckDate),
                SortStateCheck.SectorAsc => checks.OrderBy(c => c.Sector.SectorName),
                SortStateCheck.SectorDesc => checks.OrderByDescending(c => c.Sector.SectorName),
                SortStateCheck.RegWorkerAsc => checks.OrderBy(c => c.RegWorkerNavigation.Family),
                SortStateCheck.RegWorkerDesc => checks.OrderByDescending(c => c.RegWorkerNavigation.Family),
                SortStateCheck.ControlIndicatorAsc => checks.OrderBy(c => c.ControlIndicator),
                SortStateCheck.ControlIndicatorDesc => checks.OrderByDescending(c => c.ControlIndicator),
                SortStateCheck.FailDescriptionAsc => checks.OrderBy(c => c.FailDescription),
                SortStateCheck.FailDescriptionDesc => checks.OrderByDescending(c => c.FailDescription),
                SortStateCheck.RegSubunitAsc => checks.OrderBy(c => c.RegWorkerNavigation.Sector.Subunit.Name),
                SortStateCheck.RegSubunitDesc => checks.OrderByDescending(c => c.RegWorkerNavigation.Sector.Subunit.Name),
                _ => checks.OrderBy(c => c.FailCount),
            };
            var count = await checks.CountAsync();

            var items = await checks.Skip((page - 1) *pageSize).Take(pageSize).ToListAsync();

            CheckListViewModel model = new CheckListViewModel
            {
                PageViewModel   = new PageViewModel(count, page, pageSize),
                SortViewModel   = new SortCheckViewModel(sortOrder),
                FilterViewModel = new FilterCheckViewModel(db.Subunits.ToList(), db.Sectors.ToList(), subunit, sector, query),
                Checks          = items
            };

            return(View(model));
        }