public ActionResult Create(BlogEntry blogEntry)
        {
            try
            {
                var blogOp = new BlogOperations();

                if (User.IsInRole("Admin"))
                {
                    blogEntry.StatusID = 1;
                }
                else
                {
                    blogEntry.StatusID = 3;
                }

                blogEntry.UserID = System.Web.HttpContext.Current.User.Identity.GetUserId();

                blogOp.CreateBlogEntry(blogEntry);

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
示例#2
0
 public void TestCreateBlog()
 {
     var operations = new BlogOperations(new MockRepo());
     var blogEntry = new BlogEntry();
     operations.CreateBlogEntry(blogEntry);
     Assert.AreEqual(6, operations.GetAllBlogEntries().Count);
 }
        public HttpResponseMessage Put(BlogEntry blogEntry)
        {
            var blogOp = new BlogOperations();
            blogOp.EditBlogEntry(blogEntry);

            var response = Request.CreateResponse(HttpStatusCode.OK, blogEntry);

            return response;
        }
        public void CreateEntry(BlogEntry blogEntry)
        {
            using (SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString))
            {
                var cmd = new SqlCommand("CreateBlogEntry", cn);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@PostContents", blogEntry.PostContents);
                cmd.Parameters.AddWithValue("@UserID", blogEntry.UserID);
                cmd.Parameters.AddWithValue("@DateOfPost", blogEntry.DateOfPost);
                if (blogEntry.StartDate == null)
                {
                    cmd.Parameters.AddWithValue("@StartDate", DBNull.Value);
                }
                else
                {
                    cmd.Parameters.AddWithValue("@StartDate", blogEntry.StartDate);
                }
                if (blogEntry.StartDate == null)
                {
                    cmd.Parameters.AddWithValue("@EndDate", DBNull.Value);
                }
                else
                {
                    cmd.Parameters.AddWithValue("@EndDate", blogEntry.StartDate);
                }
                //cmd.Parameters.AddWithValue("@StartDate", blogEntry.StartDate);
                //cmd.Parameters.AddWithValue("@EndDate", blogEntry.EndDate);
                cmd.Parameters.AddWithValue("@StatusID", blogEntry.StatusID);
                cmd.Parameters.AddWithValue("@Title", blogEntry.Title);
                //cmd.Parameters.AddWithValue("@CategoryName", blogEntry.CategoryName);
                // DO NOT UNCOMMENT UNTIL SPROC IS UPDATED

                cn.Open();
                cmd.ExecuteNonQuery();
            }
        }
        public ActionResult Create(BlogEntry blogEntry)
        {
            try
            {
                var blogOp = new BlogOperations();

                if (User.IsInRole("Admin"))
                {
                    blogEntry.StatusID = 1;
                }
                else
                {
                    blogEntry.StatusID = 3;
                }

                blogOp.CreateBlogEntry(blogEntry);

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
        public BlogEntry GetBlog(int id)
        {
            var temp = new BlogEntry();
            using (SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString))
            {

                var cmd = new SqlCommand("GetBlogEntry", cn);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@BlogPostID", id);

                cn.Open();
                using (SqlDataReader dr = cmd.ExecuteReader())
                {
                    while (dr.Read())
                    {
                        temp.BlogID = dr.GetInt32(0);
                        temp.PostContents = dr.GetString(1);
                        temp.UserID = dr.GetInt32(2);
                        temp.DateOfPost = dr.GetDateTime(3);
                        temp.StartDate = dr["StartDate"] is DBNull ? DateTime.Now : dr.GetDateTime(4);
                        temp.EndDate = dr["StartDate"] is DBNull ? DateTime.Now.AddYears(100) : dr.GetDateTime(5);
                        temp.StatusID = dr.GetInt32(6);
                        temp.Title = dr.GetString(7);
                        return temp;
                    }
                }
            }
            return temp;
        }
        public List<BlogEntry> GetAll()
        {
            var blogEntries = new List<BlogEntry>();
            using (SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString))
            {
                var cmd = new SqlCommand("GetBlogEntries", cn);
                cmd.CommandType = CommandType.StoredProcedure;

                cn.Open();
                using (SqlDataReader dr = cmd.ExecuteReader())
                {
                    while (dr.Read())
                    {
                        var temp = new BlogEntry();
                        temp.BlogID = dr.GetInt32(0);
                        temp.PostContents = dr.GetString(1);
                        temp.UserID = dr.GetInt32(2);
                        temp.DateOfPost = dr.GetDateTime(3);
                        temp.StartDate = dr["StartDate"] is DBNull ? DateTime.Now : dr.GetDateTime(4);
                        temp.EndDate = dr["StartDate"] is DBNull ? DateTime.Now.AddYears(100) : dr.GetDateTime(5);
                        temp.StatusID = dr.GetInt32(6);
                        temp.Title = dr.GetString(7);
                        blogEntries.Add(temp);
                    }
                }
            }
            return blogEntries;
        }
        public void EditEntry(BlogEntry blogEntry)
        {
            using (SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString))
            {
                var cmd = new SqlCommand("EditBlogEntry", cn);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@BlogPostID", blogEntry.BlogID);
                cmd.Parameters.AddWithValue("@PostContents", blogEntry.PostContents);
                cmd.Parameters.AddWithValue("@UserID", blogEntry.UserID);
                cmd.Parameters.AddWithValue("@DateOfPost", blogEntry.DateOfPost);
                cmd.Parameters.AddWithValue("@StartDate", blogEntry.StartDate);
                cmd.Parameters.AddWithValue("@EndDate", blogEntry.EndDate);
                cmd.Parameters.AddWithValue("@Title", blogEntry.Title);
                cmd.Parameters.AddWithValue("@StatusID", blogEntry.StatusID);

                cn.Open();
                cmd.ExecuteNonQuery();
            }
        }
        public ActionResult Delete(int id, BlogEntry blogEntry)
        {
            try
            {
                var blogOp = new BlogOperations();
                blogOp.DeleteBlogEntry(id);

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
 // GET: Blog/Create
 public ActionResult Create()
 {
     var blogEntry = new BlogEntry();
     return View(blogEntry);
 }
        public ActionResult Edit(int id, BlogEntry blogEntry)
        {
            try
            {
                var blogOp = new BlogOperations();
                blogOp.EditBlogEntry(blogEntry);

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
示例#12
0
 public void TestGetBlog()
 {
     var operations = new BlogOperations(new MockRepo());
     var expected = new BlogEntry()
     {
         BlogID = 6,
         DateOfPost = DateTime.Now.Date,
         EndDate = DateTime.Now.Date.AddDays(2),
         StartDate = DateTime.Now.Date,
         Title = "Fake Title" + 6,
         PostContents = "Test Post" + 6,
         StatusID = 1,
         UserID = "19faea31-fb63-4d55-b661-6884255d4d53"
     };
     operations.CreateBlogEntry(expected);
     Assert.AreEqual(expected, operations.GetBlogEntry(6));
 }
 public void EditBlogEntry(BlogEntry blogEntry)
 {
     _blogRepo.EditEntry(blogEntry);
 }
 public void CreateBlogEntry(BlogEntry blogEntry)
 {
     blogEntry.DateOfPost = DateTime.Now;
     blogEntry.StatusID = 1;
     _blogRepo.CreateEntry(blogEntry);
 }
示例#15
0
 public void EditEntry(BlogEntry blogEntry)
 {
     GetBlog(1);
     blogEntry.PostContents = "edit";
 }
示例#16
0
 public void CreateEntry(BlogEntry blogEntry)
 {
     Blogs.Add(blogEntry);
 }