public Task <Person> MergeAsync(Guid fromId, Guid toId) { return(ManagerInvoker.Default.InvokeAsync(this, async() => { ExecutionContext.Current.OperationType = OperationType.Update; EntityBase.CleanUp(fromId, toId); if (_mergeOnPreValidateAsync != null) { await _mergeOnPreValidateAsync(fromId, toId).ConfigureAwait(false); } MultiValidator.Create() .Add(fromId.Validate(nameof(fromId)).Mandatory()) .Add(toId.Validate(nameof(toId)).Mandatory().CompareValue(CompareOperator.NotEqual, fromId, nameof(fromId).ToSentenceCase() !)) .Additional((__mv) => _mergeOnValidate?.Invoke(__mv, fromId, toId)) .Run().ThrowOnError(); if (_mergeOnBeforeAsync != null) { await _mergeOnBeforeAsync(fromId, toId).ConfigureAwait(false); } var __result = await PersonDataSvc.MergeAsync(fromId, toId).ConfigureAwait(false); if (_mergeOnAfterAsync != null) { await _mergeOnAfterAsync(__result, fromId, toId).ConfigureAwait(false); } Cleaner.Clean(__result); return __result; }));
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).ConfigureAwait(false); } 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).ConfigureAwait(false); } var __result = await CustomerGroupDataSvc.GetByArgsAsync(args, paging).ConfigureAwait(false); if (_getByArgsOnAfterAsync != null) { await _getByArgsOnAfterAsync(__result, args, paging).ConfigureAwait(false); } Cleaner.Clean(__result); return __result; })); }
public Task <Person> UpdateAsync(Person value, Guid id) { value.Validate(nameof(value)).Mandatory().Run().ThrowOnError(); return(ManagerInvoker.Default.InvokeAsync(this, async() => { ExecutionContext.Current.OperationType = OperationType.Update; value.Id = id; EntityBase.CleanUp(value, id); if (_updateOnPreValidateAsync != null) { await _updateOnPreValidateAsync(value, id).ConfigureAwait(false); } MultiValidator.Create() .Add(value.Validate(nameof(value)).Entity(PersonValidator.Default)) .Additional((__mv) => _updateOnValidate?.Invoke(__mv, value, id)) .Run().ThrowOnError(); if (_updateOnBeforeAsync != null) { await _updateOnBeforeAsync(value, id).ConfigureAwait(false); } var __result = await PersonDataSvc.UpdateAsync(value).ConfigureAwait(false); if (_updateOnAfterAsync != null) { await _updateOnAfterAsync(__result, id).ConfigureAwait(false); } Cleaner.Clean(__result); return __result; })); }
public Task <Person?> GetAsync(Guid id) { return(ManagerInvoker.Default.InvokeAsync(this, async() => { ExecutionContext.Current.OperationType = OperationType.Read; EntityBase.CleanUp(id); if (_getOnPreValidateAsync != null) { await _getOnPreValidateAsync(id).ConfigureAwait(false); } MultiValidator.Create() .Add(id.Validate(nameof(id)).Mandatory()) .Additional((__mv) => _getOnValidate?.Invoke(__mv, id)) .Run().ThrowOnError(); if (_getOnBeforeAsync != null) { await _getOnBeforeAsync(id).ConfigureAwait(false); } var __result = await PersonDataSvc.GetAsync(id).ConfigureAwait(false); if (_getOnAfterAsync != null) { await _getOnAfterAsync(__result, id).ConfigureAwait(false); } Cleaner.Clean(__result); return __result; })); }
public Task DeleteAsync(Guid id) { return(ManagerInvoker.Default.InvokeAsync(this, async() => { ExecutionContext.Current.OperationType = OperationType.Delete; EntityBase.CleanUp(id); if (_deleteOnPreValidateAsync != null) { await _deleteOnPreValidateAsync(id).ConfigureAwait(false); } MultiValidator.Create() .Add(id.Validate(nameof(id)).Mandatory()) .Additional((__mv) => _deleteOnValidate?.Invoke(__mv, id)) .Run().ThrowOnError(); if (_deleteOnBeforeAsync != null) { await _deleteOnBeforeAsync(id).ConfigureAwait(false); } await PersonDataSvc.DeleteAsync(id).ConfigureAwait(false); if (_deleteOnAfterAsync != null) { await _deleteOnAfterAsync(id).ConfigureAwait(false); } })); }
public Task <CustomerGroup> UpdateAsync(CustomerGroup value, string?id, RefDataNamespace.Company?company) { value.Validate(nameof(value)).Mandatory().Run().ThrowOnError(); return(ManagerInvoker.Default.InvokeAsync(this, async() => { ExecutionContext.Current.OperationType = OperationType.Update; value.Id = id; value.Company = company; EntityBase.CleanUp(value, id); if (_updateOnPreValidateAsync != null) { await _updateOnPreValidateAsync(value, id, company).ConfigureAwait(false); } MultiValidator.Create() .Add(value.Validate(nameof(value)).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).ConfigureAwait(false); } var __result = await CustomerGroupDataSvc.UpdateAsync(value).ConfigureAwait(false); if (_updateOnAfterAsync != null) { await _updateOnAfterAsync(__result, id, company).ConfigureAwait(false); } Cleaner.Clean(__result); return __result; })); }
public Task UpdateBatchAsync(CustomerGroupCollection?value, RefDataNamespace.Company?company) { return(ManagerInvoker.Default.InvokeAsync(this, async() => { ExecutionContext.Current.OperationType = OperationType.Unspecified; value?.ForEach(__item => __item.Company = company); EntityBase.CleanUp(value); if (_updateBatchOnPreValidateAsync != null) { await _updateBatchOnPreValidateAsync(value, company).ConfigureAwait(false); } 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).ConfigureAwait(false); } await CustomerGroupDataSvc.UpdateBatchAsync(value).ConfigureAwait(false); if (_updateBatchOnAfterAsync != null) { await _updateBatchOnAfterAsync(value, company).ConfigureAwait(false); } })); }
public Task <Gender> CreateAsync(Gender value) { value.Validate(nameof(value)).Mandatory().Run().ThrowOnError(); return(ManagerInvoker.Default.InvokeAsync(this, async() => { ExecutionContext.Current.OperationType = OperationType.Create; EntityBase.CleanUp(value); if (_createOnPreValidateAsync != null) { await _createOnPreValidateAsync(value).ConfigureAwait(false); } MultiValidator.Create() .Add(value.Validate(nameof(value)).Entity(new ReferenceDataValidator <Gender>())) .Additional((__mv) => _createOnValidate?.Invoke(__mv, value)) .Run().ThrowOnError(); if (_createOnBeforeAsync != null) { await _createOnBeforeAsync(value).ConfigureAwait(false); } var __result = await GenderDataSvc.CreateAsync(value).ConfigureAwait(false); if (_createOnAfterAsync != null) { await _createOnAfterAsync(__result).ConfigureAwait(false); } Cleaner.Clean(__result); return __result; })); }
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); } })); }
public Task <Person?> GetAsync(Guid id) => ManagerInvoker.Current.InvokeAsync(this, async() => { Cleaner.CleanUp(id); await MultiValidator.Create() .Add(id.Validate(nameof(id)).Mandatory()) .RunAsync(throwOnError: true).ConfigureAwait(false); return(Cleaner.Clean(await _dataService.GetAsync(id).ConfigureAwait(false))); }, BusinessInvokerArgs.Read);
public async Task <TransactionCollectionResult> GetTransactionsAsync(string?accountId, TransactionArgs?args, PagingArgs?paging) => await ManagerInvoker.Current.InvokeAsync(this, async() => { Cleaner.CleanUp(accountId, args); await MultiValidator.Create() .Add(accountId.Validate(nameof(accountId)).Mandatory().Common(Validators.AccountId)) .Add(args.Validate(nameof(args)).Entity().With <IValidator <TransactionArgs> >()) .RunAsync(throwOnError: true).ConfigureAwait(false); return(Cleaner.Clean(await _dataService.GetTransactionsAsync(accountId, args, paging).ConfigureAwait(false))); }, BusinessInvokerArgs.Read).ConfigureAwait(false);
public Task <PostalInfo?> GetPostCodesAsync(RefDataNamespace.Country?country, string?state, string?city) => ManagerInvoker.Current.InvokeAsync(this, async() => { Cleaner.CleanUp(country, state, city); await MultiValidator.Create() .Add(country.Validate(nameof(country)).Mandatory().IsValid()) .Add(state.Validate(nameof(state)).Mandatory()) .Add(city.Validate(nameof(city)).Mandatory()) .RunAsync(throwOnError: true).ConfigureAwait(false); return(Cleaner.Clean(await _dataService.GetPostCodesAsync(country, state, city).ConfigureAwait(false))); }, BusinessInvokerArgs.Read);
public Task <Product?> GetAsync(int id) { return(ManagerInvoker.Current.InvokeAsync(this, async() => { ExecutionContext.Current.OperationType = OperationType.Read; Cleaner.CleanUp(id); MultiValidator.Create() .Add(id.Validate(nameof(id)).Mandatory()) .Run().ThrowOnError(); return Cleaner.Clean(await _dataService.GetAsync(id).ConfigureAwait(false)); })); }
public Task <Balance?> GetBalanceAsync(string?accountId) { return(ManagerInvoker.Current.InvokeAsync(this, async() => { ExecutionContext.Current.OperationType = OperationType.Read; Cleaner.CleanUp(accountId); MultiValidator.Create() .Add(accountId.Validate(nameof(accountId)).Mandatory()) .Run().ThrowOnError(); return Cleaner.Clean(await _dataService.GetBalanceAsync(accountId).ConfigureAwait(false)); })); }
public Task <ProductCollectionResult> GetByArgsAsync(ProductArgs?args, PagingArgs?paging) { return(ManagerInvoker.Current.InvokeAsync(this, async() => { ExecutionContext.Current.OperationType = OperationType.Read; Cleaner.CleanUp(args); MultiValidator.Create() .Add(args.Validate(nameof(args)).Entity(ProductArgsValidator.Default)) .Run().ThrowOnError(); return Cleaner.Clean(await _dataService.GetByArgsAsync(args, paging).ConfigureAwait(false)); })); }
public Task <PersonCollectionResult> GetAll2Async() => ManagerInvoker.Current.InvokeAsync(this, async() => { await(_getAll2OnPreValidateAsync?.Invoke() ?? Task.CompletedTask).ConfigureAwait(false); await MultiValidator.Create() .Additional((__mv) => _getAll2OnValidate?.Invoke(__mv)) .RunAsync(throwOnError: true).ConfigureAwait(false); await(_getAll2OnBeforeAsync?.Invoke() ?? Task.CompletedTask).ConfigureAwait(false); var __result = await _dataService.GetAll2Async().ConfigureAwait(false); await(_getAll2OnAfterAsync?.Invoke(__result) ?? Task.CompletedTask).ConfigureAwait(false); return(Cleaner.Clean(__result)); }, BusinessInvokerArgs.Read);
public Task DeleteAsync(Guid id) { return(ManagerInvoker.Current.InvokeAsync(this, async() => { ExecutionContext.Current.OperationType = OperationType.Delete; Cleaner.CleanUp(id); MultiValidator.Create() .Add(id.Validate(nameof(id)).Mandatory()) .Run().ThrowOnError(); await _dataService.DeleteAsync(id).ConfigureAwait(false); })); }
public Task <TransactionCollectionResult> GetTransactionsAsync(string?accountId, TransactionArgs?args, PagingArgs?paging) { return(ManagerInvoker.Current.InvokeAsync(this, async() => { ExecutionContext.Current.OperationType = OperationType.Read; Cleaner.CleanUp(accountId, args); MultiValidator.Create() .Add(accountId.Validate(nameof(accountId)).Mandatory().Common(Validators.AccountId)) .Add(args.Validate(nameof(args)).Entity(TransactionArgsValidator.Default)) .Run().ThrowOnError(); return Cleaner.Clean(await _dataService.GetTransactionsAsync(accountId, args, paging).ConfigureAwait(false)); })); }
public Task DeleteAsync(Guid id) => ManagerInvoker.Current.InvokeAsync(this, async() => { Cleaner.CleanUp(id); await(_deleteOnPreValidateAsync?.Invoke(id) ?? Task.CompletedTask).ConfigureAwait(false); await MultiValidator.Create() .Add(id.Validate(nameof(id)).Mandatory()) .Additional((__mv) => _deleteOnValidate?.Invoke(__mv, id)) .RunAsync(throwOnError: true).ConfigureAwait(false); await(_deleteOnBeforeAsync?.Invoke(id) ?? Task.CompletedTask).ConfigureAwait(false); await _dataService.DeleteAsync(id).ConfigureAwait(false); await(_deleteOnAfterAsync?.Invoke(id) ?? Task.CompletedTask).ConfigureAwait(false); }, BusinessInvokerArgs.Delete);
public Task <PersonDetailCollectionResult> GetDetailByArgsAsync(PersonArgs?args, PagingArgs?paging) => ManagerInvoker.Current.InvokeAsync(this, async() => { Cleaner.CleanUp(args); await(_getDetailByArgsOnPreValidateAsync?.Invoke(args, paging) ?? Task.CompletedTask).ConfigureAwait(false); await MultiValidator.Create() .Add(args.Validate(nameof(args)).Entity().With <IValidator <PersonArgs> >()) .Additional((__mv) => _getDetailByArgsOnValidate?.Invoke(__mv, args, paging)) .RunAsync(throwOnError: true).ConfigureAwait(false); await(_getDetailByArgsOnBeforeAsync?.Invoke(args, paging) ?? Task.CompletedTask).ConfigureAwait(false); var __result = await _dataService.GetDetailByArgsAsync(args, paging).ConfigureAwait(false); await(_getDetailByArgsOnAfterAsync?.Invoke(__result, args, paging) ?? Task.CompletedTask).ConfigureAwait(false); return(Cleaner.Clean(__result)); }, BusinessInvokerArgs.Read);
public Task <Contact> CreateAsync(Contact value) { value.Validate(nameof(value)).Mandatory().Run().ThrowOnError(); return(ManagerInvoker.Current.InvokeAsync(this, async() => { ExecutionContext.Current.OperationType = OperationType.Create; Cleaner.CleanUp(value); MultiValidator.Create() .Add(value.Validate(nameof(value))) .Run().ThrowOnError(); return Cleaner.Clean(await _dataService.CreateAsync(value).ConfigureAwait(false)); })); }
public Task <Gender> UpdateAsync(Gender value, Guid id) { value.Validate(nameof(value)).Mandatory().Run().ThrowOnError(); return(ManagerInvoker.Current.InvokeAsync(this, async() => { ExecutionContext.Current.OperationType = OperationType.Update; value.Id = id; Cleaner.CleanUp(value); MultiValidator.Create() .Add(value.Validate(nameof(value)).Entity(new ReferenceDataValidator <Gender>())) .Run().ThrowOnError(); return Cleaner.Clean(await _dataService.UpdateAsync(value).ConfigureAwait(false)); })); }
public Task <Contact> UpdateAsync(Contact value) { return(ManagerInvoker.Default.InvokeAsync(this, async() => { ExecutionContext.Current.OperationType = OperationType.Update; EntityBase.CleanUp(value); MultiValidator.Create() .Add(value.Validate(nameof(value)).Mandatory()) .Run().ThrowOnError(); var __result = await _dataService.UpdateAsync(value).ConfigureAwait(false); Cleaner.Clean(__result); return __result; })); }
public Task <TripPerson> UpdateAsync(TripPerson value, string?id) { value.Validate(nameof(value)).Mandatory().Run().ThrowOnError(); return(ManagerInvoker.Current.InvokeAsync(this, async() => { ExecutionContext.Current.OperationType = OperationType.Update; value.Id = id; Cleaner.CleanUp(value); MultiValidator.Create() .Add(value.Validate(nameof(value))) .Run().ThrowOnError(); return Cleaner.Clean(await _dataService.UpdateAsync(value).ConfigureAwait(false)); })); }
public Task <Person> UpdateWithRollbackAsync(Person value, Guid id) => ManagerInvoker.Current.InvokeAsync(this, async() => { await value.Validate().Mandatory().RunAsync(throwOnError: true).ConfigureAwait(false); value.Id = id; Cleaner.CleanUp(value); await(_updateWithRollbackOnPreValidateAsync?.Invoke(value, id) ?? Task.CompletedTask).ConfigureAwait(false); await MultiValidator.Create() .Add(value.Validate(nameof(value)).Entity().With <IValidator <Person> >()) .Additional((__mv) => _updateWithRollbackOnValidate?.Invoke(__mv, value, id)) .RunAsync(throwOnError: true).ConfigureAwait(false); await(_updateWithRollbackOnBeforeAsync?.Invoke(value, id) ?? Task.CompletedTask).ConfigureAwait(false); var __result = await _dataService.UpdateWithRollbackAsync(value).ConfigureAwait(false); await(_updateWithRollbackOnAfterAsync?.Invoke(__result, id) ?? Task.CompletedTask).ConfigureAwait(false); return(Cleaner.Clean(__result)); }, BusinessInvokerArgs.Update);
public Task <Person> CreateAsync(Person value) => ManagerInvoker.Current.InvokeAsync(this, async() => { await value.Validate().Mandatory().RunAsync(throwOnError: true).ConfigureAwait(false); value.Id = await _guidIdGen.GenerateIdentifierAsync <Person>().ConfigureAwait(false); Cleaner.CleanUp(value); await(_createOnPreValidateAsync?.Invoke(value) ?? Task.CompletedTask).ConfigureAwait(false); await MultiValidator.Create() .Add(value.Validate(nameof(value)).Entity().With <IValidator <Person> >()) .Additional((__mv) => _createOnValidate?.Invoke(__mv, value)) .RunAsync(throwOnError: true).ConfigureAwait(false); await(_createOnBeforeAsync?.Invoke(value) ?? Task.CompletedTask).ConfigureAwait(false); var __result = await _dataService.CreateAsync(value).ConfigureAwait(false); await(_createOnAfterAsync?.Invoke(__result) ?? Task.CompletedTask).ConfigureAwait(false); return(Cleaner.Clean(__result)); }, BusinessInvokerArgs.Create);
public async Task MultiValidatorTest() { MultiValidator.Validators.AddRange(new[] { typeof(DataValidator <>), typeof(SQLInjectionValidator <>) }); UpdateUserProfileDataRequestDto message = new UpdateUserProfileDataRequestDto() { NewBiography = null, NewEmail = ";DROP TABLE test;", NewPassword = null, NewPhoneNumber = null, OldBiography = null, OldEmail = "*****@*****.**", OldPassword = null, OldPhoneNumber = null, UserID = -2 }; bool result = await MultiValidator <UpdateUserProfileDataRequestDto> .IsValid(message); result.Should().BeFalse(); message.NewEmail = "*****@*****.**"; result = await MultiValidator <UpdateUserProfileDataRequestDto> .IsValid(message); result.Should().BeFalse(); message.NewEmail = ";DROP TABLE test;"; message.UserID = 2; result = await MultiValidator <UpdateUserProfileDataRequestDto> .IsValid(message); result.Should().BeFalse(); message.NewEmail = "*****@*****.**"; result = await MultiValidator <UpdateUserProfileDataRequestDto> .IsValid(message); result.Should().BeTrue(); }
public static Task <bool> IsValid <T>(this T obj) => MultiValidator <T> .IsValid(obj);