示例#1
0
        /// <summary>
        /// Gets the <see cref="CustomerGroup"/> object that matches the selection criteria.
        /// </summary>
        /// <param name="id">The <see cref="CustomerGroup"/> identifier.</param>
        /// <param name="company">The Company (see <see cref="RefDataNamespace.Company"/>).</param>
        /// <returns>The selected <see cref="CustomerGroup"/> object where found; otherwise, <c>null</c>.</returns>
        public Task <CustomerGroup> GetAsync(string id, RefDataNamespace.Company company)
        {
            return(ManagerInvoker.Default.InvokeAsync(this, async() =>
            {
                ExecutionContext.Current.OperationType = OperationType.Read;
                EntityBase.CleanUp(id);
                if (_getOnPreValidateAsync != null)
                {
                    await _getOnPreValidateAsync(id, company);
                }

                MultiValidator.Create()
                .Add(id.Validate(nameof(id)).Mandatory())
                .Add(company.Validate(nameof(company)).Mandatory().IsValid())
                .Additional((__mv) => _getOnValidate?.Invoke(__mv, id, company))
                .Run().ThrowOnError();

                if (_getOnBeforeAsync != null)
                {
                    await _getOnBeforeAsync(id, company);
                }
                var __result = await CustomerGroupDataSvc.GetAsync(id, company);
                if (_getOnAfterAsync != null)
                {
                    await _getOnAfterAsync(__result, id, company);
                }
                Cleaner.Clean(__result);
                return __result;
            }));
        }
示例#2
0
        /// <summary>
        /// Upserts a <see cref="CustomerGroupCollection"/> as a batch.
        /// </summary>
        /// <param name="value">The Value (see <see cref="CustomerGroupCollection"/>).</param>
        /// <param name="company">The Company (see <see cref="RefDataNamespace.Company"/>).</param>
        public Task UpdateBatchAsync(CustomerGroupCollection value, RefDataNamespace.Company company)
        {
            return(ManagerInvoker.Default.InvokeAsync(this, async() =>
            {
                ExecutionContext.Current.OperationType = OperationType.Unspecified;
                if (value != null)
                {
                    value?.ForEach(__item => __item.Company = company);
                }
                EntityBase.CleanUp(value);
                if (_updateBatchOnPreValidateAsync != null)
                {
                    await _updateBatchOnPreValidateAsync(value, company);
                }

                MultiValidator.Create()
                .Add(value.Validate(nameof(value)).Mandatory().Collection(minCount: 1, maxCount: 1, item: new Beef.Validation.Rules.CollectionRuleItem <CustomerGroup>(CustomerGroupValidator.Default)))
                .Add(company.Validate(nameof(company)).Mandatory().IsValid())
                .Additional((__mv) => _updateBatchOnValidate?.Invoke(__mv, value, company))
                .Run().ThrowOnError();

                if (_updateBatchOnBeforeAsync != null)
                {
                    await _updateBatchOnBeforeAsync(value, company);
                }
                await CustomerGroupDataSvc.UpdateBatchAsync(value);
                if (_updateBatchOnAfterAsync != null)
                {
                    await _updateBatchOnAfterAsync(value, company);
                }
            }));
        }
示例#3
0
        /// <summary>
        /// Gets the <see cref="CustomerGroup"/> collection object that matches the selection criteria.
        /// </summary>
        /// <param name="args">The Args (see <see cref="CustomerGroupArgs"/>).</param>
        /// <param name="paging">The <see cref="PagingArgs"/>.</param>
        /// <returns>A <see cref="CustomerGroupCollectionResult"/>.</returns>
        public Task <CustomerGroupCollectionResult> GetByArgsAsync(CustomerGroupArgs args, PagingArgs paging)
        {
            return(ManagerInvoker.Default.InvokeAsync(this, async() =>
            {
                ExecutionContext.Current.OperationType = OperationType.Read;
                EntityBase.CleanUp(args);
                if (_getByArgsOnPreValidateAsync != null)
                {
                    await _getByArgsOnPreValidateAsync(args, paging);
                }

                MultiValidator.Create()
                .Add(args.Validate(nameof(args)).Entity(CustomerGroupArgsValidator.Default))
                .Additional((__mv) => _getByArgsOnValidate?.Invoke(__mv, args, paging))
                .Run().ThrowOnError();

                if (_getByArgsOnBeforeAsync != null)
                {
                    await _getByArgsOnBeforeAsync(args, paging);
                }
                var __result = await CustomerGroupDataSvc.GetByArgsAsync(args, paging);
                if (_getByArgsOnAfterAsync != null)
                {
                    await _getByArgsOnAfterAsync(__result, args, paging);
                }
                Cleaner.Clean(__result);
                return __result;
            }));
        }
示例#4
0
        /// <summary>
        /// Updates the <see cref="CustomerGroup"/> object.
        /// </summary>
        /// <param name="value">The <see cref="CustomerGroup"/> object.</param>
        /// <param name="id">The <see cref="CustomerGroup"/> identifier.</param>
        /// <param name="company">The Company (see <see cref="RefDataNamespace.Company"/>).</param>
        /// <returns>A refreshed <see cref="CustomerGroup"/> object.</returns>
        public Task <CustomerGroup> UpdateAsync(CustomerGroup value, string id, RefDataNamespace.Company company)
        {
            return(ManagerInvoker.Default.InvokeAsync(this, async() =>
            {
                ExecutionContext.Current.OperationType = OperationType.Update;
                if (value != null)
                {
                    value.Id = id; value.Company = company;
                }
                EntityBase.CleanUp(value, id);
                if (_updateOnPreValidateAsync != null)
                {
                    await _updateOnPreValidateAsync(value, id, company);
                }

                MultiValidator.Create()
                .Add(value.Validate(nameof(value)).Mandatory().Entity(CustomerGroupValidator.Default))
                .Add(company.Validate(nameof(company)).IsValid())
                .Additional((__mv) => _updateOnValidate?.Invoke(__mv, value, id, company))
                .Run().ThrowOnError();

                if (_updateOnBeforeAsync != null)
                {
                    await _updateOnBeforeAsync(value, id, company);
                }
                var __result = await CustomerGroupDataSvc.UpdateAsync(value);
                if (_updateOnAfterAsync != null)
                {
                    await _updateOnAfterAsync(__result, id, company);
                }
                Cleaner.Clean(__result);
                return __result;
            }));
        }
        /// <summary>
        /// Deletes the <see cref="CustomerGroup"/> object.
        /// </summary>
        /// <param name="id">The <see cref="CustomerGroup"/> identifier.</param>
        /// <param name="company">The Company (see <see cref="RefDataNamespace.Company"/>).</param>
        public Task DeleteAsync(string id, RefDataNamespace.Company company)
        {
            return(ManagerInvoker.Default.InvokeAsync(this, async() =>
            {
                ExecutionContext.Current.OperationType = OperationType.Delete;
                EntityBase.CleanUp(id);
                if (_deleteOnPreValidateAsync != null)
                {
                    await _deleteOnPreValidateAsync(id, company).ConfigureAwait(false);
                }

                MultiValidator.Create()
                .Add(id.Validate(nameof(id)).Mandatory())
                .Add(company.Validate(nameof(company)).Mandatory().IsValid())
                .Additional((__mv) => _deleteOnValidate?.Invoke(__mv, id, company))
                .Run().ThrowOnError();

                if (_deleteOnBeforeAsync != null)
                {
                    await _deleteOnBeforeAsync(id, company).ConfigureAwait(false);
                }
                await CustomerGroupDataSvc.DeleteAsync(id, company).ConfigureAwait(false);
                if (_deleteOnAfterAsync != null)
                {
                    await _deleteOnAfterAsync(id, company).ConfigureAwait(false);
                }
            }));
        }