public void PreparePostOveralData(PostOveralViewModel p, String currentUserId) { var likeService = this.Service <ILikeService>(); var commentService = this.Service <IPostCommentService>(); List <Like> likeList = likeService.GetLikeListByPostId(p.Id).ToList(); p.LikeCount = likeList.Count(); foreach (var like in likeList) { if (like.UserId == currentUserId) { p.Liked = true; } } p.CommentCount = commentService.GetCommentListByPostId(p.Id).Count(); p.CreateDateString = p.CreateDate.ToString("dd/MM/yyyy HH:mm:ss"); if (!p.EditDate.ToString().Equals("01/01/0001 12:00:00 SA")) { p.EditDateString = p.EditDate.ToString("dd/MM/yyyy HH:mm:ss"); } }
public ActionResult ShowPostDetail(int postId, String currentUserId, int skip, int take) { var postService = this.Service <IPostService>(); Post post = null; ResponseModel <PostDetailViewModel> response = null; try { post = postService.GetPostById(postId); PostOveralViewModel overal = Mapper.Map <PostOveralViewModel>(post); PreparePostOveralData(overal, currentUserId); PostDetailViewModel result = PreparePostDetailData(overal, skip, take); response = new ResponseModel <PostDetailViewModel>(true, "Chi tiết bài viết:", null, result); } catch (Exception) { response = ResponseModel <PostDetailViewModel> .CreateErrorResponse("Tải bài viết thất bại!", systemError); } return(Json(response)); }
public ActionResult EditPost(PostUploadViewModel model) { var postService = this.Service <IPostService>(); var postImageService = this.Service <IPostImageService>(); ResponseModel <PostOveralViewModel> response = null; try { Post post = postService.FirstOrDefaultActive(x => x.Id == model.Id); post.ContentType = GetPostType(model); if (model.UploadImage != null) { postImageService.saveImage(post.Id, model.UploadImage); } if (model.DeleteImage != null && model.DeleteImage.Count > 0) { foreach (var delete in model.DeleteImage) { PostImage img = postImageService.FirstOrDefaultActive(x => x.Id == delete); postImageService.Delete(img); } } post.PostContent = model.PostContent; post.EditDate = DateTime.Now; postService.Update(post); PostOveralViewModel result = Mapper.Map <PostOveralViewModel>(post); PreparePostOveralData(result, post.UserId); response = new ResponseModel <PostOveralViewModel>(true, "Bài viết đã được chỉnh sửa!", null, result); } catch (Exception) { response = ResponseModel <PostOveralViewModel> .CreateErrorResponse("Chỉnh sửa thất bại!", systemError); } return(Json(response)); }
public PostDetailViewModel PreparePostDetailData(PostOveralViewModel post, int skip, int take) { var likeService = this.Service <ILikeService>(); var commentService = this.Service <IPostCommentService>(); PostDetailViewModel result = new PostDetailViewModel(); result.Post = post; List <PostComment> commentList = commentService.GetCommentListByPostId(post.Id, skip, take).ToList <PostComment>(); List <PostCommentDetailViewModel> commentListResult = new List <PostCommentDetailViewModel>(); foreach (var comment in commentList) { commentListResult.Add(PreparePostCommentDetailViewModel(comment)); } result.CommentList = commentListResult; return(result); }
public ActionResult PostOnTimeLine(PostUploadViewModel model, string profileId) { var service = this.Service <IPostService>(); var aspNetUserService = this.Service <IAspNetUserService>(); var notiService = this.Service <INotificationService>(); var memberService = this.Service <IGroupMemberService>(); PostOveralViewModel result = null; ResponseModel <PostOveralViewModel> response = null; try { Post post = Mapper.Map <Post>(model); post.ProfileId = profileId; if (model.PostContent == null) { post.PostContent = ""; } post.ContentType = GetPostType(model); if (post.ContentType != int.Parse(ContentPostType.TextOnly.ToString("d"))) { FileUploader uploader = new FileUploader(); foreach (var img in model.UploadImage) { PostImage image = new PostImage(); image.Image = uploader.UploadImage(img, userImagePath); post.PostImages.Add(image); } } post = service.CreatePost(post); ////Notify all group members //if (post.GroupId != null) //{ // List<GroupMember> memberList = GetMemberList(post.GroupId); // AspNetUser postedUser = aspNetUserService.FindUser(post.UserId); // foreach (var member in memberList) // { // if (!(member.UserId.Equals(post.UserId))) // { // Notification noti = notiService.SaveNoti(member.UserId, post.UserId, "Post", postedUser.FullName + " đã đăng một bài viết", (int)NotificationType.Post, post.Id, null, null); // List<string> registrationIds = GetToken(member.UserId); // if (registrationIds != null && registrationIds.Count != 0) // { // NotificationModel notiModel = Mapper.Map<NotificationModel>(PrepareNotificationViewModel(noti)); // Android.Notify(registrationIds, null, notiModel); // } // } // } //} if (post.UserId != profileId) { var _notificationService = this.Service <INotificationService>(); var _userService = this.Service <IAspNetUserService>(); AspNetUser sender = _userService.FindUser(post.UserId); string title = Utils.GetEnumDescription(NotificationType.Post); int type = (int)NotificationType.Post; string message = sender.FullName + " đã đăng một bài viết lên tường nhà bạn"; Notification noti = _notificationService.CreateNoti(profileId, post.UserId, title, message, type, post.Id, null, null, null); ////////////////////////////////////////////// //signalR noti NotificationFullInfoViewModel notiModel = _notificationService.PrepareNoti(Mapper.Map <NotificationFullInfoViewModel>(noti)); // Get the context for the Pusher hub IHubContext hubContext = GlobalHost.ConnectionManager.GetHubContext <RealTimeHub>(); // Notify clients in the group hubContext.Clients.User(notiModel.UserId).send(notiModel); } //Missing post sport result = Mapper.Map <PostOveralViewModel>(post); result.AspNetUser = Mapper.Map <AspNetUserSimpleModel>(aspNetUserService.FindUser(result.UserId)); PreparePostOveralData(result, post.UserId); response = new ResponseModel <PostOveralViewModel>(true, "Đăng bài thành công!", null, result); } catch (Exception) { response = ResponseModel <PostOveralViewModel> .CreateErrorResponse("Đăng bài thất bại!", systemError); } return(Json(response)); }