예제 #1
0
        public IActionResult Edit(int?id)
        {
            var customscontext    = db.Forests.Include(c => c.PointName).Include(d => d.Loc).Include(d => d.FIO).Include(d => d.SortD);
            var items             = customscontext.Where(d => d.ForestID == id).ToList();
            var agents            = new SelectList(db.Appointments, "PointID", "PointName", items.First().PointID);
            var goods             = new SelectList(db.Mazists, "CarID", "FIO", items.First().CarID);
            var products          = new SelectList(db.Sorts, "SortID", "SortD", items.First().SortID);
            var loc               = new SelectList(db.Locations, "LocID", "Loc", items.First().LocID);
            ForestsViewModel duti = new ForestsViewModel
            {
                Forests          = items,
                ForestViewModel  = _duti,
                MazistsList      = goods,
                SortsList        = products,
                LocList          = loc,
                AppointmentsList = agents
            };

            return(View(duti));
        }
예제 #2
0
        public IActionResult Details(int?id)
        {
            var customscontext = db.Forests.Include(c => c.FIO).Include(d => d.PointName).Include(d => d.Loc).Include(d => d.SortD);
            var items          = customscontext.Where(d => d.ForestID == id).ToList();
            var agents         = new SelectList(db.Appointments, "PointID", "PointName");
            var goods          = new SelectList(db.Mazists, "CarID", "FIO");
            var products       = new SelectList(db.Sorts, "SortID", "SortD");
            var loc            = new SelectList(db.Locations, "LocID", "Loc");

            ForestViewModel dutiView = new ForestViewModel
            {
                ForestID          = items.First().ForestID,
                FIO               = items.First().FIO.FIO,
                SortD             = items.First().SortD.SortD,
                PointName         = items.First().PointName.PointName,
                Quarter           = items.First().Quarter,
                Location          = items.First().Loc.Loc,
                DateOfAppointment = items.First().DateOfAppointment
            };
            ForestsViewModel dutis = new ForestsViewModel
            {
                Forests          = items,
                ForestViewModel  = _duti,
                MazistsList      = agents,
                SortsList        = products,
                LocList          = loc,
                AppointmentsList = goods
            };

            if (items == null)
            {
                return(View("NotFound"));
            }
            else
            {
                return(View(dutis));
            }
        }
예제 #3
0
        //[Authorize(Roles = "MainAdmin, user")]
        public IActionResult Index(int?agent, int?name, int?sort, int?forest, int page = 1, SortState sortOrder = SortState.DateOfAppointmentDesc)
        {
            int pageSize = 10;
            IQueryable <Forest> source = db.Forests.Include(d => d.FIO)
                                         .Include(d => d.PointName)
                                         .Include(d => d.SortD)
                                         .Include(d => d.Loc);

            // .Include(d => d.Lght.Sorte);
            if (agent != null && agent != 0)
            {
                source = source.Where(p => p.CarID == agent);
            }
            if (name != null && name != 0)
            {
                source = source.Where(p => p.PointID == name);
            }
            if (sort != null && sort != 0)
            {
                source = source.Where(p => p.SortID == sort);
            }
            if (forest != null && forest != 0)
            {
                source = source.Where(p => p.ForestID == forest);
            }
            switch (sortOrder)
            {
            case SortState.ForestIDAsc:
                source = source.OrderBy(s => s.ForestID);
                break;

            case SortState.ForestIDDesc:
                source = source.OrderByDescending(s => s.ForestID);
                break;

            case SortState.FIOAsc:
                source = source.OrderBy(s => s.FIO.FIO);
                break;

            case SortState.FIODesc:
                source = source.OrderByDescending(s => s.FIO.FIO);
                break;

            case SortState.SortDAsc:
                source = source.OrderBy(s => s.SortD.SortD);
                break;

            case SortState.SortDDesc:
                source = source.OrderByDescending(s => s.SortD.SortD);
                break;

            case SortState.PointNameAsc:
                source = source.OrderBy(s => s.PointName.PointName);
                break;

            case SortState.PointNameDesc:
                source = source.OrderByDescending(s => s.PointName.PointName);
                break;

            case SortState.QuarterAsc:
                source = source.OrderBy(s => s.Quarter);
                break;

            case SortState.QuarterDesc:
                source = source.OrderByDescending(s => s.Quarter);
                break;

            case SortState.LocAsc:
                source = source.OrderBy(s => s.Loc.Loc);
                break;

            case SortState.LocDesc:
                source = source.OrderByDescending(s => s.Loc.Loc);
                break;

            case SortState.DateOfAppointmentAsc:
                source = source.OrderBy(s => s.DateOfAppointment);
                break;

            case SortState.DateOfAppointmentDesc:
                source = source.OrderByDescending(s => s.DateOfAppointment);
                break;
            }
            var count = source.Count();
            var items = source.Skip((page - 1) * pageSize).Take(pageSize).ToList();

            PageViewModel    pageViewModel = new PageViewModel(count, page, pageSize);
            ForestsViewModel duti          = new ForestsViewModel
            {
                Forests         = items,
                ForestViewModel = _duti,
                PageViewModel   = pageViewModel,
                SortViewModel   = new ForestsSortViewModel(sortOrder),
                FilterViewModel = new ForestsFilterViewModel(db.Mazists.ToList(), db.Appointments.ToList(), db.Sorts.ToList(), db.Forests.ToList(), agent, name, sort, forest)
            };

            return(View(duti));
        }