public bool MayIComeIn_v2(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) { return(true); } else { Console.WriteLine("Object is not found in data base! "); return(false); } } } catch { Console.WriteLine("Thomething is wrong with MayIComeIn_v2 method! "); return(false); } }
public void MayIComeIn(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) { ServerUser temp = new ServerUser() { Id = nextID, UserName = usersaccaunt.Name, ChatCallback = OperationContext.Current.GetCallbackChannel <IServiceChatCallBack>(), }; temp.ChatCallback.OnEnterIntoChatIsAllowed(); Console.WriteLine("User " + login + " is allowed to connect!"); } else { Console.WriteLine("Object is not found in data base! "); } } } catch { Console.WriteLine("Thomething is wrong with MayIComeIn method! "); } }
/*-------------------------------------------------------------------------------------------------------------------------------------------------------*/ public async void RegistrateUsersAccaunt(string login, string password, string name, int age, int i) { //Console.WriteLine(login +" ; " + password + " ; " + name + " ; " + age + " ; " + i); sex s; if (i == 0) { s = sex.Male; } else { s = sex.Female; } UsersAccaunt usersaccaunt = new UsersAccaunt() { Login = login, Password = password, Name = name, Age = age, sex = new Sex(s) }; try { using (UsersAccauntContext ua = new UsersAccauntContext()) { ua.UsersAccaunts.Add(usersaccaunt); await ua.SaveChangesAsync(); Console.WriteLine("New object UsersAccaunt: "); Console.WriteLine("----New object UsersAccaunt: " + usersaccaunt.Login + " ; " + usersaccaunt.Name + " ; " + usersaccaunt.sex.ToString() + " has been added to the database. "); string msg = "Your accaunt was created saccessfully =)!"; ServerUser temp = new ServerUser() { Id = nextID, UserName = name, ChatCallback = OperationContext.Current.GetCallbackChannel <IServiceChatCallBack>(), }; temp.ChatCallback.OnMessageBoxShow(msg); } } catch { Console.WriteLine("Thomething is wrong with adding an object to DataBase! "); } }
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! "); } }