Frapid.WebApi.DataAccess.FilterRepository.RecreateFiltersAsync C# (CSharp) Method

RecreateFiltersAsync() public method

public RecreateFiltersAsync ( string objectName, string filterName, List filters ) : System.Threading.Tasks.Task
objectName string
filterName string
filters List
return System.Threading.Tasks.Task
        public async Task RecreateFiltersAsync(string objectName, string filterName, List<ExpandoObject> filters)
        {
            if (!this.SkipValidation)
            {
                if (!this.Validated)
                {
                    await this.ValidateAsync(AccessTypeEnum.Create, this.LoginId, this.Database, false).ConfigureAwait(false);
                }

                if (!this.HasAccess)
                {
                    Log.Information("Access to add entity \"Filter\" was denied to the user with Login ID {LoginId}. {filters}", this.LoginId, filters);
                    throw new UnauthorizedException("Access is denied.");
                }
            }


            using (var db = DbProvider.GetDatabase(this.Database))
            {
                try
                {
                    await db.BeginTransactionAsync().ConfigureAwait(false);

                    var toDelete = await this.GetWhereAsync
                        (
                            1,
                            new List<Filter>
                            {
                                new Filter
                                {
                                    ColumnName = "object_name",
                                    FilterCondition = (int) FilterCondition.IsEqualTo,
                                    FilterValue = objectName
                                },
                                new Filter
                                {
                                    ColumnName = "filter_name",
                                    FilterCondition = (int) FilterCondition.IsEqualTo,
                                    FilterValue = filterName
                                }
                            }).ConfigureAwait(false);


                    foreach (var filterId in toDelete)
                    {
                        await DefaultDelete.DeleteAsync(db, filterId, "config.filters", "filter_id").ConfigureAwait(false);
                    }

                    foreach (dynamic filter in filters)
                    {
                        filter.audit_user_id = this.UserId;
                        filter.audit_ts = DateTimeOffset.UtcNow;

                        await DefaultInsert.InsertAsync(db, "config.filters", "filter_id", true, filter);
                    }

                    db.CommitTransaction();
                }
                catch
                {
                    db.RollbackTransaction();
                    throw;
                }
            }
        }

Usage Example

Beispiel #1
0
        public async Task RecreateFiltersAsync(string objectName, string filterName, [FromBody] List<ExpandoObject> collection)
        {
            try
            {
                var repository = new FilterRepository(this.AppUser.Tenant, this.AppUser.LoginId, this.AppUser.UserId);
                await repository.RecreateFiltersAsync(objectName, filterName, collection).ConfigureAwait(false);
            }
            catch(UnauthorizedException)
            {
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.Forbidden));
            }
            catch(DataAccessException ex)
            {
                throw new HttpResponseException
                    (
                    new HttpResponseMessage
                    {
                        Content = new StringContent(ex.Message),
                        StatusCode = HttpStatusCode.InternalServerError
                    });
            }
#if !DEBUG
            catch
            {
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError));
            }
#endif
        }