public virtual IBaseEntity Get(object key) { /*using (var db = CreateContext()) * { * var table = db.Set<TEntity>(); * return table.Find(key); * }*/ var table = _context.Set <IBaseEntity>(); return(table.Find(key)); }
public IActionResult SavePost(IFormCollection form) { if (!IsLoggedIn()) { return(Redirect("/admin")); } // retrieve user input from the form int? postID = Convert.ToInt32(form["hdnPostId"]); int userID = Convert.ToInt32(form["hdnUserId"]); string title = form["txtTitle"]; string url = form["txtUrl"]; string summary = form["txtSummary"]; string content = form["txtContent"]; string search = form["txtSearch"]; DateTime dateCreated = form["hdnDateCreated"].ToString().ToDateTime(); DateTime dateModified = DateTime.Now; bool published = (form["chkPublished"] == "on"); bool pageable = (form["chkPageable"] == "on"); int loggedInUserID = HttpContext.Session.GetInt32(_loggedInUserId) ?? 0; // create Post object var post = new SlickCMS.Data.Entities.Post { PostId = postID ?? 0, UserId = userID != 0 ? userID : loggedInUserID, Title = title, Content = content, DateCreated = dateCreated, DateModified = dateModified, Pageable = pageable ? 1 : 0, Published = published ? 1 : 0, Search = search, Summary = summary, Url = url, }; // save post if (postID == null || postID == 0) { //_context.Post.Add(post); _context.Set <Data.Entities.Post>().Add(post); postID = post.PostId; } else { //_context.Post.Update(post); _context.Set <Data.Entities.Post>().Update(post); } _context.SaveChanges(); SaveCategories(postID, form); SaveTags(postID, form); return(Redirect("/admin/posts")); }