public void New(Message msg, MaildbContext context, ApplicationUser appUser) { msg.MailDate = DateTime.Now; msg.MailFrom = appUser.Email; context.Messages.Add(msg); context.SaveChanges(); }
public void DeleteFriend(string friendName) { using (var _context = new MaildbContext()) { var friend = _context.ChatFriends.Single(c => c.Friend == friendName || c.FriendUserName == friendName); _context.ChatFriends.Remove(friend); _context.SaveChanges(); Clients.Caller.friendsToList(CreateFriendsList(Context.User.Identity.Name, _context)); } }
public void Delete(MaildbContext _context, string[] rows) { if (rows != null) { foreach (var row in rows) { int id = Decode(row); var delRow = _context.Messages.First(c => c.ID == id); _context.Messages.Remove(delRow); } _context.SaveChanges(); } }
public void AddFriend(string friendName) { ChatFriend chtFr = new ChatFriend(); var me = Context.User.Identity.Name; ApplicationUser friend = new ApplicationUser(); using (var _context = new MaildbContext()) { var appUser = _context.Users.First(c => c.Email == me || c.UserName == me); friend = _context.Users.First(c => c.Email == friendName || c.UserName == friendName); chtFr.ApplicationUser = appUser; chtFr.Friend = friend.Email; chtFr.FriendUserName = friend.UserName; _context.ChatFriends.Add(chtFr); _context.SaveChanges(); Clients.Caller.friendsToList(CreateFriendsList(me, _context)); } }