public void CreateFriendRequest(FriendRequest fr) { using (TempDBFriendContext db = new TempDBFriendContext()) { db.FriendRequests.Add(fr); db.SaveChanges(); } }
public ActionResult RequestFriend(User user, string name) { FriendRequest fr = new FriendRequest(); fr.Receiver = name; fr.Sender = user.UserName; IDAL DAL = new DBDataAL(); DAL.CreateFriendRequest(fr); FriendData data = new FriendData("matt"); return View("Web/Friends", data); }
public ActionResult RequestFriend(string name) { string currentUser = User.Identity.Name; IDAL DAL = new DBDataAL(); User user = DAL.GetUser(name); try { FriendRequest requests = DAL.GetFriendRequests(user).Where(x => x.Sender == currentUser).First(); } catch(Exception) //if null catch explosion { FriendRequest fr = new FriendRequest(); fr.Receiver = name; fr.Sender = currentUser; DAL.CreateFriendRequest(fr); } FriendData data = new FriendData(currentUser); return View("~/Views/Web/Friends.cshtml", data); }
public void RemoveFriendRequest(FriendRequest fr) { using (TempDBFriendContext db = new TempDBFriendContext()) { FriendRequest request = db.FriendRequests.Where(x => x.Receiver == fr.Receiver && x.Sender == fr.Sender).First(); db.FriendRequests.Remove(request); db.SaveChanges(); } }