Beispiel #1
0
        public ActionResult NotificationHome(int page)
        {
            if (Session["LibrarianName"] == null)
            {
                return(RedirectToAction("LibrarianLogin", "Login"));
            }

            var noticeListFromDb = _dbContext.NOTICE_STORE.OrderByDescending(t => t.CreateTime).ToList();
            var noticeList       = new List <Notification>();
            int size             = 10;
            int count            = 0;

            if (TempData.Peek("SearchNoticeList") != null)
            {
                noticeList = (List <Notification>)TempData.Peek("SearchNoticeList");
            }
            else
            {
                foreach (var item in noticeListFromDb)
                {
                    Notification notification = new Notification()
                    {
                        ID          = item.ID,
                        Title       = item.Title,
                        Content     = item.Content,
                        CreateTime  = item.CreateTime.ToString("HH:mm:ss dd/MM/yyyy"),
                        TypeName    = HomeDao.GetTypeNotice(item.TypeID),
                        LibraryName = HomeDao.GetLibraryCode(item.LibID)
                    };

                    noticeList.Add(notification);
                }
            }

            foreach (var item in noticeList)
            {
                count++;
                item.Count = count;
            }

            ViewBag.TypeNoticeList = _dbContext.TYPE_NOTICE.ToList();
            ViewBag.LibraryList    = _dbContext.HOLDING_LIBRARY.Where(t => t.Name != null).ToList();
            ViewBag.FirstIndex     = noticeList.ToPagedList(page, size).FirstItemOnPage;
            ViewBag.LastIndex      = noticeList.ToPagedList(page, size).LastItemOnPage;
            ViewBag.Total          = noticeList.ToPagedList(page, size).TotalItemCount;

            return(View(noticeList.ToPagedList(page, size)));
        }
Beispiel #2
0
        public ActionResult SearchNotification(string searchByTitle, int searchByType, int searchByLibrary,
                                               string startDate, string endDate)
        {
            var noticeListFromDb = _dbContext.NOTICE_STORE.AsQueryable();
            var theStartTime     = ConvertToDate(startDate);
            var theEndTime       = ConvertToDate(endDate);
            //Item1: year, Item2: month, Item3: day
            var    startDateTime = new DateTime(theStartTime.Item1, theStartTime.Item2, theStartTime.Item3);
            var    endDateTime   = new DateTime(theEndTime.Item1, theEndTime.Item2, theEndTime.Item3);
            string title         = Regex.Replace(searchByTitle, @"\s+", " ").Trim();

            if (string.IsNullOrEmpty(title) && searchByLibrary == 0 && searchByType == 0 &&
                CheckNullDateTime(startDateTime) && CheckNullDateTime(endDateTime))
            {
                TempData["SearchNoticeList"] = null;
            }
            else
            {
                if (!string.IsNullOrEmpty(title))
                {
                    noticeListFromDb = noticeListFromDb.Where(t => t.Title.Contains(title) || t.Title.Equals(title));
                }

                if (searchByType != 0)
                {
                    noticeListFromDb = noticeListFromDb.Where(t => t.TypeID == searchByType);
                }

                if (searchByLibrary != 0)
                {
                    noticeListFromDb = noticeListFromDb.Where(t => t.LibID == searchByLibrary);
                }

                if (!CheckNullDateTime(startDateTime) && !CheckNullDateTime(endDateTime))
                {
                    noticeListFromDb = noticeListFromDb.Where(t => t.CreateTime >= startDateTime && t.CreateTime <= endDateTime);
                }

                if (!CheckNullDateTime(startDateTime))
                {
                    noticeListFromDb = noticeListFromDb.Where(t => t.CreateTime >= startDateTime);
                }

                if (!CheckNullDateTime(endDateTime))
                {
                    noticeListFromDb = noticeListFromDb.Where(t => t.CreateTime <= endDateTime);
                }

                var noticeStoreList = noticeListFromDb.OrderByDescending(t => t.CreateTime).ToList();
                var noticeList      = (from t in noticeStoreList
                                       select new Notification()
                {
                    ID = t.ID,
                    Title = t.Title,
                    Content = t.Content,
                    CreateTime = t.CreateTime.ToString("HH:mm:ss dd/MM/yyyy"),
                    TypeName = HomeDao.GetTypeNotice(t.TypeID),
                    LibraryName = HomeDao.GetLibraryCode(t.LibID)
                }).ToList();

                TempData["SearchNoticeList"] = noticeList;
            }

            return(RedirectToAction("NotificationHome", new { page = 1 }));
        }