public void AddUser(string userName) { var list = DataController.GetData(_filepath); if (CheckIfUserExists(userName, list)) { var newId = Convert.ToInt32(list[list.Count - 1].Id) + 1; list.Add(new User(userName, newId.ToString())); DataController.SendData(_filepath, list); } else { throw new ArgumentException("User already exists"); } }
public bool DeleteUser(string id) { if (id.Equals("1")) { throw new ArgumentException("Can not delete Bob"); } var list = DataController.GetData(_filepath); foreach (var user in list) { if (user.Id.Equals(id)) { list.Remove(user); DataController.SendData(_filepath, list); return(true); } } throw new ArgumentException("User does not exist"); }
public bool UpdateUserName(string id, string newName) { var list = DataController.GetData(_filepath); foreach (var user in list) { if (user.Name.Equals(newName)) { throw new ArgumentException("User already exists"); } if (user.Id.Equals(id)) { user.Name = newName; DataController.SendData(_filepath, list); return(true); } } throw new ArgumentException("User doesn't exist"); }
public List <User> GetAllUsers() { // TODO: extract this later return(DataController.GetData(_filepath)); }