public ActionResult RemoveFriend(int friendToRemove) { int currentUser = personRepository.GetIdByUserIdentityEmail(User.Identity.Name); List <FriendRequest> friends = requestRepository.GetFriendsByPersonId(currentUser); foreach (FriendRequest f in friends) { /*Hämtar den FriendRequest där SenderID och ReceiverID stämmer, och tar bort den, kontroll görs åt båda hållen * - användaren kan nämligen antingen vara den som skickat eller fått vänförfrågan. */ if (f.ReceiverId.Equals(currentUser) && f.SenderId.Equals(friendToRemove) || f.ReceiverId.Equals(friendToRemove) && f.SenderId.Equals(currentUser)) { try { _context.Remove(f); _context.SaveChanges(); } catch (Exception) { TempData["ProcessMessage"] = "Could not remove friend, try again later"; return(PartialView("Exception")); } } } return(RedirectToAction("Profile", "Person", new { id = friendToRemove })); }
public ActionResult DeclineRequest(int senderId) { int receiverId = personRepository.GetIdByUserIdentityEmail(User.Identity.Name); List <FriendRequest> requests = requestRepository.GetAllRequestsSentToUser(receiverId); foreach (FriendRequest fr in requests) { if (fr.SenderId.Equals(senderId) && fr.ReceiverId.Equals(receiverId)) { try { _context.Remove(fr); _context.SaveChanges(); } catch (Exception) { TempData["ProcessMessage"] = "Could not decline friend, try again later"; return(PartialView("Exception")); } } } return(RedirectToAction("Profile", "Person", new { id = senderId })); }
public void Remove <T>(T entity) where T : class { _context.Remove(entity); }