private AccountStatementViewModel[] GetStatementsByEventId(string eventId, IMyMentorRepository repository, EntityDto[] entities, IEnumerable<CouponStatusDto> couponStatuses, EventTypeDto[] eventTypes, IEnumerable<TransactionTypeDto> transactionTypes, IEnumerable<CouponTypeDto> couponTypes, IEnumerable<SupportTypeDto> supportTypes, string nisCurrencySymbol) { var accountStatementVm = new List<AccountStatementViewModel>(); var clipStatuses = repository.FindClipStatuses(); var purchaseStatuses = repository.FindPurchaseStatues().ToArray(); Event eventrecord = null; eventrecord = Task.Run(() => repository.FindEventById(eventId)).Result; if (eventrecord == null) { return new AccountStatementViewModel[0]; } var eventType = eventTypes.FirstOrDefault(x => x.EventTypeKey == eventrecord.EventType); var action = eventType != null ? eventType.GetLocalizedField("EventType") : string.Empty; // add event AddEvent(entities, nisCurrencySymbol, accountStatementVm, eventrecord, action); // add coupons AddCoupons(eventId, couponTypes, supportTypes, repository, entities, couponStatuses, accountStatementVm, nisCurrencySymbol); IEnumerable<Purchase> purchases = repository.FindPurchasesByEventId(eventId); // add account statements IEnumerable<AccountStatement> accountStatements = Task.Run(() => repository.FindAccountStatementsByEventId(eventId)).Result; var accountStatementViewModels = GetAccountStatements( accountStatements, entities, eventTypes, transactionTypes, couponTypes, supportTypes, couponStatuses, nisCurrencySymbol, purchases, clipStatuses, purchaseStatuses); accountStatementVm.AddRange(accountStatementViewModels); // add purchases foreach (var purchase in purchases) { accountStatementVm.Add(new AccountStatementViewModel { Id = purchase.ObjectId, Type = entities.FindEntityName(EntityKeys.Purchases), UserName = purchase.UserKey.GetFullName(Language.CurrentLanguageCode), CreatedAt = purchase.UpdatedAt.HasValue ? purchase.UpdatedAt.Value : DateTime.MinValue, DueDate = purchase.UpdatedAt.HasValue ? purchase.UpdatedAt.Value : DateTime.MinValue, Item = purchase.GetItemName(entities), Status = purchaseStatuses.Single(x=>x.StatusCode.ToLower() == purchase.PurchaseStatusCode.ToLower()).GetLocalizedField("purchaseStatus"), Amount = purchase.GetFormattedPrice(), AmountNis = purchase.GetFormattedPriceNis(), AmountClassName = "azure", Remarks = purchase.GetLocalizedField("purchaseRemarks"), Lesson = GetLessonPurchaseView(purchase.ClipKey, purchases, nisCurrencySymbol, clipStatuses, purchaseStatuses, purchase.Event.ObjectId), Bundle = GetBundlePurchaseView(purchase.BundleKey, purchases, nisCurrencySymbol, clipStatuses, purchaseStatuses,purchase.Event.ObjectId), EventData = GetEventData(purchase.Event), Action = action }); } return accountStatementVm.ToArray(); }