public ActionResult Index() { using (BlogDBEntities db = new BlogDBEntities()) { var BlogQuery = (from blog in db.Tbl_Blog orderby blog.BlogID descending select blog).Take(4); return(View(BlogQuery.ToList())); } }
public bool Delete(int id) { bool isDelete = false; using (var dbContext = new BlogDBEntities()) { if (!dbContext.Blog_Mst.Any(p => p.PK_Blog_id == id)) { throw new Exception("Not Found."); } dbContext.Blog_Mst.Remove(dbContext.Blog_Mst.First(p => p.PK_Blog_id == id)); isDelete = dbContext.SaveChanges() > 0; } return(isDelete); }
public UserModel Login(UserModel user) { UserModel loginUserInfromation = null; using (BlogDBEntities dbContext = new BlogDBEntities()) { loginUserInfromation = (from m in dbContext.Users.Where(p => p.Email == user.Email && p.Password == user.Password) select new UserModel() { Id = m.PK_User_Id, Name = m.Name, Email = m.Email }).FirstOrDefault(); } return(loginUserInfromation); }
public ActionResult Login(string username, string password) { if (ModelState.IsValid) { using (BlogDBEntities db = new BlogDBEntities()) { var obj = db.Tbl_User.Where(a => a.Username.Equals(username) && a.Password.Equals(password)).FirstOrDefault(); if (obj != null) { Session["UserID"] = obj.UserID.ToString(); Session["UserName"] = obj.Username.ToString(); return(RedirectToRoute("BlogIndex")); } } } ViewBag.Username = username.ToString(); ViewBag.Status = 0; return(View()); }
public IEnumerable <BlogModel> Get() { IEnumerable <BlogModel> blogsList = null; using (var dbContext = new BlogDBEntities()) { blogsList = (from m in dbContext.Blog_Mst select new BlogModel() { Id = m.PK_Blog_id, Title = m.Title, BlogContent = m.BlogContent, Description = m.Description, FK_User_Id = m.FK_User_Id, Keyword = m.Keyword, IsActive = m.IsActive }).ToList(); } return(blogsList); }
public bool Update(int id, BlogModel model) { bool isUpdated = false; using (var dbContext = new BlogDBEntities()) { if (!dbContext.Blog_Mst.Any(p => p.PK_Blog_id == id)) { throw new Exception("Not Found."); } var findObject = dbContext.Blog_Mst.Find(id); findObject.Title = model.Title; findObject.Keyword = model.Keyword; findObject.Description = model.Description; findObject.BlogContent = model.BlogContent; dbContext.Entry(findObject).State = System.Data.Entity.EntityState.Modified; isUpdated = dbContext.SaveChanges() > 0; } return(isUpdated); }
public bool Add(BlogModel model) { bool isAdded = false; using (BlogDBEntities dbContext = new BlogDBEntities()) { Blog_Mst temp = new Blog_Mst() { Title = model.Title, BlogContent = model.BlogContent, Description = model.Description, FK_User_Id = model.FK_User_Id, Keyword = model.Keyword, IsActive = model.IsActive }; dbContext.Blog_Mst.Add(temp); isAdded = dbContext.SaveChanges() > 0; } return(isAdded); }
public BlogController() { context = new BlogDBEntities(); title = context.Options.Select(i => i.Title).FirstOrDefault(); }
public SeoController() { context = new BlogDBEntities(); }