public void CreateMessage(Message message) { using(TempDBFriendContext db = new TempDBFriendContext()) { db.Messages.Add(message); db.SaveChanges(); } }
public void CreateFriendRequest(FriendRequest fr) { using (TempDBFriendContext db = new TempDBFriendContext()) { db.FriendRequests.Add(fr); db.SaveChanges(); } }
public void RemoveMessage(Message message) { using (TempDBFriendContext db = new TempDBFriendContext()) { db.Messages.Remove(message); db.SaveChanges(); } }
public void DeleteUser(string userName) { //Remove user from Friend table using(SqlDBFriendListContext db = new SqlDBFriendListContext()) { List<Friend> friends = db.Friends.Where(u => (u.Friend1 == userName) || (u.User == userName)).ToList(); foreach(Friend friend in friends) { db.Friends.Remove(friend); db.Entry(friend).State = EntityState.Deleted; } db.SaveChanges(); } //Remove user from FriendRequest and Message table using(TempDBFriendContext db = new TempDBFriendContext()) { List<FriendRequest> friends = db.FriendRequests.Where(u => (u.Sender == userName) || (u.Receiver == userName)).ToList(); List<Message> messages = db.Messages.Where(u => (u.Sender == userName) || (u.Receiver == userName)).ToList(); foreach (FriendRequest friend in friends) { db.FriendRequests.Remove(friend); db.Entry(friend).State = EntityState.Deleted; } foreach(Message m in messages) { db.Messages.Remove(m); db.Entry(m).State = EntityState.Deleted; } db.SaveChanges(); } //Remove user from User table using(TempDBContext1 db = new TempDBContext1()) { User user = db.Users.Where(u => u.UserName == userName).FirstOrDefault(); if (user != null) { //db.Users.Attach(user); db.Users.Remove(user); db.Entry(user).State = EntityState.Deleted; db.SaveChanges(); } } //Remove user from LogUser table and UserRoles table using(TempDBLogUsers db = new TempDBLogUsers()) { LogUser user = db.LogUsers.Where(u => u.UserName == userName).FirstOrDefault(); if (user != null) { user.Roles.FirstOrDefault().LogUsers.Remove(user); user.Roles.Remove(user.Roles.FirstOrDefault()); //db.LogUsers.Attach(user); db.LogUsers.Remove(user); db.Entry(user).State = EntityState.Deleted; db.SaveChanges(); } } }
public void RemoveMessage(int id) { using (TempDBFriendContext db = new TempDBFriendContext()) { try { Message message = db.Messages.Where(x => x.Id == id).ToList().First(); db.Messages.Remove(message); db.SaveChanges(); } catch(Exception) { } } }
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(); } }