public ActionResult CreateStaticPagePost(Response response)
        {
            _ops = new MVCBlogOps();

            var staticPage = new StaticPage();

            var userManager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(new ApplicationDbContext()));
            var user = userManager.FindById(User.Identity.GetUserId());
            if (User.IsInRole("Admin"))
            {
                // TODO: simplify this, inspect blogPost.Status
                staticPage.Status = 1; // 1 is Approved
            }
            else
            {
                staticPage.Status = 2; // 2 is Unapproved
            }

            staticPage.UserID = user.Id;
            staticPage.Title = response.StaticPage.Title;
            staticPage.Mce.Body = response.StaticPage.Mce.Body;

            _ops.SaveStaticPageToRepo(staticPage);

            return RedirectToAction("Index", "StaticPage");
        }
Beispiel #2
0
        public Response ArchiveStaticPageToRepo(StaticPage staticPage)
        {
            _response = new Response();
            _repo.ArchiveStaticPageDB(staticPage);

            _response.Success = true;
            return _response;
        }
        public ActionResult ArchiveStaticPage(StaticPage staticPage)
        {
            _res = new Response();
            _ops = new MVCBlogOps();

            _res = _ops.ArchiveStaticPageToRepo(staticPage);
            return RedirectToAction("Index", "StaticPage");
        }
Beispiel #4
0
        public void ArchiveStaticPageDB(StaticPage staticPage)
        {
            using (var cn = new SqlConnection(Settings.ConnectionString))
            {
                var p = new DynamicParameters();
                p.Add("@StaticPageID", staticPage.StaticPageID);

                cn.Execute("ArchiveStaticPageByID", p, commandType: CommandType.StoredProcedure);
            }
        }
Beispiel #5
0
        public void CreateStaticPageDB()
        {
            var staticPage = new StaticPage()
            {
                Date = DateTime.Today,
                Mce = new TinyMceClass()
                {
                    Body = "Unit Test for CreateStaticPageDB method"
                },
                StaticPageID = 0,
                Status = 2,
                Title = "Testing",
                UserID = "2598e14d-88d0-46a7-ace9-f323ffe89181"
            };

            var repo = new MVCBlogRepo();
            repo.CreateStaticPageDB(staticPage);

            var cn = new SqlConnection(Settings.ConnectionString);

            var expected = cn.Query<int>("SELECT COUNT(StaticPageID) FROM StaticPages").FirstOrDefault();

            Assert.AreEqual(expected, 6);
        }
Beispiel #6
0
        //-------------------------------------------------------------------------------------------------------
        public List<StaticPage> GetAllStaticPages()
        {
            List<StaticPage> pages = new List<StaticPage>();

            using (var cn = new SqlConnection(Settings.ConnectionString))
            {
                SqlCommand cmd = cn.CreateCommand();
                cmd.CommandText = "GetAllStaticPages";
                cmd.CommandType = CommandType.StoredProcedure;

                cn.Open();

                using (SqlDataReader dr = cmd.ExecuteReader())
                {
                    while (dr.Read())
                    {
                            StaticPage page = new StaticPage();
                            page.StaticPageID= dr.GetInt32(0);
                            page.Date = dr.GetDateTime(1);
                            page.Title = dr.GetString(2);
                            page.Mce.Body = dr.GetString(3);
                            page.Status = dr.GetInt32(4);
                            page.UserID = dr.GetString(5);

                            pages.Add(page);
                    }
                }
            }
            return pages;
        }
Beispiel #7
0
        public void CreateStaticPageDB(StaticPage staticPage)
        {
            using (var cn = new SqlConnection(Settings.ConnectionString))
            {
                var p = new DynamicParameters();
                p.Add("@UserID", staticPage.UserID);
                p.Add("@Title", staticPage.Title);
                p.Add("@Body", staticPage.Mce.Body);
                p.Add("@Date", DateTime.Today);
                p.Add("@Status", staticPage.Status);

                p.Add("@StaticPageID", DbType.Int32, direction: ParameterDirection.Output);
                cn.Execute("StaticPageInsert", p, commandType: CommandType.StoredProcedure);
            }
        }