public override bool DeleteRole(string roleName, bool throwOnPopulatedRole) { // Find matching role var matchingRole = (from role in dataAccessor.Roles.Include(x => x.Users) where role.RoleName == roleName select new { role.Id, role.RoleName, UserCount = role.Users.Count }) .SingleOrDefault(); // Throw error if no matching role if (matchingRole == null) { throw new FormattedException("Delete Role: Invalid role '{0}'", roleName); } // Throw error if populated if (throwOnPopulatedRole && matchingRole.UserCount > 0) { throw new FormattedException("Delete Role: Role still has {0} user(s) assigned", matchingRole.UserCount); } // Delete role dataAccessor.Delete <Role>(x => x.Id == matchingRole.Id); return(dataAccessor.SaveChanges() > 0); }
/// <summary> /// Delete the entry from persistant storage. /// It is a generic method, it can be used to delete any of the /// objects which implements Framework.Common.Models.IModel interface. /// </summary> /// <typeparam name="T"> /// Any type which implements Framework.Common.Models.IModel interface. /// </typeparam> /// <param name="primaryKey"> /// Primary key of the entity which is used to identify the entity. /// </param> /// <returns> /// A boolean value indicating delete operation is succesful or not. /// </returns> public bool Delete <T>(int primaryKey) where T : IModel, new() { IFrameworkDataAccessFactory factory = DbInstance.CurrentInstance; // retrieves connection string of specified server type string connectionString = ServerManager.Instance.GetConnectionString(new T().DatabaseServerType); IDbConnection connection = factory.CreateConnection(connectionString); bool isSuccess = false; try { connection.Open(); // create common data accessor for doing database operations. IDataAccessor dataAccessor = factory.CreateAccessor(connection, typeof(T)); dataAccessor.Delete(primaryKey); isSuccess = true; } finally { // Close the Connection if Opened if (connection.State == ConnectionState.Open) { connection.Close(); } } return(isSuccess); }
public void DeleteUser(AccountUser user) { dataAccessorAccountUser.Delete(user); }
public Task <OperationResult> DeleteAsync(TModel model) => Task.Run(() => _dataAccessor.Delete(_queryProvider.Delete(model)));
public void DeletePlay(PlayModel play) { _plays.Remove(play); _playAccessor.Delete(play.Id); }