Ejemplo n.º 1
0
        /// <summary>
        /// Updates the access point with the provided values. Any null values will be ignored during the update
        /// </summary>
        /// <param name="id">access point id</param>
        /// <param name="transaction">transaction</param>
        /// <param name="description">access point description</param>
        /// <param name="isActive">access point is active flag</param>
        /// <param name="accessLevel">access point access level</param>
        /// <returns></returns>
        public async Task <InsertOrUpdDbResult> UpdateAccessPointAsync(
            int id,
            IDbTransaction transaction,
            String description                 = null,
            bool?isActive                      = null,
            bool?isDeleted                     = null,
            AccessLevel?accessLevel            = null,
            AccessPointDirectionType?direction = null)
        {
            var serialNumber = await this.GetAccessPointSerialNumberAsync(id, transaction);

            if (String.IsNullOrEmpty(serialNumber))
            {
                return(InsertOrUpdDbResult.NotFound);
            }
            else
            {
                var param = new DynamicParameters(new { serial_number = serialNumber, description = description, is_active = isActive, is_deleted = isDeleted, level_id = (int?)accessLevel, direction_id = (int?)direction });
                param.AddIdentity();

                var inserted = await transaction.ExecuteStoreProcedureAsync <bool>("access_control.usp_insert_or_update_access_point", param);

                return(InsertOrUpdDbResult.Create(param.Identity(), inserted, inserted == false));
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Registers a tag with the specified number and access level and associated user if such tag does not exists already
        /// </summary>
        /// <param name="number">Number of the tag</param>
        /// <param name="userId">User id</param>
        /// <param name="accessLevel">Tag access level</param>
        /// <param name="transaction">Transaction</param>
        /// <returns>True if the tag does not already exists and is added to the database</returns>
        public async Task <InsertOrUpdDbResult> InsertTagIfNotExistsAsync(String number, int userId, AccessLevel accessLevel, IDbTransaction transaction)
        {
            var dynamicParams = new DynamicParameters(new { @number = number, @user_id = userId, @level_id = accessLevel, @is_active = true, @is_deleted = false });

            dynamicParams.AddIdentity();

            var isInserted = await transaction.ExecuteStoreProcedureAsync <bool>("access_control.usp_insert_tag_if_not_exists", dynamicParams);

            return(InsertOrUpdDbResult.Create(dynamicParams.Identity(), isInserted, false));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Insert administration user
        /// </summary>
        /// <param name="email">email</param>
        /// <param name="passwordHash">password hash</param>
        /// <param name="roles">roles</param>
        /// <param name="transaction">transaction</param>
        /// <returns></returns>
        public async Task <InsertOrUpdDbResult> InsertAdministrationUserAsync(String email, String passwordHash, UserRoles roles, IDbTransaction transaction)
        {
            var param = new DynamicParameters(new { @email = email, @password_hash = passwordHash, @roles = AsIntList(roles.Ints()) });

            param.Add("identity", dbType: DbType.Int32, direction: ParameterDirection.Output);

            var isInserted = await transaction.ExecuteStoreProcedureAsync <bool>("administration.usp_insert_user_if_not_exists", param : param);

            return(InsertOrUpdDbResult.Create(param.Identity(), isInserted, isUpdated: false));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Inserts access point if does not exists or updates it by identifier. If any of the provided values is null the column won't be updated
        /// </summary>
        /// <param name="identifier">identifier of the access point</param>
        /// <param name="transaction">transaction</param>
        /// <param name="description">description of the access point</param>
        /// <param name="IsActive">is active flag</param>
        /// <param name="accessLevel">access level of the access point</param>
        /// <returns></returns>
        public async Task <InsertOrUpdDbResult> InsertAccessPointIfNotExistsAsync(
            String serialNumber,
            IDbTransaction transaction,
            String description,
            bool IsActive,
            AccessLevel accessLevel,
            AccessPointDirectionType direction)
        {
            var param = new DynamicParameters(new { serial_number = serialNumber, description = description, is_active = IsActive, level_id = accessLevel, direction_id = direction });

            param.AddIdentity();

            var isInserted = await transaction.ExecuteStoreProcedureAsync <bool>("access_control.usp_insert_access_point_if_not_exists", param : param);

            return(InsertOrUpdDbResult.Create(param.Identity(), isInserted, false));
        }