Exemple #1
0
 public virtual async Task <string> GenerateLicenseForProductAsync(TblInvoices invoice, TblUsers user,
                                                                   TblProducts product, int quantity)
 {
     return("Test product license for : " + product.GetLocalized(p => p.Title));
 }
Exemple #2
0
        public virtual ProductModel PrepareProductModel(TblProducts product, TblUsers currentUser, UrlHelper url)
        {
            var result = product.Adapt <TblProducts, ProductModel>();

            result.Title           = product.GetLocalized(p => p.Title);
            result.PageTitle       = product.GetLocalized(p => p.PageTitle);
            result.MetaDescription = product.GetLocalized(p => p.MetaDescription);
            result.MetaKeyWords    = product.GetLocalized(p => p.MetaKeyWords);

            var downloadsCount = _productService.GetNumberOfDownloads(product.Id);
            var likesCount     = _userLikesService.GetNumberOfLikes(product.Id);

            result.NumberOfDownloads = downloadsCount;
            result.NumberOfLikes     = likesCount;
            result.LastUpdate        = product.LastUpDate ?? product.PublishDate;
            result.Categories        = product.Categories
                                       .Select(p => new PostCategoriesModel()
            {
                Id           = p.Id,
                CategoryName = p.GetLocalized(x => x.CategoryName),
                Slug         = p.Slug,
                CategoryUrl  = url.Action("FilterByCategory", "Product", new { slug = p.Slug })
            })
                                       .ToList();
            result.TagsList = product.Tags
                              .Select(p => new Tuple <int, string>(p.Id, p.GetLocalized(x => x.Tag)))
                              .ToList();

            //user purchased current product ?
            var purchasedProducts = _usersService.GetUserPurchasedProducts(currentUser?.Id, product.Id);

            if (purchasedProducts.Any(p => p.PurchaseExpiration > DateTime.Now))
            {
                result.CurrentUserHasAlreadyPurchasedThisProduct = true;
            }

            result.PriceForCurrentUser = _productService.CalculateProductPriceForUser(product, currentUser);
            result.CurrentUserGroup    = currentUser?.UserGroup;

            result.LikeWishlistButtonsModel = new LikeWishlistButtonsModel()
            {
                PostId = product.Id,
                AlreadyAddedToWishlist = _userWishlistService.UserAddedThisPostToWishlist(product.Id, currentUser?.Id),
                AlreadyLiked           = _userLikesService.UserLikedThisPost(product.Id, currentUser?.Id)
            };

            result.DownloadModel = PrepareProductDownloadPurchaseButtonModel(product, currentUser);

            result.Images.Clear();
            foreach (var img in product.Images.OrderBy(p => p.DisplayOrder))
            {
                result.Images.Add(new PostImagesModel()
                {
                    Title        = img.GetLocalized(p => p.Title) ?? result.PageTitle,
                    Alt          = img.GetLocalized(p => p.Alt) ?? result.Title,
                    ImageUrl     = img.GetLocalized(p => p.ImageUrl),
                    DisplayOrder = img.DisplayOrder
                });
            }

            result.Descriptions.Clear();
            foreach (var desc in product.Descriptions.OrderBy(p => p.DisplayOrder))
            {
                var description = desc.GetLocalized(x => x.HtmlDescription);
                result.Descriptions.Add(new PostDescriptionsModel()
                {
                    Description = description,
                    Title       = desc.GetLocalized(x => x.Title),
                    IsRtl       = description.StripHtml().IsRtlLanguage()
                });
            }

            result.Attributes.Clear();
            foreach (var attr in product.Attributes)
            {
                result.Attributes.Add(new PostAttributesModel()
                {
                    Type  = attr.PostAttribute.AttributeType,
                    Name  = attr.PostAttribute.GetLocalized(p => p.Name),
                    Value = attr.PostAttribute.AttributeType == PostAttributeType.Option
                        ? attr.AttributeOption.GetLocalized(p => p.Name)
                        : attr.GetLocalized(p => p.Value),
                    DisplayOrder = attr.DisplayOrder
                });
            }

            result.CheckoutAttributes.Clear();
            foreach (var attr in product.CheckoutAttributes)
            {
                result.CheckoutAttributes.Add(new TblProductCheckoutAttributes()
                {
                    Id                        = attr.Id,
                    Name                      = attr.GetLocalized(p => p.Name),
                    Description               = attr.GetLocalized(p => p.Description),
                    AttributeType             = attr.AttributeType,
                    DisplayOrder              = attr.DisplayOrder,
                    ProductId                 = attr.ProductId,
                    Required                  = attr.Required,
                    MaxRange                  = attr.MaxRange,
                    MinRange                  = attr.MinRange,
                    LicenseGeneratorServiceId = attr.LicenseGeneratorServiceId,
                    UnitPrice                 = attr.UnitPrice,
                    Options                   = attr.Options.Select(p => p.Adapt <TblProductCheckoutAttributeOptions>()).ToList()
                });
            }

            var protocol = _httpContext?.Request.Url?.Scheme ?? "http";

            result.PostUrl = new Uri(url.Action("Index", "Product", new { slug = product.Slug }, protocol: protocol) ?? "").ToString();

            return(result);
        }