Exemplo n.º 1
0
        public ActionResult Table(string tclass, string model, string manufacturer, int?airbase, int?year, string status, string sortOrder, string SearchParam, string SearchString)
        {
            if (!User.Identity.IsAuthenticated)
            {
                return(Redirect("/Account/Login"));
            }
            ViewBag.IsOwner = AccountController.IsOwner(this);
            //формирование списков
            IQueryable <Aircraft> aircrafts = db.Aircrafts
                                              .Include(a => a.Base);
            List <String> classes       = db.Aircrafts.Select(p => p.Class).Distinct().ToList();
            List <String> models        = db.Aircrafts.Select(p => p.Model).Distinct().ToList();
            List <String> manufacturers = db.Aircrafts.Select(p => p.Manufacturer).Distinct().ToList();
            List <Base>   bases         = db.Bases.ToList();
            List <int>    years         = db.Aircrafts.Select(p => p.YearOfProduction).Distinct().ToList();

            //перенос имеющихся фильтров во вьюбэг
            ViewBag.Class        = tclass;
            ViewBag.Model        = model;
            ViewBag.Manufacturer = manufacturer;
            ViewBag.Airbase      = airbase;
            ViewBag.Year         = year;
            ViewBag.Status       = status;
            ViewBag.SearchParam  = SearchParam;
            ViewBag.SearchString = SearchString;
            //сортировка
            ViewBag.RegNumSortParm       = String.IsNullOrEmpty(sortOrder) ? "RegNum desc" : "";
            ViewBag.ClassSortParm        = sortOrder == "Class" ? "Class desc" : "Class";
            ViewBag.ModelSortParm        = sortOrder == "Model" ? "Model desc" : "Model";
            ViewBag.ManufacturerSortParm = sortOrder == "Manufacturer" ? "Manufacturer desc" : "Manufacturer";
            ViewBag.BaseSortParm         = sortOrder == "Base" ? "Base desc" : "Base";
            ViewBag.StatusSortParm       = sortOrder == "Status" ? "Status desc" : "Status";
            ViewBag.YearSortParm         = sortOrder == "Year" ? "Year desc" : "Year";
            ViewBag.ContractsSortParm    = sortOrder == "Contracts" ? "Contracts desc" : "Contracts";
            switch (sortOrder)
            {
            case "RegNum desc":
                aircrafts = aircrafts.OrderByDescending(s => s.RegistrationNumber);
                break;

            case "Class":
                aircrafts = aircrafts.OrderBy(s => s.Class);
                break;

            case "Class desc":
                aircrafts = aircrafts.OrderByDescending(s => s.Class);
                break;

            case "Model":
                aircrafts = aircrafts.OrderBy(s => s.Model);
                break;

            case "Model desc":
                aircrafts = aircrafts.OrderByDescending(s => s.Model);
                break;

            case "Manufacturer":
                aircrafts = aircrafts.OrderBy(s => s.Manufacturer);
                break;

            case "Manufacturer desc":
                aircrafts = aircrafts.OrderByDescending(s => s.Manufacturer);
                break;

            case "Base":
                aircrafts = aircrafts.OrderBy(s => s.BaseId);
                break;

            case "Base desc":
                aircrafts = aircrafts.OrderByDescending(s => s.BaseId);
                break;

            case "Status":
                aircrafts = aircrafts.OrderBy(s => s.Status);
                break;

            case "Status desc":
                aircrafts = aircrafts.OrderByDescending(s => s.Status);
                break;

            case "Year":
                aircrafts = aircrafts.OrderBy(s => s.YearOfProduction);
                break;

            case "Year desc":
                aircrafts = aircrafts.OrderByDescending(s => s.YearOfProduction);
                break;

            case "Contracts":
                aircrafts = aircrafts.OrderBy(s => s.FinishedContracts);
                break;

            case "Contracts desc":
                aircrafts = aircrafts.OrderByDescending(s => s.FinishedContracts);
                break;

            default:
                aircrafts = aircrafts.OrderBy(s => s.RegistrationNumber);
                break;
            }
            //поиск
            if (!String.IsNullOrEmpty(SearchString))
            {
                switch (SearchParam)
                {
                case "Реєстраційний номер":
                    aircrafts = aircrafts.Where(s => s.RegistrationNumber.ToUpper().Contains(SearchString.ToUpper()));
                    break;

                case "Клас":
                    aircrafts = aircrafts.Where(s => s.Class.ToUpper().Contains(SearchString.ToUpper()));
                    break;

                case "Модель":
                    aircrafts = aircrafts.Where(s => s.Model.ToUpper().Contains(SearchString.ToUpper()));
                    break;

                case "Виробник":
                    aircrafts = aircrafts.Where(s => s.Manufacturer.ToUpper().Contains(SearchString.ToUpper()));
                    break;

                case "Рік виробництва":
                    aircrafts = aircrafts.Where(s => s.YearOfProduction.ToString().ToUpper().Contains(SearchString.ToUpper()));
                    break;

                default:
                    break;
                }
            }
            ViewBag.SearchParams = new SelectList(new List <string>()
            {
                "Реєстраційний номер",
                "Клас",
                "Модель",
                "Виробник",
                "Рік виробництва"
            });
            //фильтрация
            if (!String.IsNullOrEmpty(tclass) && !tclass.Equals("Всі"))
            {
                aircrafts = aircrafts.Where(p => p.Class == tclass);
            }
            if (!String.IsNullOrEmpty(model) && !model.Equals("Всі"))
            {
                aircrafts = aircrafts.Where(p => p.Model == model);
            }
            if (!String.IsNullOrEmpty(manufacturer) && !manufacturer.Equals("Всі"))
            {
                aircrafts = aircrafts.Where(p => p.Manufacturer == manufacturer);
            }
            if (airbase != null && airbase != 0)
            {
                aircrafts = aircrafts.Where(p => p.BaseId == airbase);
            }
            if (!String.IsNullOrEmpty(status) && !status.Equals("Всі"))
            {
                aircrafts = aircrafts.Where(p => p.Status == status);
            }
            ViewBag.Aircrafts = aircrafts;
            classes.Insert(0, "Всі");
            models.Insert(0, "Всі");
            manufacturers.Insert(0, "Всі");
            bases.Insert(0, new Base {
                Adress = "Всі", Id = 0
            });
            years.Insert(0, 0);

            AircraftListViewModel blvm = new AircraftListViewModel()
            {
                Aircrafts         = aircrafts.ToList(),
                Classes           = new SelectList(classes),
                Models            = new SelectList(models),
                Manufacturers     = new SelectList(manufacturers),
                Bases             = new SelectList(bases, "Id", "Adress"),
                YearsOfProduction = new SelectList(years),
                Statuses          = new SelectList(new List <string>()
                {
                    "Всі",
                    "Вільний",
                    "Зайнятий"
                })
            };

            return(View(blvm));
        }
Exemplo n.º 2
0
        public ActionResult Table(string name, int?aircraft, string sortOrder, string SearchParam, string SearchString)
        {
            if (!User.Identity.IsAuthenticated)
            {
                return(Redirect("/Account/Login"));
            }
            ViewBag.IsOwner = AccountController.IsOwner(this);
            //формирование списков
            IQueryable <Service> services  = db.Services.Include(a => a.Aircraft);
            List <String>        names     = db.Services.Select(p => p.Name).Distinct().ToList();
            List <Aircraft>      aircrafts = db.Aircrafts.ToList();

            //перенос имеющихся фильтров во вьюбэг
            ViewBag.Name         = name;
            ViewBag.Aircraft     = aircraft;
            ViewBag.SearchParam  = SearchParam;
            ViewBag.SearchString = SearchString;
            //сортировка
            ViewBag.NameSortParm     = String.IsNullOrEmpty(sortOrder) ? "Name desc" : "";
            ViewBag.AircraftSortParm = sortOrder == "Aircraft" ? "Aircraft desc" : "Class";
            ViewBag.CostSortParm     = sortOrder == "Cost" ? "Cost desc" : "Cost";
            switch (sortOrder)
            {
            case "Name desc":
                services = services.OrderByDescending(s => s.Name);
                break;

            case "Aircraft":
                services = services.OrderBy(s => s.AircraftId);
                break;

            case "Aircraft desc":
                services = services.OrderByDescending(s => s.AircraftId);
                break;

            case "Cost":
                services = services.OrderBy(s => s.Price);
                break;

            case "Cost desc":
                services = services.OrderByDescending(s => s.Price);
                break;

            default:
                services = services.OrderBy(s => s.Name);
                break;
            }
            //поиск
            if (!String.IsNullOrEmpty(SearchString))
            {
                switch (SearchParam)
                {
                case "Реєстраційний номер техніки":
                    services = services.Where(s => s.Aircraft.RegistrationNumber.ToUpper().Contains(SearchString.ToUpper()));
                    break;

                case "Назва":
                    services = services.Where(s => s.Name.ToUpper().Contains(SearchString.ToUpper()));
                    break;

                default:
                    break;
                }
            }
            ViewBag.SearchParams = new SelectList(new List <string>()
            {
                "Реєстраційний номер техніки",
                "Назва"
            });
            //фильтрация
            if (!String.IsNullOrEmpty(name) && !name.Equals("Всі"))
            {
                services = services.Where(p => p.Name == name);
            }
            if (aircraft != null && aircraft != 0)
            {
                services = services.Where(p => p.AircraftId == aircraft);
            }
            ViewBag.Services = services;
            names.Insert(0, "Всі");
            aircrafts.Insert(0, new Aircraft {
                RegistrationNumber = "Всі", Id = 0
            });

            ServiceListViewModel blvm = new ServiceListViewModel()
            {
                Services  = services.ToList(),
                Names     = new SelectList(names),
                Aircrafts = new SelectList(aircrafts, "Id", "RegistrationNumber")
            };

            return(View(blvm));
        }
Exemplo n.º 3
0
        public ActionResult Table(string sortOrder, string SearchParam, string SearchString)
        {
            if (!User.Identity.IsAuthenticated)
            {
                return(Redirect("/Account/Login"));
            }
            ViewBag.IsOwner = AccountController.IsOwner(this);
            //формирование списков
            IQueryable <Customer> customers = db.Customers;

            //перенос имеющихся фильтров во вьюбэг
            ViewBag.SearchParam  = SearchParam;
            ViewBag.SearchString = SearchString;
            //сортировка
            ViewBag.NameSortParm     = String.IsNullOrEmpty(sortOrder) ? "Name desc" : "";
            ViewBag.BirthdaySortParm = sortOrder == "Birthday" ? "Birthday desc" : "Birthday";
            ViewBag.SortOrder        = sortOrder;
            switch (sortOrder)
            {
            case "Name desc":
                customers = customers.OrderByDescending(s => s.Name);
                break;

            case "Birthday":
                customers = customers.OrderBy(s => s.Birthday);
                break;

            case "Birthday desc":
                customers = customers.OrderByDescending(s => s.Birthday);
                break;

            default:
                customers = customers.OrderBy(s => s.Name);
                break;
            }
            //поиск
            if (!String.IsNullOrEmpty(SearchString))
            {
                switch (SearchParam)
                {
                case "Им'я":
                    customers = customers.Where(s => s.Name.ToUpper().Contains(SearchString.ToUpper()));
                    break;

                case "Номер паспорта":
                    customers = customers.Where(s => s.Passport.ToUpper().Contains(SearchString.ToUpper()));
                    break;

                case "Адреса":
                    customers = customers.Where(s => s.Adress.ToUpper().Contains(SearchString.ToUpper()));
                    break;

                default:
                    customers = customers.OrderBy(s => s.Id);
                    break;
                }
            }
            ViewBag.SearchParams = new SelectList(new List <string>()
            {
                "Им'я",
                "Номер паспорта",
                "Адреса"
            });
            //фильтрация
            ViewBag.Customers = customers;
            return(View());
        }