// GET: PWrInfo
        public ActionResult Index()
        {
            if (Session["UserTicket"] != null)
            {
                MessagesModel m = new MessagesModel();
                EventsModel   e = new EventsModel();

                var tuple = new Tuple <List <MessagesModel>, List <EventsModel> >
                                (m.GetMessages(new Guid(Session["UserTicket"].ToString())).OrderByDescending(msg => msg.Id).ToList(), e.GetEvents(new Guid(Session["UserTicket"].ToString())).OrderByDescending(evt => evt.Id).ToList());

                return(View(tuple));
            }
            return(Redirect("~/Login/Login"));
        }
예제 #2
0
        // GET: Messages
        public ViewResult Messages(string sortOrder, string currentFilter, string searchString, int?page)
        {
            if (Session["UserTicket"] != null)
            {
                ViewBag.CurrentSort        = sortOrder;
                ViewBag.IdSortParm         = String.IsNullOrEmpty(sortOrder) ? "id_asc" : "";
                ViewBag.UserIdParm         = sortOrder == "UserId" ? "UserId_desc" : "UserId";
                ViewBag.DepartmentSortParm = sortOrder == "DeparmentId" ? "DeparmentId_desc" : "DeparmentId";

                if (searchString != null)
                {
                    page = 1;
                }
                else
                {
                    searchString = currentFilter;
                }

                ViewBag.CurrentFilter = searchString;

                MessagesModel m = new MessagesModel();

                var messages = m.GetMessages(new Guid(Session["UserTicket"].ToString()));

                if (!String.IsNullOrEmpty(searchString))
                {
                    messages = messages.Where(s => s.title.Contains(searchString) ||
                                              s.content.Contains(searchString) ||
                                              s.departments.Name.Contains(searchString) ||
                                              s.Id.ToString().Contains(searchString) ||
                                              s.UserId.ToString().Contains(searchString));
                }
                switch (sortOrder)
                {
                case "id_asc":
                    messages = messages.OrderBy(s => s.Id);
                    break;

                case "UserId":
                    messages = messages.OrderBy(s => s.UserId);
                    break;

                case "UserId_desc":
                    messages = messages.OrderByDescending(s => s.UserId);
                    break;

                case "DeparmentId_desc":
                    messages = messages.OrderByDescending(s => s.departments.Name);
                    break;

                case "DeparmentId":
                    messages = messages.OrderBy(s => s.departments.Name);
                    break;

                default:      // id ascending
                    messages = messages.OrderByDescending(s => s.Id);
                    break;
                }

                int pageSize   = 5;
                int pageNumber = (page ?? 1);
                return(View(messages.ToPagedList(pageNumber, pageSize)));
            }

            RedirectToAction("Login", "login");
            return(View());
        }