/// <summary> /// Remove entity item from data source using default query builder /// </summary> /// <typeparam name="TEntity">Entity model</typeparam> /// <param name="unitOfWorkAsync"></param> /// <param name="predicate">Custom filter predicate</param> public static async Task RemoveAsync <TEntity>(this IUnitOfWorkAsync unitOfWorkAsync, Expression <Func <TEntity, bool> > predicate) where TEntity : class { var repository = unitOfWorkAsync.GetRepository <TEntity>(); var entity = await unitOfWorkAsync.LoadAsync(predicate); repository.Remove(entity); }
public async Task <CustomerViewModel> GetAsync(CustomerInquirySearchModel query) { query.ThrowNoValidIf(q => string.IsNullOrEmpty(q.Email) && !q.CustomerID.HasValue, "Bad Request"); query.ThrowNoValidIf(q => !string.IsNullOrEmpty(q.Email) && !q.Email.IsValidEmail(), "Invalid Email"); var searchPredicate = new CustomerInquirySearchCriteriaBuilder().Build(query); var customer = await _unitOfWorkAsync.LoadAsync(searchPredicate, x => x.Transactions); customer.ThrowIfNull("Customer Inquiry is not found"); var recentTransactions = customer.Transactions .OrderByDescending(t => t.DateTime) .Take(CountOfTopRecentElements) .Select(t => new TransactionViewModel { Id = t.Id, Amount = t.Amount, Currency = t.Currency.Code, Date = Helper.Format(t.DateTime), Status = t.Status.GetDescription() }) .ToList(); return(new CustomerViewModel { Id = customer.Id, Name = customer.Name, Email = customer.ContactEmail, Mobile = customer.MobileNo, Transactions = recentTransactions, }); }