public ActionResult BooksPopularity()
        {
            if (Session["CurUsr"] == null)
            {
                Response.Redirect("SignIn");
            }
            List <BooksPopularity> BP = (from b in DM.Book.publications()
                                         let count = b.BookGiving.Count
                                                     orderby count descending
                                                     select new BooksPopularity(b.Name, b.Author, b.Publisher.Name, b.Year, count)).ToList();

            ViewData.Model = BP;
            string path = Server.MapPath("~/Files/BooksPop.xlsx");

            ExcelExecuter.XLOutput_BooksPop(path, BP);
            return(View());
        }
        public ActionResult BooksByDate()
        {
            if (Session["CurUsr"] == null)
            {
                Response.Redirect("SignIn");
            }
            List <BooksByDate> BD = (from t in DM.BG.bookGivings()
                                     where t.Give_Date == DateTime.Today
                                     select new BooksByDate(t.Reader.Library_Card, t.Reader.FIO, t.Publication.Id, t.Publication.Name, t.Publication.Author, t.Librarian.FIO, t.Expected_Return_Date.ToShortDateString())).ToList();

            ViewData.Model = BD;
            string path = Server.MapPath("~/Files/BooksByDate.xlsx");

            ExcelExecuter.XLOutput_BooksByDate(path, BD);
            Session["ChosenDate"] = DateTime.Today;
            string str = DateTime.Today.ToString("s");

            Session["ChosenDate_string"] = str.Substring(0, str.IndexOf('T'));
            return(View());
        }
        public ActionResult CountBooks()
        {
            if (Session["CurUsr"] == null)
            {
                Response.Redirect("SignIn");
            }
            ViewData["People"] = DM.Rd.readers().ToList();
            ViewData["Counts"] = (from t in DM.Rd.readers() select t.BookGiving.Count).ToList();
            var values = (from t in DM.Rd.readers()
                          select new NamePlusCountBooks(t.FIO, t.Library_Card, t.Phone_Number, t.Email, t.Registration_Date, t.BookGiving.Count)).
                         OrderBy(p => p.Count).
                         Reverse().
                         ToList();

            ViewData["AllCounts"] = values;
            string path = Server.MapPath("~/Files/CountBooks.xlsx");

            ExcelExecuter.XLOutput_NamePlusCountBooks(path, values);
            return(View());
        }
        public ActionResult PenaltyDebtors()
        {
            if (Session["CurUsr"] == null)
            {
                Response.Redirect("SignIn");
            }
            List <PenaltyDebtors> PD = (from t in DM.Rd.readers()
                                        let sum = (from p in DM.Penalty.penalties()
                                                   where p.BookReturning.BookGiving.Reader.Id == t.Id && p.Sum > 0
                                                   select p.Sum).Sum()
                                                  where sum > 0
                                                  orderby sum descending
                                                  select new PenaltyDebtors(t.FIO, t.Birthday.ToShortDateString(), t.Phone_Number, t.Email, sum)).ToList();

            ViewData.Model = PD;
            string path = Server.MapPath("~/Files/PenaltyDebt.xlsx");

            ExcelExecuter.XLOutput_PenaltyDebts(path, PD);
            return(View());
        }
        public ActionResult Debtors()
        {
            if (Session["CurUsr"] == null)
            {
                Response.Redirect("SignIn");
            }
            List <NamePlusCountBooks> NP = (from t in DM.Rd.readers()
                                            let countB = (from p in DM.BG.bookGivings()
                                                          where (p.Reader.Id == t.Id && p.BookReturning == null &&
                                                                 p.Expected_Return_Date < DateTime.Today)
                                                          select p).Count()
                                                         where countB > 0
                                                         select new NamePlusCountBooks(t.FIO, t.Library_Card, t.Phone_Number, t.Email,
                                                                                       t.Registration_Date, countB)).ToList();

            ViewData.Model      = NP;
            ViewData["Debtors"] = ViewData.Model;
            string path = Server.MapPath("~/Files/Debt.xlsx");

            ExcelExecuter.XLOutput_NamePlusCountBooks(path, NP);
            return(View());
        }