Пример #1
0
 public JsonResult LoadGrid()
 {
     try
     {
         clsDataBaseMethodsPosts objDB = new clsDataBaseMethodsPosts();
         bool   blnUserIsAuthenticated = Session[Blog.Helpers.Constant.USUARIO] == null ? false : true;
         string strProfile             = Session[Blog.Helpers.Constant.PERFIL] == null ? "" : Session[Blog.Helpers.Constant.PERFIL].ToString();
         return(Json(objDB.ListPosts(blnUserIsAuthenticated, strProfile)));
     }
     catch (Exception)
     {
         return(null);
     }
 }
Пример #2
0
        public JsonResult Delete(string id)
        {
            try
            {
                clsDataBaseMethodsPosts objDB = new clsDataBaseMethodsPosts();
                if (objDB.ExistsId(id))
                {
                    return(Json(new { Message = "Post not found", Type = "Error" }, JsonRequestBehavior.AllowGet));
                }

                objDB.Delete(id);

                return(Json(new { Message = "Post deleted", Type = "Success" }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                return(Json(new { Message = "Error:" + ex.Message, Type = "Error" }, JsonRequestBehavior.AllowGet));
            }
        }
Пример #3
0
        public ActionResult Insert(Models.Post objPost)
        {
            try
            {
                clsDataBaseMethodsPosts objDB = new clsDataBaseMethodsPosts();
                if (objDB.ExistsTitle(objPost.strTitle))
                {
                    TempData["Error"] = "¡Post title already exists!";
                    return(RedirectToAction("Index", "Posts"));
                }
                objDB.Insert(objPost);

                TempData["Success"] = "¡Post Created!";
                return(RedirectToAction("Index", "Posts"));
            }
            catch (Exception ex)
            {
                ViewBag.Error = ex.Message;
            }
            return(View(objPost));
        }
Пример #4
0
        public ActionResult Update(Models.Post objPost)
        {
            try
            {
                clsDataBaseMethodsPosts objDB = new clsDataBaseMethodsPosts();
                if (objDB.ExistsTitleAndIdForUpdate(objPost.IdPost.ToString(), objPost.strTitle))
                {
                    TempData["Error"] = "¡Post title already exists!";
                    return(RedirectToAction("Index", "Posts"));
                }
                objDB.Update(objPost, Session[Blog.Helpers.Constant.PERFIL].ToString(), Session[Blog.Helpers.Constant.USUARIO].ToString());

                TempData["Success"] = "Update successfull!";
                return(RedirectToAction("Index", "Posts"));
            }
            catch (Exception ex)
            {
                TempData["Error"] = ex.InnerException;
            }
            return(View(objPost));
        }
Пример #5
0
        public void TestMethod_NotExistTitle()
        {
            IDataBase objDataBase = new clsDataBaseMethodsPosts();

            Assert.IsFalse(objDataBase.ExistsTitle("-abcdeft76876889980"));
        }
Пример #6
0
        public void TestMethod_ExistPost()
        {
            IDataBase objDataBase = new clsDataBaseMethodsPosts();

            Assert.IsTrue(objDataBase.ExistsId("1"));
        }
Пример #7
0
        public void TestMethod_NotExistPost()
        {
            IDataBase objDataBase = new clsDataBaseMethodsPosts();

            Assert.IsFalse(objDataBase.ExistsId("-1"));
        }