private ActionResult ChooseOldReport(CathedraReport oldReport, List <Publication> allPublications)
        {
            var viewModel = ReportConverter.ConvertToViewModel(oldReport);

            viewModel.PrintedPublicationBudgetTheme = allPublications
                                                      .Select(x =>
            {
                var option = new PublicationOption()
                {
                    Checked = false,
                    Id      = x.ID,
                    Name    = x.Name
                };
                if (viewModel.PrintedPublicationBudgetTheme.Any(y => y.Id == x.ID))
                {
                    option.Checked = true;
                }
                return(option);
            })
                                                      .ToList();
            viewModel.PrintedPublicationHospDohovirTheme = allPublications
                                                           .Select(x =>
            {
                var option = new PublicationOption()
                {
                    Checked = false,
                    Id      = x.ID,
                    Name    = x.Name
                };
                if (viewModel.PrintedPublicationHospDohovirTheme.Any(y => y.Id == x.ID))
                {
                    option.Checked = true;
                }
                return(option);
            })
                                                           .ToList();
            viewModel.PrintedPublicationThemeInWorkTime = allPublications
                                                          .Select(x =>
            {
                var option = new PublicationOption()
                {
                    Checked = false,
                    Id      = x.ID,
                    Name    = x.Name
                };
                if (viewModel.PrintedPublicationThemeInWorkTime.Any(y => y.Id == x.ID))
                {
                    option.Checked = true;
                }
                return(option);
            })
                                                          .ToList();
            return(View(viewModel));
        }
        private ActionResult ChooseOldReport(Report oldReport, List <Publication> allPublications)
        {
            var viewModel = ReportConverter.ConvertToViewModel(oldReport);

            viewModel.RecomendedPublication = allPublications
                                              .Select(x =>
            {
                var option = new PublicationOption()
                {
                    Checked = false,
                    Id      = x.ID,
                    Name    = x.Name
                };
                if (viewModel.RecomendedPublication.Any(y => y.Id == x.ID))
                {
                    option.Checked = true;
                }
                return(option);
            })
                                              .ToList();
            viewModel.PrintedPublication = allPublications
                                           .Select(x =>
            {
                var option = new PublicationOption()
                {
                    Checked = false,
                    Id      = x.ID,
                    Name    = x.Name
                };
                if (viewModel.PrintedPublication.Any(y => y.Id == x.ID))
                {
                    option.Checked = true;
                }
                return(option);
            })
                                           .ToList();
            viewModel.AcceptedToPrintPublication = allPublications
                                                   .Select(x =>
            {
                var option = new PublicationOption()
                {
                    Checked = false,
                    Id      = x.ID,
                    Name    = x.Name
                };
                if (viewModel.AcceptedToPrintPublication.Any(y => y.Id == x.ID))
                {
                    option.Checked = true;
                }
                return(option);
            })
                                                   .ToList();
            return(View(viewModel));
        }
        // GET: Report
        public ActionResult Index(int?stepIndex, int?reportId)
        {
            db = new ApplicationDbContext();
            ViewBag.stepIndex = stepIndex ?? 0;
            var reportVerifiedId = reportId ?? -1;

            var           currentUser    = db.Users.First(x => x.UserName == User.Identity.Name);
            var           allReports     = db.Reports.Where(x => x.User.Cathedra.ID == currentUser.Cathedra.ID && x.IsSigned && x.IsConfirmed && x.ThemeOfScientificWork != null).ToList();
            List <Report> lectorsReports = new List <Report>();

            if (stepIndex == 0)
            {
                lectorsReports = allReports.Where(x => x.ThemeOfScientificWork.Financial == Financial.БЮДЖЕТ).ToList();
            }
            else if (stepIndex == 1)
            {
                lectorsReports = allReports.Where(x => x.ThemeOfScientificWork.Financial == Financial.В_МЕЖАХ_РОБОЧОГО_ЧАСУ).ToList();
            }
            else if (stepIndex == 2)
            {
                lectorsReports = allReports.Where(x => x.ThemeOfScientificWork.Financial == Financial.ГОСПДОГОВІР).ToList();
            }
            ViewBag.AllThemeDescriptions = lectorsReports
                                           .GroupBy(x => x.ThemeOfScientificWork.ID).ToDictionary(k => k.Key.ToString(), v => v.Select(y => y.ThemeOfScientificWorkDescription).ToList());

            var themes = lectorsReports.Select(x => x.ThemeOfScientificWork).ToList();

            ViewBag.ScientificThemesByFaculty = themes.Select(x => new SelectListItem
            {
                Text  = x.Value,
                Value = x.ID.ToString(),
            }).ToList();
            CathedraReport oldReport;

            if (reportVerifiedId == -1)
            {
                oldReport = db.CathedraReport.Where(x => x.User.UserName == User.Identity.Name).FirstOrDefault();
            }
            else
            {
                oldReport = db.CathedraReport.Find(reportVerifiedId);
            }
            var allPublications = new List <Publication>();

            foreach (var r in lectorsReports)
            {
                allPublications.AddRange(r.PrintedPublication);
            }
            allPublications = allPublications.Distinct().ToList();
            if (oldReport != null)
            {
                return(ChooseOldReport(oldReport, allPublications));
            }

            var publicationOptions = allPublications
                                     .Select(x =>
            {
                var option = new PublicationOption()
                {
                    Checked = true,
                    Id      = x.ID,
                    Name    = x.Name
                };
                return(option);
            })
                                     .ToList();

            return(View(new CathedraReportViewModel()
            {
                ID = oldReport?.ID,
                PrintedPublicationBudgetTheme = publicationOptions,
                PrintedPublicationHospDohovirTheme = publicationOptions,
                PrintedPublicationThemeInWorkTime = publicationOptions,
                Patents = String.Join("\n\r", lectorsReports.Select(x => x.PatentForInevention).ToList()),
                ApplicationOnInvention = String.Join("\n\r", lectorsReports.Select(x => x.ApplicationForInevention).ToList())
            }));
        }
        // GET: Report
        public ActionResult Index(string dateFrom, string dateTo, int?stepIndex, int?reportId)
        {
            db = new ApplicationDbContext();
            string dateFromVerified = dateFrom ?? "";
            string dateToVerified   = dateTo ?? "";

            ViewBag.dateFrom  = dateFrom;
            ViewBag.dateTo    = dateTo;
            ViewBag.stepIndex = stepIndex ?? 0;
            int reportVerifiedId = reportId ?? -1;

            var currentUser = db.Users.Where(x => x.UserName == User.Identity.Name).First();
            var themes      = db.ThemeOfScientificWork
                              .Where(x => x.Cathedra.Faculty.ID == currentUser.Cathedra.Faculty.ID).ToList();

            ViewBag.ScientificThemesByFaculty = themes.Select(x => new SelectListItem
            {
                Text  = x.Value,
                Value = x.ID.ToString(),
            }).ToList();
            Report oldReport;

            if (reportVerifiedId == -1)
            {
                oldReport = db.Reports.Where(x => !x.IsSigned && x.User.UserName == User.Identity.Name).FirstOrDefault();
            }
            else
            {
                oldReport = db.Reports.Find(reportVerifiedId);
            }
            var allPublications = db.Publication.Where(x => x.User.Any(y => y.UserName == User.Identity.Name)).ToList();

            allPublications = allPublications.Where(x =>
                                                    !x.AcceptedToPrintPublicationReport.Union(x.RecomendedPublicationReport).Union(x.PrintedPublicationReport)
                                                    .Any(y => y.User.Id == currentUser.Id && (y.IsSigned || y.IsConfirmed))).ToList();
            if (oldReport != null && dateFromVerified == "" && dateToVerified == "")
            {
                return(ChooseOldReport(oldReport, allPublications));
            }

            var publicationOptions = allPublications
                                     .Select(x =>
            {
                var option = new PublicationOption()
                {
                    Checked = false,
                    Id      = x.ID,
                    Name    = x.Name
                };
                if ((dateFromVerified == "" || (dateFromVerified != "" && Convert.ToDateTime(x.Date) >= DateTime.Parse(dateFromVerified))) &&
                    (dateToVerified == "" || (dateToVerified != "" && Convert.ToDateTime(x.Date) <= DateTime.Parse(dateToVerified))))
                {
                    option.Checked = true;
                }
                return(option);
            })
                                     .ToList();

            return(View(new ReportViewModel()
            {
                ID = oldReport?.ID,
                PrintedPublication = publicationOptions,
                RecomendedPublication = publicationOptions,
                AcceptedToPrintPublication = publicationOptions
            }));
        }