示例#1
0
        private ScreenContentPageState GetPageState()
        {
            try
            {
                ScreenContentPageState pagestate = new ScreenContentPageState();


                // Initialize the session values if they don't exist - need to do this the first time controller is hit
                if (Session["ScreenContentPageState"] == null)
                {
                    int accountid = 0;
                    if (Session["UserAccountID"] != null)
                    {
                        accountid = Convert.ToInt32(Session["UserAccountID"]);
                    }

                    pagestate.AccountID           = accountid;
                    pagestate.ScreenContentName   = String.Empty;
                    pagestate.ScreenContentTypeID = 0;
                    pagestate.IncludeInactive     = false;
                    pagestate.SortBy     = "ScreenContentName";
                    pagestate.AscDesc    = "Ascending";
                    pagestate.PageNumber = 1;
                    Session["ScreenContentPageState"] = pagestate;
                }
                else
                {
                    pagestate = (ScreenContentPageState)Session["ScreenContentPageState"];
                }
                return(pagestate);
            }
            catch { return(new ScreenContentPageState()); }
        }
示例#2
0
 private void SavePageState(ScreenContentPageState pagestate)
 {
     Session["ScreenContentPageState"] = pagestate;
 }
示例#3
0
        //
        // GET: /ScreenContent/

        public ActionResult Index()
        {
            try
            {
                if (Session["UserAccountID"] == null)
                {
                    return(RedirectToAction("Validate", "Login"));
                }
                User user = (User)Session["User"];
                ViewData["LoginInfo"] = Utility.BuildUserAccountString(user.Username, Convert.ToString(Session["UserAccountName"]));
                if (user.IsAdmin)
                {
                    ViewData["txtIsAdmin"] = "true";
                }
                else
                {
                    ViewData["txtIsAdmin"] = "false";
                }

                // Initialize or get the page state using session
                ScreenContentPageState pagestate = GetPageState();

                // Get the account id
                int accountid = 0;
                if (Session["UserAccountID"] != null)
                {
                    accountid = Convert.ToInt32(Session["UserAccountID"]);
                }

                // Set and save the page state to the submitted form values if any values are passed
                if (Request.Form["lstAscDesc"] != null)
                {
                    pagestate.AccountID           = accountid;
                    pagestate.ScreenContentName   = Request.Form["txtScreenContentName"].ToString().Trim();
                    pagestate.ScreenContentTypeID = Convert.ToInt32(Request.Form["lstScreenContentTypeList"]);
                    if (Request.Form["chkIncludeInactive"].ToLower().StartsWith("true"))
                    {
                        pagestate.IncludeInactive = true;
                    }
                    else
                    {
                        pagestate.IncludeInactive = false;
                    }
                    pagestate.SortBy     = Request.Form["lstSortBy"].ToString().Trim();
                    pagestate.AscDesc    = Request.Form["lstAscDesc"].ToString().Trim();
                    pagestate.PageNumber = Convert.ToInt32(Request.Form["txtPageNumber"].ToString().Trim());
                    SavePageState(pagestate);
                }

                // Add the session values to the view data so they can be populated in the form
                ViewData["AccountID"]           = pagestate.AccountID;
                ViewData["ScreenContentName"]   = pagestate.ScreenContentName;
                ViewData["ScreenContentTypeID"] = pagestate.ScreenContentTypeID;
                ViewData["IncludeInactive"]     = pagestate.IncludeInactive;
                ViewData["SortBy"]                = pagestate.SortBy;
                ViewData["SortByList"]            = new SelectList(BuildSortByList(), "Value", "Text", pagestate.SortBy);
                ViewData["AscDescList"]           = new SelectList(BuildAscDescList(), "Value", "Text", pagestate.AscDesc);
                ViewData["ScreenContentTypeList"] = new SelectList(BuildScreenContentTypeList(true), "Value", "Text", pagestate.ScreenContentTypeID);

                // Determine asc/desc
                bool isdescending = false;
                if (pagestate.AscDesc.ToLower().StartsWith("d"))
                {
                    isdescending = true;
                }

                // Get a Count of all filtered records
                int recordcount = repository.GetScreenContentRecordCount(pagestate.AccountID, pagestate.ScreenContentName, pagestate.ScreenContentTypeID, pagestate.IncludeInactive);

                // Determine the page count
                int pagecount = 1;
                if (recordcount > 0)
                {
                    pagecount = recordcount / Constants.PageSize;
                    if (recordcount % Constants.PageSize != 0) // Add a page if there are more records
                    {
                        pagecount = pagecount + 1;
                    }
                }

                // Make sure the current page is not greater than the page count
                if (pagestate.PageNumber > pagecount)
                {
                    pagestate.PageNumber = pagecount;
                    SavePageState(pagestate);
                }

                // Set the page number and account in viewdata
                ViewData["PageNumber"]  = Convert.ToString(pagestate.PageNumber);
                ViewData["PageCount"]   = Convert.ToString(pagecount);
                ViewData["RecordCount"] = Convert.ToString(recordcount);

                // Set the image folder
                ViewData["ImageFolder"] = @"~/Media/" + Convert.ToString(Session["UserAccountID"]) + @"/Images/";

                // Need to return the stored filename and content type name
                IEnumerable <ScreenContent>  screencontents = repository.GetScreenContentPage(pagestate.AccountID, pagestate.ScreenContentName, pagestate.ScreenContentTypeID, pagestate.IncludeInactive, pagestate.SortBy, isdescending, pagestate.PageNumber, pagecount);
                IScreenContentTypeRepository sctrep         = new EntityScreenContentTypeRepository();
                IImageRepository             imgrep         = new EntityImageRepository();
                List <ScreenContentView>     contentviews   = new List <ScreenContentView>();
                foreach (ScreenContent screencontent in screencontents)
                {
                    ScreenContentView contentview = new ScreenContentView();
                    contentview.ScreenContentID     = screencontent.ScreenContentID;
                    contentview.AccountID           = screencontent.AccountID;
                    contentview.ScreenContentTypeID = screencontent.ScreenContentTypeID;
                    ScreenContentType sctype = sctrep.GetScreenContentType(screencontent.ScreenContentTypeID);
                    contentview.ScreenContentTypeName = sctype.ScreenContentTypeName;
                    contentview.ScreenContentName     = screencontent.ScreenContentName;
                    contentview.ScreenContentTitle    = screencontent.ScreenContentTitle;
                    contentview.ThumbnailImageID      = screencontent.ThumbnailImageID;
                    Image img = imgrep.GetImage(screencontent.ThumbnailImageID);
                    contentview.StoredFilename = img.StoredFilename;
                    contentview.CustomField1   = screencontent.CustomField1;
                    contentview.CustomField2   = screencontent.CustomField2;
                    contentview.CustomField3   = screencontent.CustomField3;
                    contentview.CustomField4   = screencontent.CustomField4;
                    contentview.IsActive       = screencontent.IsActive;
                    contentviews.Add(contentview);
                }

                ViewResult result = View(contentviews);
                result.ViewName = "Index";
                return(result);
            }
            catch (Exception ex)
            {
                Helpers.SetupApplicationError("ScreenContent", "Index", ex.Message);
                return(RedirectToAction("Index", "ApplicationError"));
            }
        }