public virtual async Task <int> AddAsync(TblUserGroups record) { _dbContext.UserGroups.Add(record); await _dbContext.SaveChangesAsync(); QueryCacheManager.ExpireTag(CacheTags.UserGroup); _eventPublisher.EntityInserted(record); return(record.Id); }
public virtual async Task UpdateAsync(TblUserGroups record) { var oldRecord = await FindByIdAsync(record.Id); _dbContext.UserGroups.AddOrUpdate(record); await _dbContext.SaveChangesAsync(); QueryCacheManager.ExpireTag(CacheTags.UserGroup); _eventPublisher.EntityUpdated(record, oldRecord); }
public virtual async Task <UserGroupModel> PrepareUserGroupModelAsync(TblUserGroups userGroup) { UserGroupModel result; if (userGroup == null) { result = new UserGroupModel(); } else { result = userGroup.Adapt <UserGroupModel>(); await userGroup.LoadAllLocalizedStringsToModelAsync(result); } return(result); }
public virtual async Task UpgradeCustomerUserGroupAsync(string userId, TblUserGroups userGroup, DateTime?startDate = null) { if (startDate == null) { startDate = DateTime.Now; } var subscriptionExpireDate = startDate?.AddTimePeriodToDateTime(userGroup.SubscriptionExpirationPeriodType, userGroup.SubscriptionExpirationTime); await _dbContext.Users.Where(p => p.Id == userId).UpdateAsync(p => new TblUsers() { SubscriptionDate = startDate, SubscriptionExpireDate = subscriptionExpireDate, UserGroupId = userGroup.Id }); _eventPublisher.Publish(new CustomerUserGroupChangeEvent(userId, userGroup, startDate)); }
public virtual ProductDownloadModel PrepareProductDownloadPurchaseButtonModel(TblProducts product, TblUsers currentUser) { var productCheckoutAttributes = AsyncHelper .RunSync(() => _checkoutAttributesService.FindProductAttributesAsync(product.Id)).ToList(); TblUserGroups downloadLimitedToUserGroupRecord = null; if (product.DownloadLimitedToUserGroupId != null) { downloadLimitedToUserGroupRecord = AsyncHelper .RunSync(() => _userGroupsService.FindByIdAsync(product.DownloadLimitedToUserGroupId.Value)); } var result = new ProductDownloadModel { ProductId = product.Id, AlwaysShowDownloadButton = product.AlwaysShowDownloadButton, DownloadLimitedToUserGroup = downloadLimitedToUserGroupRecord, HigherUserGroupsCanDownload = product.HigherUserGroupsCanDownload, HasDownloadableFile = !string.IsNullOrWhiteSpace(product.FilesPath) || productCheckoutAttributes.Any(p => p.Options.Any(x => !string.IsNullOrWhiteSpace(x.FilesPath))), PriceForCurrentUser = _productService.CalculateProductPriceForUser(product, currentUser), DiscountForUserGroupsDescription = GenerateUserGroupDiscountsDescription(product, currentUser), DownloadBlockingReason = _productService.UserCanDownloadProduct(product, currentUser, false) }; result.CanDownloadByCurrentUser = result.DownloadBlockingReason.HasFlagFast(ProductService.UserCanDownloadProductResult.UserCanDownloadProduct); result.CurrentUserGroup = currentUser?.UserGroup; result.HasDemoVersion = !string.IsNullOrWhiteSpace(product.DemoFilesPath); //user purchased current product ? var purchasedProducts = _usersService.GetUserPurchasedProducts(currentUser?.Id, product.Id); if (purchasedProducts.Any(p => p.PurchaseExpiration > DateTime.Now)) { result.CurrentUserHasAlreadyPurchasedThisProduct = true; } //ShowUpgradeUserAccountBtn if (result.DownloadLimitedToUserGroup != null && (result.DownloadBlockingReason.HasFlagFast(ProductService.UserCanDownloadProductResult.UserMustSubscribeToAPlan) || result.DownloadBlockingReason.HasFlagFast(ProductService.UserCanDownloadProductResult.UserMustSubscribeToAPlanOrHigher))) { if (result.CurrentUserGroup == null) { //Current user don't subscribed to any plan result.ShowUpgradeUserAccountBtn = true; } else { if (result.DownloadBlockingReason.HasFlagFast(ProductService.UserCanDownloadProductResult.UserMustSubscribeToAPlan) && result.CurrentUserGroup.Id != result.DownloadLimitedToUserGroup.Id) { result.ShowUpgradeUserAccountBtn = true; } if (result.DownloadBlockingReason.HasFlagFast(ProductService.UserCanDownloadProductResult.UserMustSubscribeToAPlanOrHigher) && result.CurrentUserGroup.GroupPriority < result.DownloadLimitedToUserGroup.GroupPriority) { result.ShowUpgradeUserAccountBtn = true; } } } //ShowDownloadFullVersionBtn if (result.HasDownloadableFile) { if (result.AlwaysShowDownloadButton || result.DownloadBlockingReason.HasFlagFast(ProductService.UserCanDownloadProductResult.UserCanDownloadProduct)) { result.ShowDownloadFullVersionBtn = true; } if (result.DownloadBlockingReason.HasFlagFast(ProductService.UserCanDownloadProductResult.UserMustLoggedIn) || result.DownloadBlockingReason.HasFlagFast(ProductService.UserCanDownloadProductResult.UserDownloadLimitReached) || result.DownloadBlockingReason.HasFlagFast(ProductService.UserCanDownloadProductResult.UserGroupDownloadLimitReached)) { if (!(result.DownloadBlockingReason.HasFlagFast(ProductService.UserCanDownloadProductResult.UserMustSubscribeToAPlan) || result.DownloadBlockingReason.HasFlagFast(ProductService.UserCanDownloadProductResult.UserMustSubscribeToAPlanOrHigher) || result.DownloadBlockingReason.HasFlagFast(ProductService.UserCanDownloadProductResult.UserMustPurchaseTheProduct))) { result.ShowDownloadFullVersionBtn = true; } } } //ShowPurchaseBtn result.ShowPurchaseBtn = result.PriceForCurrentUser > 0 || !string.IsNullOrWhiteSpace(product.LicenseGeneratorServiceId) || productCheckoutAttributes.Any(p => (p.UnitPrice > 0 && p.AttributeType == ProductCheckoutAttributeType.NumberBox) || !string.IsNullOrWhiteSpace(p.LicenseGeneratorServiceId)) || productCheckoutAttributes.SelectMany(p => p.Options).Any(p => p.Price > 0 || !string.IsNullOrWhiteSpace(p.LicenseGeneratorServiceId)); //ShowDownloadDemoVersionBtn result.ShowDownloadDemoVersionBtn = result.HasDemoVersion; return(result); }
public CustomerUserGroupChangeEvent(string userId, TblUserGroups userGroup, DateTime?startDate) { UserId = userId; UserGroup = userGroup; StartDate = startDate; }