public static string GetWorldId(HttpContextBase httpContext, HttpSessionStateBase session) { using (var reposotory = RepositoryFactory.GetInstance(session)) { var contentTypeRetriver = new WorldContentTypeRetriver(httpContext, reposotory); var worldId = contentTypeRetriver.GetWorldContentTypeId(); if (string.IsNullOrEmpty(worldId)) { httpContext.Response.Redirect("/"); } return worldId; } }
/// <summary> /// /// </summary> /// <param name="cartItemModel"></param> /// <param name="contentItem"></param> /// <param name="repository"></param> /// <param name="purchase"></param> /// <param name="existingPurchase"></param> /// <returns>update shopping cart</returns> private Purchase AddToCartInternal(ShoppoingCartItemModel cartItemModel, ParseObject contentItem, ParseRepository repository, Purchase existingPurchase, string previosDemoId) { var currentUser = Session.GetLoggedInUser(); var isLessson = cartItemModel.ContentItemType.Contains("lesson"); var isDemo = cartItemModel.ContentItemType.Contains("demo"); var includingSupport = cartItemModel.ContentItemType.Contains("support"); var defaultCurrency = repository.FindDefaultCurrency(); var worldRetriever = new WorldContentTypeRetriver(HttpContext, repository); CurrencyDto contentItemCurrency = null; CurrencyDto userCurrency = null; userCurrency = Task.Run(() => currentUser.GetPointerObject<Currency>("currency")).Result.ConvertToCurrencyDto(); float contentItemPrice; float contentItemSupportPrice; string purchaseStatusCode; var clips = new List<string>(); string clipId = "1"; string bundleId = ""; string objectId = ""; if (isLessson) { var clip = (Clip)contentItem; var isAdminOrCurrenctUser = clip.Teacher.ObjectId == currentUser.ObjectId || Session.GetLoggedInUserRoleName() == RoleNames.ADMINISTRATORS; clipId = clip.ObjectId; contentItemCurrency = clip.Currency.ConvertToCurrencyDto(); contentItemPrice = clip.Price; contentItemSupportPrice = includingSupport ? clip.SupportPrice : 0; purchaseStatusCode = isAdminOrCurrenctUser ? PurchaseStatusCodes.LessonIsActive : PurchaseStatusCodes.LessonIsInBaskert; } else { var bundle = (Bundle)contentItem; bundleId = bundle.ObjectId; contentItemCurrency = bundle.Currency.ConvertToCurrencyDto(); contentItemPrice = bundle.Price; contentItemSupportPrice = includingSupport ? bundle.SupportPrice : 0; purchaseStatusCode = PurchaseStatusCodes.PackageIsInBasket; clips = bundle.ClipsInBundle.Select(x => x.ObjectId).ToList(); } PurchaseDto purchaseDto = null; if (isDemo) { purchaseDto = new PurchaseDto { ObjectId = existingPurchase != null ? existingPurchase.ObjectId : null, ClipId = clipId, BundleId = bundleId, ClipKind = ClipPurchaseTypes.Demo, PurchaseStatusCode = PurchaseStatusCodes.DemoOrdered, PurchaseStatusDate = DateTime.Now, UserKey = currentUser.ObjectId, WorldId = worldRetriever.GetWorldContentTypeId() }; } else { if (!string.IsNullOrEmpty(previosDemoId)) { objectId = previosDemoId; } if (existingPurchase != null) { objectId = existingPurchase.ObjectId; } purchaseDto = new PurchaseDto { ObjectId = objectId, ClipId = clipId, BundleId = bundleId, ClipKind = isLessson ? ClipPurchaseTypes.Lesson : ClipPurchaseTypes.Bundle, UserCurrencyId = currentUser.GetPointerObjectId("currency"), Price = CurrencyConverter.Convert(contentItemPrice, contentItemCurrency, userCurrency), PriceNIS = CurrencyConverter.Convert(contentItemPrice, contentItemCurrency, defaultCurrency), OriginalItemPrice = contentItemPrice, OriginalItemCurrency = contentItemCurrency.ObjectId, PurchaseStatusCode = purchaseStatusCode, PurchaseStatusDate = DateTime.Now, SupportPrice = CurrencyConverter.Convert(contentItemSupportPrice, contentItemCurrency, userCurrency), SupportPriceNIS = CurrencyConverter.Convert(contentItemSupportPrice, contentItemCurrency, defaultCurrency), OriginalSupportPrice = contentItemSupportPrice, UserKey = currentUser.ObjectId, WorldId = worldRetriever.GetWorldContentTypeId(), ClipIds = clips.ToArray(), IncludingSupport = includingSupport }; } // repository.AddPurchase(purchaseDto); return purchaseDto.ConvertToDomain(); }
private CheckoutViewModel GetCheckoutViewModel(Purchase[] userPurchases, IMyMentorRepository repository) { var loggedInUser = Session.GetLoggedInUser(); var model = new CheckoutViewModel(); CurrencyDto currencyDto = Task.Run(() => loggedInUser.GetPointerObject<BL.Models.Currency>("currency")).Result.ConvertToCurrencyDto(); model.UserCurrency = currencyDto; var worldRetriver = new WorldContentTypeRetriver(HttpContext, repository); var world = worldRetriver.GetWorldContentTypeId(); string issuedFor = loggedInUser.ObjectId; var userCoupons = repository.FindCoupon(issuedFor, world).ToArray(); UpdateDuplicateRecords(ref userCoupons, ref userPurchases); SetPurchases(model, userPurchases, userCoupons, repository, currencyDto); SetCoupons(userCoupons, userPurchases, currencyDto, repository, model); SetTotals(model, repository, currencyDto); model.PurchaseFor = loggedInUser.Username; return model; }
public async Task<ActionResult> AddCouponFromContentItem(string id) { using (var repository = RepositoryFactory.GetInstance(Session)) { var worldRetriver = new WorldContentTypeRetriver(HttpContext, repository); var world = worldRetriver.GetWorldContentTypeId(); var purchase = await repository.FindPurchase(id); var issuedFor = Session.GetLoggedInUser().ObjectId; var userCoupons = repository.FindCoupon(issuedFor, world).Where(x => x.State == CouponStates.UnUsed.ToString()).ToArray(); Coupon couponForItem = null; if (purchase.ClipKey != null) { couponForItem = userCoupons.SingleOrDefault(x => x.Clip != null && x.Clip.ObjectId == purchase.ClipKey.ObjectId); } if (purchase.BundleKey != null) { couponForItem = userCoupons.SingleOrDefault(x => x.Bundle != null && x.Bundle.ObjectId == purchase.BundleKey.ObjectId); } if (couponForItem != null) { return await AddCoupon(couponForItem.ObjectId); } } return RedirectToAction("Index"); }
public async Task<ActionResult> AddUpdateBundleData(BundleUpdateViewModel model) { var repository = RepositoryFactory.GetInstance(Session); try { var contentTypeRetriver = new WorldContentTypeRetriver(HttpContext,repository); var worldContentTypeId = contentTypeRetriver.GetWorldContentTypeId(); var isNewBundle = model.ObjectId == null; var clipsIds = model.BundleClips.Select(o => o.Id).ToArray(); if (!clipsIds.Any()) { return Json(new ServiceObjectResponse { Status = ServiceObjectResponse.Failure, StatusReason = MyMentorResources.updateBundleNoLessonsSelected }); } ValidateBundlePrice(model); var teacher = await repository.FindUserByName(model.TeacherName); model.TeacherId = teacher.ObjectId; new NameManager(repository, Session).SetPortalBundleName(_worldId, model, teacher.ConvertToParseUserDto()); if (isNewBundle) { model.ObjectId = await AddBundle(model, worldContentTypeId); } else { await UpdateBundle(model); } lock (locker) { Task.Run(() => repository.UpdateClipsInBundle(model.GetBundle(), clipsIds)).Wait(); var context = System.Web.HttpContext.Current; new WebCacheProvider(context).ClearCachedItem(CacheKeys.ClipToBundle); } return Json(new ServiceObjectResponse { Status = ServiceObjectResponse.Success, }); } catch (Exception ex) { if (ex is DuplicateNameException || ex is StatusChangeException || ex is BundlePriceException) { return Json(new ServiceObjectResponse { Status = ServiceObjectResponse.Failure, StatusReason = ex.Message }); } mLogger.Log(LogLevel.Error, ex); return Json(new ServiceObjectResponse { Status = ServiceObjectResponse.Failure, StatusReason = MyMentorResources.errCanotAddBundleGeneral }); } finally { repository.Dispose(); } }