public IActionResult CreateDbPost(PostViewModel viewModel) { if (ModelState.IsValid) { DbPost model = new DbPost(); model.Description = viewModel.Description; model.CreatedDate = DateTime.Now; model.UserId = _userManager.GetUserId(HttpContext.User); model.Likes = 0; if (viewModel.Photo != null) { byte[] image; using (var binaryReader = new BinaryReader(viewModel.Photo.OpenReadStream())) { image = binaryReader.ReadBytes((int)viewModel.Photo.Length); } model.Photo = image; } var createdPost = _uow.DbPosts.Create(model); _uow.Save(); return(RedirectToAction("Index")); } return(View(viewModel)); }
private void InitializeRepository(DbContext hazenaContext) { Hraci = new DbHraci <T>(hazenaContext.Hrac); Kluby = new DbKluby <T>(hazenaContext.Klub); Zapasy = new DbZapasy <T>(hazenaContext.Zapas); Post = new DbPost <T>(hazenaContext.Post); Tabulka = new DbTabulka <T>(hazenaContext.Tabulka); }
private static void MapPost(ThreadModel threadModel, DbPost post) { // note that we don't map thread id here threadModel.Title = post.Title; threadModel.Excerpt = post.Message; threadModel.UserId = post.UserId; threadModel.Username = post.Username; threadModel.Updated = post.Updated ?? post.Posted; }
public static ThreadModel CreateThreadModel(this DbPost post, DbThread thread, IEnumerable <DbRating> ratings, int userId, DbPost parent) { var threadModel = post.UserId == userId ? new PostActivityModel() : parent != null && parent.UserId == userId ? new ReplyActivityModel() : new ThreadModel(); MapPost(threadModel, post); MapThread(threadModel, thread); MapRatings(threadModel, ratings); return(threadModel); }
public DbPost Create(DbPost post) { var entry = _context.DbPosts.Add(post); return(entry.Entity); }