public SortExperimentsViewModel(ExperimentsSortState sortOrder)
 {
     IdExperimentAscSort = sortOrder == ExperimentsSortState.IdExperimentAsc ? ExperimentsSortState.IdExperimentDesc : ExperimentsSortState.IdExperimentAsc;
     IdSampleAscSort     = sortOrder == ExperimentsSortState.IdSampleAsc ? ExperimentsSortState.IdSampleDesc : ExperimentsSortState.IdSampleAsc;
     DatesAscSort        = sortOrder == ExperimentsSortState.DatesAsc ? ExperimentsSortState.DatesDesc : ExperimentsSortState.DatesAsc;
     StartTimeAscSort    = sortOrder == ExperimentsSortState.StartTimeAsc ? ExperimentsSortState.StartTimeDesc : ExperimentsSortState.StartTimeAsc;
     EndTimeAscSort      = sortOrder == ExperimentsSortState.EndTimeAsc ? ExperimentsSortState.EndTimeDesc : ExperimentsSortState.EndTimeAsc;
     SupposeMassAscSort  = sortOrder == ExperimentsSortState.SupposeMassAsc ? ExperimentsSortState.SupposeMassDesc : ExperimentsSortState.SupposeMassAsc;
     ReceiveMassAscSort  = sortOrder == ExperimentsSortState.ReceiveMassAsc ? ExperimentsSortState.ReceiveMassDesc : ExperimentsSortState.ReceiveMassAsc;
     IdLaboratoryAscSort = sortOrder == ExperimentsSortState.IdLaboratoryAsc ? ExperimentsSortState.IdLaboratoryDesc : ExperimentsSortState.IdLaboratoryAsc;
     IdWorkerAscSort     = sortOrder == ExperimentsSortState.IdWorkerAsc ? ExperimentsSortState.IdWorkerDesc : ExperimentsSortState.IdWorkerAsc;
     Current             = sortOrder;
 }
        // GET: Experiments
        public IActionResult Index(int idexperiment, string namesample, DateTime?dates, TimeSpan?starttime, TimeSpan?endtime, double?supposemass, double?receivemass, int?numberlaboratory, string surname, int page = 1, ExperimentsSortState sortOrder = ExperimentsSortState.IdSampleAsc)
        {
            int pageSize = 10;
            IQueryable <Experiments> source = _context.Experiments.Include(e => e.IdLaboratoryNavigation).Include(e => e.IdSampleNavigation).Include(e => e.IdWorkerNavigation);

            if (idexperiment != 0)
            {
                source = source.Where(x => x.IdExperiment == idexperiment);
            }
            if (namesample != null)
            {
                source = source.Where(x => x.IdSampleNavigation.NameSample == namesample);
            }
            if (dates != null)
            {
                source = source.Where(x => x.Dates == dates);
            }
            if (starttime != null)
            {
                source = source.Where(x => x.StartTime == starttime);
            }
            if (endtime != null)
            {
                source = source.Where(x => x.EndTime == endtime);
            }
            if (supposemass != null && supposemass != 0)
            {
                source = source.Where(x => x.SupposeMass.Value == supposemass.Value);
            }
            if (receivemass != null && receivemass != 0)
            {
                source = source.Where(x => x.ReceiveMass.Value == receivemass.Value);
            }
            if (numberlaboratory != null && numberlaboratory != 0)
            {
                source = source.Where(x => x.IdLaboratoryNavigation.NumberLaboratory == numberlaboratory);
            }
            if (surname != null)
            {
                source = source.Where(x => x.IdWorkerNavigation.Surname == surname);
            }

            switch (sortOrder)
            {
            case ExperimentsSortState.IdExperimentAsc:
                source = source.OrderBy(x => x.IdExperiment);
                break;

            case ExperimentsSortState.IdExperimentDesc:
                source = source.OrderByDescending(x => x.IdExperiment);
                break;

            case ExperimentsSortState.IdSampleAsc:
                source = source.OrderBy(x => x.IdSample);
                break;

            case ExperimentsSortState.IdSampleDesc:
                source = source.OrderByDescending(x => x.IdSample);
                break;

            case ExperimentsSortState.DatesAsc:
                source = source.OrderBy(x => x.Dates);
                break;

            case ExperimentsSortState.DatesDesc:
                source = source.OrderBy(x => x.Dates);
                break;

            case ExperimentsSortState.StartTimeAsc:
                source = source.OrderBy(x => x.StartTime);
                break;

            case ExperimentsSortState.StartTimeDesc:
                source = source.OrderBy(x => x.StartTime);
                break;

            case ExperimentsSortState.EndTimeAsc:
                source = source.OrderBy(x => x.EndTime);
                break;

            case ExperimentsSortState.EndTimeDesc:
                source = source.OrderBy(x => x.EndTime);
                break;

            case ExperimentsSortState.SupposeMassAsc:
                source = source.OrderBy(x => x.SupposeMass);
                break;

            case ExperimentsSortState.SupposeMassDesc:
                source = source.OrderBy(x => x.SupposeMass);
                break;

            case ExperimentsSortState.ReceiveMassAsc:
                source = source.OrderBy(x => x.ReceiveMass);
                break;

            case ExperimentsSortState.ReceiveMassDesc:
                source = source.OrderBy(x => x.ReceiveMass);
                break;

            case ExperimentsSortState.IdLaboratoryAsc:
                source = source.OrderBy(x => x.IdLaboratory);
                break;

            case ExperimentsSortState.IdLaboratoryDesc:
                source = source.OrderBy(x => x.IdLaboratory);
                break;

            case ExperimentsSortState.IdWorkerAsc:
                source = source.OrderBy(x => x.IdWorker);
                break;

            case ExperimentsSortState.IdWorkerDesc:
                source = source.OrderBy(x => x.IdWorker);
                break;
            }

            var                  count    = source.Count();
            var                  items    = source.Skip((page - 1) * pageSize).Take(pageSize);
            PageViewModel        pageView = new PageViewModel(count, page, pageSize);
            ExperimentsViewModel ivm      = new ExperimentsViewModel
            {
                PageViewModel   = pageView,
                SortViewModel   = new SortExperimentsViewModel(sortOrder),
                FilterViewModel = new FilterExperimentsViewModel(idexperiment, namesample, dates, starttime, endtime, supposemass, receivemass, numberlaboratory, surname),
                Experiments     = items
            };

            return(View(ivm));
        }