public bool AskAdresseeToPrivateMessage(string adresseeName, string senderName) { bool success = false; ServerUser adressee = _users.Where(x => x.UserName == adresseeName).FirstOrDefault(); if (adressee != null && adressee.PrivateMessageCallback == null) { adressee.ChatCallback.OnPrivateChatAskAccepted(adresseeName, senderName); success = true; } return(success); }
//IServiceChat interface methods public int Connect(string name) { ServerUser user = new ServerUser() { Id = nextID, UserName = name, ChatCallback = OperationContext.Current.GetCallbackChannel <IServiceChatCallBack>(), }; nextID++; _users.Add(user); SendMsg(user.UserName + " connected to the chat! ", user.Id); //IDs start with 1, with id = 0 the server will not send anything. Console.WriteLine("the ServerUser object has been created. ID=" + user.Id + " ; name= " + user.UserName); UpdateUsersList(); return(user.Id); }
public async void DeleteUsersAccaunt(string login, string password) { try { using (UsersAccauntContext ua = new UsersAccauntContext()) { UsersAccaunt usersaccaunt = new UsersAccaunt(); usersaccaunt = ua.UsersAccaunts.FirstOrDefault(ob => ob.Login == login && ob.Password == password); if (usersaccaunt != null) { /*-----------------------------------------------------------------------------------------------------*/ string msg = "Your accaunt was deleted saccessfully =(!"; ServerUser temp = new ServerUser() { Id = nextID, UserName = usersaccaunt.Name, ChatCallback = OperationContext.Current.GetCallbackChannel <IServiceChatCallBack>(), }; ua.UsersAccaunts.Remove(usersaccaunt); await ua.SaveChangesAsync(); temp.ChatCallback.OnMessageBoxShow(msg); /*-----------------------------------------------------------------------------------------------------*/ Console.WriteLine("---UsersAccaunt: " + " : " + usersaccaunt.Login + " ; " + usersaccaunt.Name + " ; " + usersaccaunt.sex.ToString() + " : has been removed from the database."); } else { Console.WriteLine("Object is not found in data base! "); } } } catch { Console.WriteLine("Thomething is wrong with deleting an object from DataBase! "); } }