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); } }
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)); } }
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)); }
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)); }
public void TestMethod_NotExistTitle() { IDataBase objDataBase = new clsDataBaseMethodsPosts(); Assert.IsFalse(objDataBase.ExistsTitle("-abcdeft76876889980")); }
public void TestMethod_ExistPost() { IDataBase objDataBase = new clsDataBaseMethodsPosts(); Assert.IsTrue(objDataBase.ExistsId("1")); }
public void TestMethod_NotExistPost() { IDataBase objDataBase = new clsDataBaseMethodsPosts(); Assert.IsFalse(objDataBase.ExistsId("-1")); }