Exemple #1
0
 public void Setup()
 {
     _stubPurchaseStatusDto = new PurchaseStatusDto
     {
         Id   = Guid.NewGuid(),
         Name = "Ordered"
     };
     _stubPaymentInformationDto = new PaymentInformationDto
     {
         CardCVC    = "121",
         CardExpiry = new DateTime(),
         CardName   = "Oliver Test",
         CardNumber = "1234567890123456",
         ID         = Guid.NewGuid()
     };
     _stubPurchaseOrderDto = new PurchaseOrderDto
     {
         Address              = "Test Drive",
         ExternalID           = 1,
         ID                   = Guid.Parse("d61a78a9-b6ad-4430-91ea-0c8d5227b6aa"),
         IsDeleted            = false,
         PaymentInformation   = _stubPaymentInformationDto,
         PaymentInformationID = _stubPaymentInformationDto.ID,
         Postcode             = "T35T DR1",
         ProductID            = Guid.NewGuid(),
         ProductName          = "Testy",
         ProductPrice         = 10.50,
         PurchasedBy          = Guid.NewGuid(),
         PurchasedOn          = new DateTime(),
         PurchaseStatus       = _stubPurchaseStatusDto,
         Quantity             = 1,
         Source               = "Undercutters",
         StatusID             = _stubPurchaseStatusDto.Id
     };
     _stubOrderCreatedDto = new OrderCreatedDto
     {
         AccountName = "Testy1",
         CardNumber  = "10490249204920492049",
         Id          = 1,
         ProductEan  = "1 2 4 2 3",
         ProductId   = 1,
         ProductName = "Product1",
         PurchasedOn = new DateTime(),
         Quantity    = 5,
         Success     = true,
         TotalPrice  = 10
     };
     _mockLogger       = new Mock <ILogger <OrdersRepository> >();
     _ordersRepository = new OrdersRepository(GetInMemoryContextWithSeedData(), _mockLogger.Object);
 }
        private MyAccountPurchaseViewModel GetBundlePurchaseView(Bundle bundle, IEnumerable<Purchase> purchases, string nisCurrencySymbol, IEnumerable<ClipStatus> clipStatuses, PurchaseStatusDto[] purchaseStatuses, string evetId)
        {
            if (purchases == null || bundle == null)
            {
                return null;
            }
            var bundlePurchase = purchases.FirstOrDefault(x => x.BundleKey != null && x.BundleKey.ObjectId == bundle.ObjectId && x.Event.ObjectId == evetId);
            if (bundlePurchase == null) return null;            
            var clipStatus = clipStatuses.Single(x => x.ObjectId == bundle.Status.ObjectId);
            var purchaseStatus = purchaseStatuses.Single(x => x.StatusCode.ToLower() == bundlePurchase.PurchaseStatusCode.ToLower());
            var clipIds = (bundlePurchase["clipArray"] as List<object>).Select(x => ((ParseObject)x).ObjectId).ToArray();

            return new MyAccountPurchaseViewModel
            {
                Title = Language.CurrentLanguageCode == Cultures.EN_US ? bundle.BundleName_en_us : bundle.BundleName_he_il,
                ContentId = bundle.ObjectId,
                BundleLessons = string.Join(",", clipIds),
                TeacherUserName = bundlePurchase.BundleKey.Teacher.Username,
                TeacherName = bundlePurchase.BundleKey.Teacher.GetFullName(Language.CurrentLanguageCode),
                LessonStatus = Language.CurrentLanguageCode == Cultures.EN_US ? clipStatus.Status_en_us : clipStatus.Status_he_il,
                Price = string.Format("{0}{1} {2}{3}", bundlePurchase.OriginalItemCurrency.CurrencySymbol, bundlePurchase.OriginalItemPrice, nisCurrencySymbol, bundlePurchase.PriceNIS),
                SupportPrice = string.Format("{0}{1} {2}{3}", bundlePurchase.OriginalItemCurrency.CurrencySymbol, bundlePurchase.OriginalSupportPrice, nisCurrencySymbol, bundlePurchase.SupportPriceNIS),
                PurchaseStatus = Language.CurrentLanguageCode == Cultures.EN_US ? purchaseStatus.PurchaseStatus_en_us : purchaseStatus.PurchaseStatus_he_il,
                PurchaseStatusDate = bundlePurchase.PurchaseStatusDate.ToString("dd/MM/yyyy"),
                BuyerUserName = bundlePurchase.PurchasedBy.Username,
                BuyerName = bundlePurchase.PurchasedBy.GetFullName(Language.CurrentLanguageCode),
                RecieverUserName = bundlePurchase.UserKey.Username,
                RecieverName = bundlePurchase.UserKey.GetFullName(Language.CurrentLanguageCode),
                IncludingSupport = bundlePurchase.IncludingSupport ? MyMentorResources.includingSupport : MyMentorResources.notIncludingSupport,
                Event = bundlePurchase.Event.ObjectId,                
                CouponId = bundlePurchase.CouponKey != null ? bundlePurchase.CouponKey.ObjectId : string.Empty,
            };
        }
 private MyAccountPurchaseViewModel GetLessonPurchaseView(Clip clip, IEnumerable<Purchase> purchases, string nisCurrencySymbol, IEnumerable<ClipStatus> clipStatuses, PurchaseStatusDto[] purchaseStatuses, string evetId)
 {
     if (purchases == null || clip == null)
     {
         return null;
     }
     var clipPurchase = purchases.FirstOrDefault(x => x.ClipKey != null && x.ClipKey.ObjectId == clip.ObjectId && x.Event.ObjectId == evetId);
     if (clipPurchase == null) return null;
     var clipStatus = clipStatuses.Single(x => x.ObjectId == clip.Status.ObjectId);
     var purchaseStatus = purchaseStatuses.Single(x => x.StatusCode.ToLower() == clipPurchase.PurchaseStatusCode.ToLower());
     
     return new MyAccountPurchaseViewModel
     {
         Title = Language.CurrentLanguageCode == Cultures.EN_US ? clip.Name_en_us:clip.Name_he_il,
         ContentId = clip.ObjectId,
         TeacherUserName = clipPurchase.ClipKey.Teacher.Username,
         TeacherName = clipPurchase.ClipKey.Teacher.GetFullName(Language.CurrentLanguageCode),
         LessonStatus = Language.CurrentLanguageCode ==Cultures.EN_US?  clipStatus.Status_en_us : clipStatus.Status_he_il,
         Price = string.Format("{0}{1} {2}{3}", clipPurchase.OriginalItemCurrency.CurrencySymbol, clipPurchase.OriginalItemPrice, nisCurrencySymbol, clipPurchase.PriceNIS),
         SupportPrice = string.Format("{0}{1} {2}{3}", clipPurchase.OriginalItemCurrency.CurrencySymbol, clipPurchase.OriginalSupportPrice, nisCurrencySymbol, clipPurchase.SupportPriceNIS),
         PurchaseStatus =Language.CurrentLanguageCode ==Cultures.EN_US?  purchaseStatus.PurchaseStatus_en_us:purchaseStatus.PurchaseStatus_he_il,
         PurchaseStatusDate = clipPurchase.PurchaseStatusDate.ToString("dd/MM/yyyy"),
         BuyerUserName = clipPurchase.PurchasedBy != null ?clipPurchase.PurchasedBy.Username:string.Empty,
         BuyerName = clipPurchase.PurchasedBy != null ? clipPurchase.PurchasedBy.GetFullName(Language.CurrentLanguageCode):string.Empty,
         RecieverUserName = clipPurchase.UserKey.Username,
         RecieverName = clipPurchase.UserKey.GetFullName(Language.CurrentLanguageCode),
         IncludingSupport = clipPurchase.IncludingSupport ? MyMentorResources.includingSupport:MyMentorResources.notIncludingSupport,
         Event = clipPurchase.Event != null ?clipPurchase.Event.ObjectId:string.Empty,
         BundleId = clipPurchase.InBundle != null ? clipPurchase.InBundle.ObjectId : string.Empty,
         CouponId = clipPurchase.CouponKey != null ? clipPurchase.CouponKey.ObjectId : string.Empty,
         FirstDownloadDate =clipPurchase.LessonFirstDownloadDate!=DateTime.MinValue? clipPurchase.LessonFirstDownloadDate.ToString("dd/MM/yyyy"):string.Empty,
         DownloadCounter = clipPurchase.LessonDownloadCounter.ToString()
     };
 }
 private AccountStatementViewModel[] GetAccountStatements(
     IEnumerable<AccountStatement> accountStatements, EntityDto[] entities, 
     IEnumerable<EventTypeDto> eventTypes, IEnumerable<TransactionTypeDto> transactionTypes, 
     IEnumerable<CouponTypeDto> couponTypes, IEnumerable<SupportTypeDto> supportTypes, 
     IEnumerable<CouponStatusDto> couponStatuses, string nisCurrencySymbol, IEnumerable<Purchase> purchases, 
     IEnumerable<ClipStatus> clipStatuses, PurchaseStatusDto[] purchaseStatuses)
 {
     
     return accountStatements.Select(accountStatement =>
     {
         var eventTypeCode = accountStatement.GetPointerValue<string>("event", "eventType");
         var transactionTypeCode = accountStatement.GetPointerValue<string>("transactionType", "transactionCode");
         return new AccountStatementViewModel
         {
             Id = accountStatement.ObjectId,
             Type = entities.FindEntityName(EntityKeys.AccountStatement),
             UserName = accountStatement.User.GetFullName(Language.CurrentLanguageCode),
             TransActionDate = accountStatement.TransactionDate,
             DueDate = accountStatement.DueDate,
             Action = GetAccountStatementActionString(eventTypeCode, transactionTypeCode, eventTypes, transactionTypes),
             Item =GetAccountStatementItemString(accountStatement, entities),
             Status = string.Empty,
             Amount = accountStatement.GetFormattedAmount(),
             AmountNis = accountStatement.GetAmountNis(),
             Balance = accountStatement.GetFormattedBalance(),
             BalanceNis = accountStatement.BalanceNIS.ToCurrency(nisCurrencySymbol),
             HasCredit = accountStatement.Balance >= 0,
             ActionType = accountStatement.GetActionType(),
             Remarks = accountStatement.GetLocalizedField("accountStatementRemarks"),
             Coupon =GetCouponView(accountStatement.Coupon, couponTypes, supportTypes, couponStatuses, nisCurrencySymbol),
             Lesson = GetLessonPurchaseView(accountStatement.Lesson, purchases, nisCurrencySymbol, clipStatuses, purchaseStatuses, accountStatement.Event.ObjectId),
             Bundle = GetBundlePurchaseView(accountStatement.Bundle, purchases, nisCurrencySymbol, clipStatuses, purchaseStatuses, accountStatement.Event.ObjectId),
             EventData = GetEventData(accountStatement.Event),
             CreatedAt = accountStatement.CreatedAt.Value,
            
         };
     }).ToArray();
 }