Exemplo n.º 1
0
        // GET: Home
        public ActionResult Home()
        {
            if (TempData["Access"] == null)
            {
                CountVisitors();
            }

            var info = new DirectoryInfo(Server.MapPath("~/AllContent/home-images"));
            ViewBag.ImageHome = info.GetFiles().OrderByDescending(t => t.CreationTime).ToList();

            var model = new OptionModel
            {
                Option = OptionList()
            };

            //Get newest book by library
            var topNewBookFromHoaLac = _dbContext.SP_OPAC_GET_NEW_ITEMS(true, 0, 10, 81).ToList();
            var topNewBookFromDetect = _dbContext.SP_OPAC_GET_NEW_ITEMS(true, 0, 10, 20).ToList();
            var topNewBookFromFSBHaNoi = _dbContext.SP_OPAC_GET_NEW_ITEMS(true, 0, 10, 111).ToList();
            var topNewBookFromDaNang = _dbContext.SP_OPAC_GET_NEW_ITEMS(true, 0, 10, 24).ToList();
            var mostUsedBook = _dbContext.FPT_SP_OPAC_GET_MOST_USE_ITEMS().ToList();
            //DateTime for counter
            var today = DateTime.Today.ToString("dd/MM/yyyy");
            var yesterday =
                new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.AddDays(-1).Day)
                    .ToString("dd/MM/yyyy");
            var thisMonth = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1).ToString("dd/MM/yyyy");
            var lastMonth = DateTime.Now.Month == 1
                ? new DateTime(DateTime.Now.AddYears(-1).Year, 12, 1).ToString("dd/MM/yyyy")
                : new DateTime(DateTime.Now.Year, DateTime.Now.AddMonths(-1).Month, 1).ToString("dd/MM/yyyy");

            foreach (var item in topNewBookFromHoaLac)
            {
                item.Content = RemoveSpecialCharacter(item.Content);
            }

            foreach (var item in topNewBookFromDetect)
            {
                item.Content = RemoveSpecialCharacter(item.Content);
            }

            foreach (var item in topNewBookFromFSBHaNoi)
            {
                item.Content = RemoveSpecialCharacter(item.Content);
            }

            foreach (var item in topNewBookFromDaNang)
            {
                item.Content = RemoveSpecialCharacter(item.Content);
            }

            foreach (var item in mostUsedBook)
            {
                item.Content = RemoveSpecialCharacter(item.Content);
            }

            //Pass newest books to view
            ViewBag.TopNewBookFromHoaLac = topNewBookFromHoaLac;
            ViewBag.TopNewBookFromDetect = topNewBookFromDetect;
            ViewBag.TopNewBookFromFSBHaNoi = topNewBookFromFSBHaNoi;
            ViewBag.TopNewBookFromDaNang = topNewBookFromDaNang;
            ViewBag.MostUsedBook = mostUsedBook;
            CounterStatistics counter = GetCounterStatistics();
            ViewBag.CounterStatistics = counter;
            ViewBag.Total = counter.GetTotal();

            //TypeID = 1 : News, 2 : Notification
            ViewBag.News = _dbContext.NOTICE_STORE.Where(t => t.TypeID == 1).OrderByDescending(t => t.CreateTime).Take(4).ToList();
            ViewBag.FullNews = _dbContext.NOTICE_STORE.Where(t => t.TypeID == 1).OrderByDescending(t => t.CreateTime).ToList();
            ViewBag.Notification = _dbContext.NOTICE_STORE.Where(t => t.TypeID == 2).OrderByDescending(t => t.CreateTime)
                .Take(4).ToList();
            ViewBag.FullNotification = _dbContext.NOTICE_STORE.Where(t => t.TypeID == 2).OrderByDescending(t => t.CreateTime).ToList();

            //Pass date for counter to view
            ViewBag.Today = today;
            ViewBag.Yesterday = yesterday;
            ViewBag.ThisMonth = thisMonth;
            ViewBag.LastMonth = lastMonth;

            TempData["CountResultList"] = 0;
            TempData["Flag"] = null;

            return View(model);
        }