public User Remove(User entity) { if (!_users.ContainsKey(entity.Id)) return null; var ret = _users[entity.Id]; _users.Remove(ret.Id); return ret; }
public User Save(User entity) { if (entity.Id == -1 || !_users.ContainsKey(entity.Id)) { var nextId = _users.Count == 0 ? 0 : _users.Keys.Max() + 1; entity.Id = nextId; _users.Add(nextId, entity); } else _users[entity.Id] = new User(entity.FirstName, entity.LastName, entity.Password, entity.Role, entity.Username); return _users[entity.Id]; }
public static void CreateTestUsersAndSaveToFile() { var userMemoryDao = UserMemoryDao.Get(); var userService = new UserServiceImpl(userMemoryDao); User testUser1 = new User("Test", "User1", PasswordHash.PasswordHash.CreateHash("heslo"), UserRole.AppUser, "test1") {Id = 0}; User testUser2 = new User("Test", "User2", PasswordHash.PasswordHash.CreateHash("heslo"), UserRole.AppUser, "test2") {Id = 1}; User testAdmin = new User("Test", "Admin", PasswordHash.PasswordHash.CreateHash("admin"), UserRole.Admin, "admin") {Id = 2}; userService.SaveUser(testUser1); userService.SaveUser(testUser2); userService.SaveUser(testAdmin); userMemoryDao.SaveToFile(); }
private User parseUser() { if (TxbUserName.Text == "" || PsbPassword.Password == "" || TxbFirstName.Text == "" || TxbLastName.Text == "") { MessageBox.Show("Vyplňte všechna pole", "Chyba"); return null; } var user = new User { Id = -1, Username = TxbUserName.Text, Password = PasswordHash.PasswordHash.CreateHash(PsbPassword.Password), FirstName = TxbFirstName.Text, LastName = TxbLastName.Text, Role = ChbIsAdmin.IsChecked == true ? UserRole.Admin : UserRole.AppUser }; return user; }
public User SaveUser(User user) { return _dao.Save(user); }
public User RemoveUser(User user) { return _dao.Remove(user); }