private bool IsAuthorizeToViewPost(Post post) { switch (post.VisibleType) { case (int)VisibleType.Public: return true; case (int)VisibleType.Friend: if (post.User1.FriendLists.First().Friends.Any(x => x.FriendId == CurrentUserID && x.FriendStatus) || post.PostedOn.Equals(CurrentUserID, StringComparison.InvariantCultureIgnoreCase) || post.UserID.Equals(CurrentUserID, StringComparison.InvariantCultureIgnoreCase)) { return true; } break; case (int)VisibleType.Private: if (post.PostedOn.Equals(CurrentUserID, StringComparison.InvariantCultureIgnoreCase) || post.UserID.Equals(CurrentUserID, StringComparison.InvariantCultureIgnoreCase)) { return true; } break; } return false; }
public string PostStatus(string postedOn, string content, int imageCount) { Post post; try { var user = db.Users.FirstOrDefault(x => x.UserID.Equals(postedOn, StringComparison.InvariantCultureIgnoreCase)); if (user == null) return ActionResults.Failed.ToString(); var setting = user.MySettings.First(); var postVisible = CurrentUserID == postedOn ? setting.DefaultMyPostVisibility : setting.DefaultOtherPostVisibility; post = new Post { PostID = Guid.NewGuid().ToString().Replace("-", string.Empty), PostContent = HttpUtility.HtmlDecode(content.Trim()), UserID = CurrentUserID, PostedOn = postedOn, PostType = (int)PostType.Status, PostedDate = DateTime.UtcNow, LastModified = DateTime.UtcNow, VisibleType = postVisible }; db.Posts.Add(post); db.SaveChanges(); string[] infoPost = new string[] { "", "" }; infoPost[0] = post.PostID; infoPost[1] = user.UserID; Session["PostIDPosted"] = infoPost; //if is not post on his own timeline, then push new notif for user who has been posted on if (postedOn != CurrentUserID) { PushNotification(postedOn, post.PostID, (int)NotificationType.Post); } } catch (Exception exception) { Helper.WriteLog(exception); return ActionResults.Failed.ToString(); } if (imageCount <= 0) { var listView = new List<Post>(); var view = post; view.User = db.Users.First(x => x.UserID == post.UserID); view.PostLikes = db.PostLikes.Where(x => x.PostID == post.PostID).ToList(); view.Comments = db.Comments.Where(x => x.PostID == post.PostID).ToList(); listView.Add(view); var str = RenderPartialViewToString("PostListPartial", listView); return str; } return post.PostID; }