public void DeleteUser(User user)
        {
            if (user == null)
                throw new ArgumentNullException(nameof(user));
            if (user.Id == null)
                throw new ArgumentNullException(nameof(user.Id));
            if (_userRepo.GetById(user.Id) == null)
                throw new ArgumentException(nameof(user));

            _userRepo.Delete(user);
        }
        public void AddUser(User user)
        {
            if (user == null)
                throw new ArgumentNullException(nameof(user));
            if (user.Name == null)
                throw new ArgumentNullException(nameof(user.Name));

            user.Id = ObjectId.GenerateNewId().ToString();
            
            _userRepo.Add(user);
        }
 public void Delete(User user)
 {
     _db.AppUsers()
        .DeleteOne(x => x.Id == user.Id);
 }
 public void Update(User user)
 {
     _db.AppUsers()
        .FindOneAndReplace(x => x.Id == user.Id, user);
 }
 public void Add(User user)
 {
     _db.AppUsers()
        .InsertOne(user);
 }
        public void Run()
        {
            Console.WriteLine("Welcome to a MongoDB Sample program.");
            var userService = GetNewUserService();
            while (true)
            {
                var opt = Menu();
                switch (opt)
                {
                    case 1:
                        var users = userService.GetAllUsers();

                        foreach (var user in users)
                        {
                            Console.WriteLine(user.ToString());
                        }

                        break;
                    case 2:
                        Console.Write("Please enter a name to lookup |> ");
                        var name = Console.ReadLine();
                        var queriedUser = userService.GetUserByName(name);
                        if (queriedUser == null)
                        {
                            Console.WriteLine("Could not find user by that name");
                            break;
                        }
                        Console.WriteLine(queriedUser.ToString());
                        break;
                    case 3:
                        Console.Write("Please enter a name |> ");
                        var newName = Console.ReadLine();
                        Console.Write("Please enter a value for the mutable field |> ");
                        var newMutableValue = Console.ReadLine();

                        if (userService.GetUserByName(newName) != null)
                        {
                            Console.WriteLine("A user by this name already exists!");
                            break;
                        }
                        var newUser = new User
                        {
                            Name = newName,
                            MutableField = newMutableValue
                        };
                        userService.AddUser(newUser);
                        break;
                    case 4:
                        Console.Write("Please enter the name of the user to update |> ");
                        name = Console.ReadLine();
                        if (name == "Will" || name == "Tim" || name == "Tari" || name == "Richard")
                        {
                            Console.WriteLine("These users cannot be deleted");
                            break;
                        }
                        var userToUpdate = userService.GetUserByName(name);
                        if (userToUpdate == null)
                        {
                            Console.WriteLine("Could not find user by that name");
                            break;
                        }
                        Console.WriteLine("Please enter a new mutable value |> ");
                        userToUpdate.MutableField = Console.ReadLine();
                        userService.UpdateUser(userToUpdate);
                        break;
                    case 5:
                        Console.Write("Please enter the name of the user to delete |> ");
                        name = Console.ReadLine();
                        if (name == "Will" || name == "Tim" || name == "Tari" || name == "Richard")
                        {
                            Console.WriteLine("These users cannot be deleted");
                            break;
                        }
                        var userToDelete = userService.GetUserByName(name);
                        if (userToDelete == null)
                        {
                            Console.WriteLine("Could not find user by that name");
                            break;
                        }
                        userService.DeleteUser(userToDelete);
                        break;
                    case 6:
                        Console.WriteLine("Goodbye!");
                        return;
                }
            }
        }