public UnitOfWorkTest() { _cnxFactory = new ConnectionTransactionFactory(); _unitOfWork = new UnitOfWork(_cnxFactory); UnitOfWorkFactory.GetDefault = () => _unitOfWork; _userWriter = new UserWriter(_cnxFactory); _userFinder = new UserFinder(_cnxFactory); }
/// <summary> /// This method deletes a 'User' object. /// </summary> /// <param name='List<PolymorphicObject>'>The 'User' to delete. /// <returns>A PolymorphicObject object with a Boolean value. internal PolymorphicObject DeleteUser(List <PolymorphicObject> parameters, DataConnector dataConnector) { // Initial Value PolymorphicObject returnObject = new PolymorphicObject(); // If the data connection is connected if ((dataConnector != null) && (dataConnector.Connected == true)) { // Create Delete StoredProcedure DeleteUserStoredProcedure deleteUserProc = null; // verify the first parameters is a(n) 'User'. if (parameters[0].ObjectValue as User != null) { // Create User User user = (User)parameters[0].ObjectValue; // verify user exists if (user != null) { // Now create deleteUserProc from UserWriter // The DataWriter converts the 'User' // to the SqlParameter[] array needed to delete a 'User'. deleteUserProc = UserWriter.CreateDeleteUserStoredProcedure(user); } } // Verify deleteUserProc exists if (deleteUserProc != null) { // Execute Delete Stored Procedure bool deleted = this.DataManager.UserManager.DeleteUser(deleteUserProc, dataConnector); // Create returnObject.Boolean returnObject.Boolean = new NullableBoolean(); // If delete was successful if (deleted) { // Set returnObject.Boolean.Value to true returnObject.Boolean.Value = NullableBooleanEnum.True; } else { // Set returnObject.Boolean.Value to false returnObject.Boolean.Value = NullableBooleanEnum.False; } } } else { // Raise Error Data Connection Not Available throw new Exception("The database connection is not available."); } // return value return(returnObject); }
/// <summary> /// This method finds a 'User' object. /// </summary> /// <param name='List<PolymorphicObject>'>The 'User' to delete. /// <returns>A PolymorphicObject object with a Boolean value. internal PolymorphicObject FindUser(List <PolymorphicObject> parameters, DataConnector dataConnector) { // Initial Value PolymorphicObject returnObject = new PolymorphicObject(); // locals User user = null; // If the data connection is connected if ((dataConnector != null) && (dataConnector.Connected == true)) { // Create Find StoredProcedure FindUserStoredProcedure findUserProc = null; // verify the first parameters is a 'User'. if (parameters[0].ObjectValue as User != null) { // Get UserParameter User paramUser = (User)parameters[0].ObjectValue; // verify paramUser exists if (paramUser != null) { // Now create findUserProc from UserWriter // The DataWriter converts the 'User' // to the SqlParameter[] array needed to find a 'User'. findUserProc = UserWriter.CreateFindUserStoredProcedure(paramUser); } // Verify findUserProc exists if (findUserProc != null) { // Execute Find Stored Procedure user = this.DataManager.UserManager.FindUser(findUserProc, dataConnector); // if dataObject exists if (user != null) { // set returnObject.ObjectValue returnObject.ObjectValue = user; } } } else { // Raise Error Data Connection Not Available throw new Exception("The database connection is not available."); } } // return value return(returnObject); }
/// <summary> /// This method fetches all 'User' objects. /// </summary> /// <param name='List<PolymorphicObject>'>The 'User' to delete. /// <returns>A PolymorphicObject object with all 'Users' objects. internal PolymorphicObject FetchAll(List <PolymorphicObject> parameters, DataConnector dataConnector) { // Initial Value PolymorphicObject returnObject = new PolymorphicObject(); // locals List <User> userListCollection = null; // Create FetchAll StoredProcedure FetchAllUsersStoredProcedure fetchAllProc = null; // If the data connection is connected if ((dataConnector != null) && (dataConnector.Connected == true)) { // Get UserParameter // Declare Parameter User paramUser = null; // verify the first parameters is a(n) 'User'. if (parameters[0].ObjectValue as User != null) { // Get UserParameter paramUser = (User)parameters[0].ObjectValue; } // Now create FetchAllUsersProc from UserWriter fetchAllProc = UserWriter.CreateFetchAllUsersStoredProcedure(paramUser); } // Verify fetchAllProc exists if (fetchAllProc != null) { // Execute FetchAll Stored Procedure userListCollection = this.DataManager.UserManager.FetchAllUsers(fetchAllProc, dataConnector); // if dataObjectCollection exists if (userListCollection != null) { // set returnObject.ObjectValue returnObject.ObjectValue = userListCollection; } } else { // Raise Error Data Connection Not Available throw new Exception("The database connection is not available."); } // return value return(returnObject); }
public static void CreateUser(string name) { //Check to see if we have an existing name Components.Models.User user = UserReader.GetUserByName(name); if (user == null) { user = new Components.Models.User(name); UserWriter.CreateUser(user); } else { throw new MembershipCreateUserException(MembershipCreateStatus.DuplicateUserName); } }
public async Task <ActionResult> UpdateUserModal(UpdateUserModal model) { if (!ModelState.IsValid) { return(View(model)); } var result = await UserWriter.UpdateUser(model); if (!ModelState.IsWriterResultValid(result)) { return(View(model)); } return(CloseModalSuccess()); }
public ActionResult Edit(int Id, string tipo) { if (Session["loggedAdmin"] == null) { return(RedirectToAction("Index", "Home")); } string filePath = Server.MapPath(@"/App_Data/Utenti.txt"); var reader = new UserReader(); var writer = new UserWriter(); IList <Account> listaAccount = reader.Read(filePath); var daAggiornare = listaAccount.First(e => e.Id == Id); daAggiornare.Tipo = (tipo == "Normal") ? Account.tipo.Normal : Account.tipo.Premium; writer.Reset(filePath); foreach (var account in listaAccount) { int Tipo = (account.Tipo == Account.tipo.Normal) ? 1 : 2; string linea = $"{account.Id},{account.Nome},{account.Cognome},{account.Email},{account.Password},{Tipo}"; writer.Append(filePath, linea); } return(RedirectToAction("Index", "Account")); }
public async Task <ActionResult> RemoveSecurityRole(UserRoleModel model) { if (!ModelState.IsValid) { return(View("UpdateRoleModal", model)); } var result = await UserWriter.RemoveUserRole(model); if (!ModelState.IsWriterResultValid(result)) { return(View("UpdateRoleModal", new UpdateUserRoleModel { UserName = model.UserName, ButtonName = "Remove Role", ActionMethod = "RemoveSecurityRole", Description = string.Format("Remove a security role from '{0}'", model.UserName) })); } return(CloseModal()); }
public WriterTest() { _userWriter = new UserWriter(new ConnectionFactory()); _userFinder = new UserFinder(new ConnectionFactory()); }