public ActionResult DeleteConfirmed(int id) { ContentNotification contentnotification = db.ContentNotifications.Find(id); db.ContentNotifications.Remove(contentnotification); db.SaveChanges(); return RedirectToAction("Index"); }
internal SendContentClientNotification(ContentNotification definition) { if (definition != null) { Definition = definition; } Type = "SendContent"; }
public ActionResult Edit([Bind(Include="ContentNotificationId,UserId,FriendId,Content,RequestDateTime")] ContentNotification contentnotification) { if (ModelState.IsValid) { db.Entry(contentnotification).State = EntityState.Modified; db.SaveChanges(); return RedirectToAction("Index"); } return View(contentnotification); }
public ActionResult Create([Bind(Include="ContentNotificationId,UserId,FriendId,Content,RequestDateTime")] ContentNotification contentnotification) { if (ModelState.IsValid) { db.ContentNotifications.Add(contentnotification); db.SaveChanges(); return RedirectToAction("Index"); } return View(contentnotification); }
// GET: /ContentNotification/Delete/5 public ActionResult Delete(int? id) { if (id == null) { return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } ContentNotification contentnotification = db.ContentNotifications.Find(id); if (contentnotification == null) { return HttpNotFound(); } return View(contentnotification); }
public ActionResult Edit(HttpPostedFileBase file) { CoverPhoto coverphoto = new CoverPhoto(); string path = null; if (file != null && file.ContentLength > 0) { try { path = Path.Combine(Server.MapPath("~/Images/CoverPic"), Path.GetFileName(file.FileName)); file.SaveAs(path); ViewBag.Message = "File uploaded successfully"; } catch (Exception ex) { ViewBag.Message = "ERROR:" + ex.Message.ToString(); } } else { ViewBag.Message = "You have not specified a file."; } coverphoto.UserId = User.Identity.GetUserId(); if (file != null && file.ContentLength > 0) { try { coverphoto.CoverImage = "~/Images/CoverPic/" + Path.GetFileName(file.FileName); string UserId = User.Identity.GetUserId(); var coverphotoFind = db.CoverPhotoes.Where(s => s.UserId.Equals(UserId)).ToList(); if (coverphotoFind.Count == 0) { if (ModelState.IsValid) { db.CoverPhotoes.Add(coverphoto); db.SaveChanges(); var friendIdLst = new List <string>(); var userIds = User.Identity.GetUserId(); var friendIdQry = db.Friends.Where(d => d.UserId == userIds && d.Status == "True").Select(d => d.FriendId); friendIdLst.AddRange(friendIdQry); var friendIdLst2 = new List <string>(); //var userIds2 = User.Identity.GetUserId(); var friendIdQry2 = db.Friends.Where(d => d.FriendId == userIds && d.Status == "True").Select(d => d.UserId); friendIdLst2.AddRange(friendIdQry2); var friendList = new List <string>(); foreach (var VARIABLE in friendIdLst) { friendList.Add(VARIABLE); } foreach (var v in friendIdLst2) { friendList.Add(v); } var name1 = (from u in db.Users where u.Id == userIds select new { u.Name }).ToList(); string name = ""; foreach (var VARIABLE in name1) { name = VARIABLE.Name; } //foreach (var f in friendList) //{ // ContentNotification cn = new ContentNotification(); // cn.UserId = User.Identity.GetUserId(); // cn.FriendId = f; // cn.Content = coverphoto.CoverImage = "~/Images/CoverPic/" + Path.GetFileName(file.FileName); // cn.RequestDateTime = DateTime.Now; // db.ContentNotifications.Add(cn); // db.SaveChanges(); //} // profilePicture save as a Post in Post Table Post aPost = new Post(); if (file != null && file.ContentLength > 0) { try { path = Path.Combine(Server.MapPath("~/Images/PostPic"), Path.GetFileName(file.FileName)); file.SaveAs(path); } catch (Exception ex) { ViewBag.Message = "ERROR:" + ex.Message.ToString(); } } if (file != null && file.ContentLength > 0) { try { aPost.ImgPost = "~/Images/PostPic/" + Path.GetFileName(file.FileName); } catch (Exception ex) { ViewBag.Message = "ERROR:" + ex.Message.ToString(); } } string userId = User.Identity.GetUserId(); var user = (from u in db.Users where u.Id == userId select new { u.Name }).ToList(); string userName = ""; foreach (var v in user) { userName = v.Name; } aPost.UserId = userId; aPost.UserName = userName; aPost.PostDate = DateTime.Now; if (ModelState.IsValid) { db.Posts.Add(aPost); db.SaveChanges(); } var photoById = (from pid in db.Posts where pid.ImgPost == aPost.ImgPost && pid.UserId == userIds select new { pid.PostId }).ToList(); int photoPostId = 0; foreach (var VARIABLE in photoById) { photoPostId = VARIABLE.PostId; } ContentNotification request = new ContentNotification(); foreach (var item in friendList) { request.FriendId = item; request.UserName = name; request.UserId = User.Identity.GetUserId(); request.PostId = photoPostId.ToString(); request.Notification = "Cover Photo Uploaded by " + request.UserName; request.RequestDateTime = DateTime.Now; db.ContentNotifications.Add(request); db.SaveChanges(); } // ---- end ---------- // //return RedirectToAction("Index", "Profile"); } } else { //var findId = from s in db.CoverPhotoes // where s.UserId.fi == UserId // select s.CoverPhotoId; var item = db.CoverPhotoes.FirstOrDefault(i => i.UserId == UserId); coverphoto = db.CoverPhotoes.Find(item.CoverPhotoId); if (ModelState.IsValid) { if (file != null && file.ContentLength > 0) { try { coverphoto.CoverImage = "~/Images/CoverPic/" + Path.GetFileName(file.FileName); } catch (Exception ex) { ViewBag.Message = "ERROR:" + ex.Message.ToString(); } } db.Entry(coverphoto).State = EntityState.Modified; db.SaveChanges(); var friendIdLst = new List <string>(); var userIds = User.Identity.GetUserId(); var friendIdQry = db.Friends.Where(d => d.UserId == userIds).Select(d => d.FriendId); friendIdLst.AddRange(friendIdQry); var friendIdLst2 = new List <string>(); var userIds2 = User.Identity.GetUserId(); var friendIdQry2 = db.Friends.Where(d => d.FriendId == userIds2).Select(d => d.FriendId); friendIdLst2.AddRange(friendIdQry2); var friendList = new List <string>(); foreach (var VARIABLE in friendIdLst) { friendList.Add(VARIABLE); } foreach (var v in friendIdLst2) { friendList.Add(v); } //foreach (var f in friendList) //{ // ContentNotification cn = new ContentNotification(); // cn.UserId = User.Identity.GetUserId(); // cn.FriendId = f; // cn.Content = coverphoto.CoverImage = "~/Images/CoverPic/" + Path.GetFileName(file.FileName); // cn.RequestDateTime = DateTime.Now; // db.ContentNotifications.Add(cn); // db.SaveChanges(); //} // profilePicture save as a Post in Post Table Post aPost = new Post(); if (file != null && file.ContentLength > 0) { try { path = Path.Combine(Server.MapPath("~/Images/PostPic"), Path.GetFileName(file.FileName)); file.SaveAs(path); } catch (Exception ex) { ViewBag.Message = "ERROR:" + ex.Message.ToString(); } } if (file != null && file.ContentLength > 0) { try { aPost.ImgPost = "~/Images/PostPic/" + Path.GetFileName(file.FileName); } catch (Exception ex) { ViewBag.Message = "ERROR:" + ex.Message.ToString(); } } string userId = User.Identity.GetUserId(); var user = (from u in db.Users where u.Id == userId select new { u.Name }).ToList(); string userName = ""; foreach (var v in user) { userName = v.Name; } aPost.UserId = userId; aPost.UserName = userName; aPost.PostDate = DateTime.Now; if (ModelState.IsValid) { db.Posts.Add(aPost); db.SaveChanges(); } var photoById = (from pid in db.Posts where pid.ImgPost == aPost.ImgPost && pid.UserId == userIds select new { pid.PostId }).ToList(); int photoPostId = 0; foreach (var VARIABLE in photoById) { photoPostId = VARIABLE.PostId; } ContentNotification request = new ContentNotification(); foreach (var item1 in friendList) { request.FriendId = item1; request.UserName = userName; request.UserId = User.Identity.GetUserId(); request.PostId = photoPostId.ToString(); request.Notification = "Cover Photo Uploaded by " + request.UserName; request.RequestDateTime = DateTime.Now; db.ContentNotifications.Add(request); db.SaveChanges(); } // ---- end ---------- // //RedirectToAction("Index", "Profile"); } } } catch (Exception ex) { ViewBag.Message = "ERROR:" + ex.Message.ToString(); } } return(RedirectToAction("Index", "Profile")); }
public ActionResult CreateCommentFromTimeline(int postId, string comment) { var commentList = db.PostComments.ToList(); // Create & save an user passed comment PostComment aComment = new PostComment(); aComment.UserId = User.Identity.GetUserId(); aComment.PostId = Convert.ToInt32(postId); aComment.UserComment = comment; db.PostComments.Add(aComment); db.SaveChanges(); // Find friends from 1st column UserId var friendIdList1 = new List <string>(); var userId = User.Identity.GetUserId(); var friendIdQuery1 = db.Friends.Where(d => d.UserId == userId && d.Status == "True").Select(d => d.FriendId); friendIdList1.AddRange(friendIdQuery1); // Find friends from 2nd column FriendId var friendIdList2 = new List <string>(); var friendIdQuery2 = db.Friends.Where(d => d.FriendId == userId && d.Status == "True").Select(d => d.UserId); friendIdList2.AddRange(friendIdQuery2); var friendList = new List <string>(); // Prepare friend list by foreach (var VARIABLE in friendIdList1) { friendList.Add(VARIABLE); } // Prepare friend list by id foreach (var VARIABLE in friendIdList2) { friendList.Add(VARIABLE); } var name1 = (from u in db.Users where u.Id == userId select new { u.Name }).ToList(); string name = ""; // Add names to friendList foreach (var VARIABLE in name1) { name = VARIABLE.Name; } // Create notification request ContentNotification request = new ContentNotification(); Post post = db.Posts.Find(postId); request.TextPost = post.TextPost; request.ImagePost = post.ImgPost; foreach (var item in friendList) { request.FriendId = item; request.UserId = User.Identity.GetUserId(); request.UserName = name; request.PostId = postId.ToString(); request.Notification = request.TextPost + " Commented by " + request.UserName; request.RequestDateTime = DateTime.Now; db.ContentNotifications.Add(request); db.SaveChanges(); } //int commentNumber = 0; //commentNumber = db.PostComments.ToList().Count; //return commentNumber.ToString(); return(RedirectToAction("Timeline", "Profile")); }
public string Create(int postIdString) { var postId = Convert.ToInt32(postIdString); var likeList = db.Likes.ToList(); var likeWithUser = (from like in likeList where like.UserId == User.Identity.GetUserId() && like.PostId == postId select new { like.PostId, like.UserId }).ToList(); var likesWithoutUser = (from like in likeList where like.UserId != User.Identity.GetUserId() && like.PostId == postId select new { like.PostId, like.UserId }).ToList(); int likeNumber = 0; if (likeWithUser.Count == 0) { Like aLike = new Like(); aLike.UserId = User.Identity.GetUserId(); aLike.PostId = Convert.ToInt32(postId); aLike.Status = 1; db.Likes.Add(aLike); db.SaveChanges(); var friendIdList1 = new List <string>(); var userId = User.Identity.GetUserId(); var friendIdQuery1 = db.Friends.Where(d => d.UserId == userId && d.Status == "True").Select(d => d.FriendId); friendIdList1.AddRange(friendIdQuery1); var friendIdList2 = new List <string>(); var friendIdQuery2 = db.Friends.Where(d => d.FriendId == userId && d.Status == "True").Select(d => d.UserId); friendIdList2.AddRange(friendIdQuery2); var friendList = new List <string>(); foreach (var VARIABLE in friendIdList1) { friendList.Add(VARIABLE); } foreach (var VARIABLE in friendIdList2) { friendList.Add(VARIABLE); } var name1 = (from u in db.Users where u.Id == userId select new { u.Name }).ToList(); string name = ""; foreach (var VARIABLE in name1) { name = VARIABLE.Name; } ContentNotification request = new ContentNotification(); Post post = db.Posts.Find(postId); request.TextPost = post.TextPost; request.ImagePost = post.ImgPost; foreach (var item in friendList) { request.FriendId = item; request.UserName = name; request.UserId = User.Identity.GetUserId(); request.PostId = postId.ToString(); request.Notification = "Post " + request.TextPost + " Liked by " + request.UserName; request.RequestDateTime = DateTime.Now; db.ContentNotifications.Add(request); db.SaveChanges(); } likeNumber = Convert.ToInt32(likesWithoutUser.Count().ToString()) + 1; return(likeNumber.ToString()); } likeNumber = Convert.ToInt32(likesWithoutUser.Count().ToString()) + 1; return(likeNumber.ToString()); }