public async Task <IActionResult> Create([Bind("ID_Post,ID_Account,PostTime,PostType,Tittle,Size,Project,Price,RealEstateType,Description,Status")] Post post, string id , int district, int ward, int street, string diachi, bool alley, bool nearSchool, bool nearAirport, bool nearHospital, bool nearMarket, List <IFormFile> images, string descriptiondetail, int bathroom, int bedroom, int yard, int floor, int province) { var user = await _userManager.GetUserAsync(User); post.PostTime = DateTime.Now; post.ID_Account = user.Id; Post a = post; _context.Post.Add(post); await _context.SaveChangesAsync(); var completePost = new CompletePost(); var builder = new PostBuilder(); completePost.Builder = builder; completePost.buildFullPost(user.Id, post.ID_Post , district, ward, street, diachi, alley, nearSchool, nearAirport, nearHospital, nearMarket, images, descriptiondetail, bathroom, bedroom, yard, floor, province, user.IsAdmin, post.Project); try { StatusMessage = "Đăng bài thành công!"; return(RedirectToAction("Index", "Post", new { area = "ManagePosts" })); } catch (Exception e) { string m = e.Message; StatusMessage = "Error Đăng bài không thành công"; } ViewData["PostType"] = new SelectList(_context.Post_Type, "ID_PostType", "Description"); ViewData["Project"] = new SelectList(_context.project, "id", "_name"); ViewData["RealEstateType"] = new SelectList(_context.RealEstate_Type, "ID_RealEstateType", "Description"); ViewData["IDAccount"] = user.Id; ViewData["Province"] = new SelectList(_context.province.OrderBy(p => p._name), "id", "_name"); return(View(post)); }
public static CompletePost GetPost(Guid?Id) { CompletePost result = new CompletePost(); Post post = db.Posts.Include("User").FirstOrDefault(p => p.Id == Id); if (post != null) { result.Id = post.Id; result.Content = post.Content; result.TimeAgo = StringHelper.TimeAgo(post.Timestamp); if (post.Type == Models.Enums.PostType.Image) { result.Title = post.Caption; } else if (post.Type == Models.Enums.PostType.Link) { result.Title = post.Content; } else if (post.Type == Models.Enums.PostType.Text) { result.Title = post.Content; } else if (post.Type == Models.Enums.PostType.Video) { result.Title = post.Caption; } result.Type = post.Type; result.User = new MiniProfile() { Id = post.UserId, Name = post.User.FirstName + " " + post.User.LastName }; result.Comments = db.PostComments .Include("User") .Where(c => c.PostId == post.Id) .Select(c => new FlatComment() { Content = c.Content, Timestamp = c.Timestamp, User = new MiniProfile() { Id = c.UserId, Name = c.User.FirstName + " " + c.User.LastName } }).ToList(); result.Hashtags = db.PostHashtags .Where(h => h.PostId == post.Id) .Select(h => h.Hashtag).ToList(); result.Likes = db.PostLikes .Include("User") .Where(l => l.PostId == post.Id) .Select(l => new MiniProfile() { Id = l.UserId, Name = l.User.FirstName + " " + l.User.LastName }).ToList(); result.UserTags = db.PostUserTags .Include("User") .Where(t => t.PostId == post.Id) .Select(t => new MiniProfile() { Id = t.UserId, Name = t.User.FirstName + " " + t.User.LastName }).ToList(); } return(result); }