/// <summary> /// Deletes a user from the database /// </summary> /// <param name="userId">id of the user to delete</param> /// <returns>false if there is no such user in the database</returns> public static bool DeleteUser(int userId) { bool success = false; DataBase db = DataBase.GetInstance(); db.SetConnections(Constants.PATH); db.LoadUsers(); success = db.Users.Remove(db.GetUserById(userId)); db.CommitUsers(); return(success); }
/// <summary> /// Method adds new user to database /// </summary> /// <param name="newName">new user's name</param> /// <param name="newPassword">new user's password</param> /// <param name="rolesIdes">List of Ides of user's roles</param> /// <returns></returns> public static bool AddNewUser(string newName, string newPassword, List <int> rolesIdes) { if (CheckNameExistence(newName) == true) { return(false); } DataBase db = DataBase.GetInstance(); db.SetConnections(Constants.PATH); db.LoadUsers(); db.Add(new User(db.Users.Last().Id + 1, newName, newPassword, rolesIdes)); db.CommitUsers(); return(true); }
/// <summary> /// Method removes user's role /// </summary> /// <param name="userId">User's idNumber</param> /// <param name="roleId">The role's id to remove</param> /// <returns>True if role was successfully removed </returns> public static bool RemoveUsersRole(int userId, int roleId) { DataBase db = DataBase.GetInstance(); db.SetConnections(Constants.PATH); db.LoadUsers(); foreach (User user in db.Users) { if (user.Id == userId) { user.RolesId.Remove(roleId); return(true); } } db.CommitUsers(); return(false); }