public ActionResult Follow(int id) { Followership followership = new Followership(); //Get the current user id from session and make it follower ID\ followership.FollowerID = Convert.ToInt32(Session["USERID"]); followership.isFollowing = true; followership.UserID = id; if (ModelState.IsValid) { //add record of following db.Followerships.Add(followership); //Nofity Followed user var notification = new Notification(); notification.User_ID = followership.UserID; var followingUser = db.Users.Find(followership.FollowerID); notification.Message = $"{followingUser.Username} has started following you!"; notification.Time = DateTime.Now.ToString(); db.Notifications.Add(notification); //save changes to db db.SaveChanges(); return(RedirectToAction("People", "Users")); } return(View(followership)); }
public ActionResult DeleteConfirmed(int id) { Followership followership = db.Followerships.Find(id); db.Followerships.Remove(followership); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "FollowershipID,UserID,FollowerID,Status")] Followership followership) { if (ModelState.IsValid) { db.Entry(followership).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(followership)); }
private void DeleteFollowerShip(string token, Account account) { if (account == null) { return; } var Initiator = new MongoDBRef(ACCOUNTS_COLLECTION_NAME, SelectAccount(token, a => a.Token)._id); var Target = new MongoDBRef(ACCOUNTS_COLLECTION_NAME, account._id); Followership followership = followershippCollection.FindOne(Query.And(Query <Followership> .EQ(f => f.Initiator, Initiator), Query <Followership> .EQ(f => f.Target, Target))); followershippCollection.Remove(Query <Followership> .EQ(f => f._id, followership._id)); }
// GET: Followerships/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Followership followership = db.Followerships.Find(id); if (followership == null) { return(HttpNotFound()); } return(View(followership)); }
public ActionResult UnFollow(int id) { var followerID = Convert.ToInt32(Session["USERID"]); var userID = id; //Get the current user id from session and make it follower ID\ //Followership followership = db.Followerships.Find(id); Followership followership = db.Followerships.Where(x => x.UserID == userID && x.FollowerID == followerID).FirstOrDefault(); if (ModelState.IsValid) { //delete record of following db.Followerships.Remove(followership); //save changes to db db.SaveChanges(); return(RedirectToAction("People", "Users")); } return(View(followership)); }
private PublicInfo InsertFollowership(string token, Account account) { if (account == null) { return(null); //just in case (can't think of a possile way where token is null and requesting to follow someone) } Followership followership = new Followership(new MongoDBRef(ACCOUNTS_COLLECTION_NAME, SelectAccount(token, a => a.Token)._id), new MongoDBRef(ACCOUNTS_COLLECTION_NAME, account._id)); if (followership.Initiator == followership.Target) { return(null); //just in case (checked already on the client side) } var query = Query.And(Query <Followership> .EQ(f => f.Target, followership.Target), Query <Followership> .EQ(f => f.Initiator, followership.Initiator)); if (followershippCollection.FindOne(query) == null) { followershippCollection.Insert(query); } return(account.GetPublicInfo()); }