public void Register(string name, string pass) { using (var ctx = new fourinrowDB_RoniShoseov_EilonOsherContext()) { var IsExists = (from u in ctx.Users where u.UserName == name select u).FirstOrDefault(); if (IsExists != null) { ConnectedFault userNameTaken = new ConnectedFault { Details = name + " is taken, please pick another." }; throw new FaultException <ConnectedFault>(userNameTaken); } User newUser = new User { UserName = name, HashedPassword = pass, NumOfGames = 0, NumOfLosses = 0, NumOfWins = 0, Points = 0 }; ctx.Users.Add(newUser); ctx.SaveChanges(); ICallback regCallback = OperationContext.Current.GetCallbackChannel <ICallback>(); updateAllClinetToUpdateList(name); avilableClinets.Add(name, regCallback); } }
public void SingIn(string user, string pass) { if (avilableClinets.ContainsKey(user)) { ConnectedFault userExsists = new ConnectedFault { Details = "User name " + user + " already exists. Try something else" }; throw new FaultException <ConnectedFault>(userExsists); } using (var ctx = new fourinrowDB_RoniShoseov_EilonOsherContext()) { var findUser = (from u in ctx.Users where u.UserName == user select u).FirstOrDefault(); if (findUser == null) { UnregisteredUser userNotExsists = new UnregisteredUser { Details = user + "does not exist in the database. Please register." }; throw new FaultException <UnregisteredUser>(userNotExsists); } else if (pass != findUser.HashedPassword) { WrongPassword userWrongPassword = new WrongPassword { Details = "Wrong password entered, please try again" }; throw new FaultException <WrongPassword>(userWrongPassword); } else { ICallback singIncallback = OperationContext.Current.GetCallbackChannel <ICallback>(); updateAllClinetToUpdateList(user); avilableClinets.Add(user, singIncallback); } } }