Ejemplo n.º 1
0
        public virtual async Task <ActionResult> Edit(EditProductViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                _productService.Update(viewModel);
                if (viewModel.OldCategoryId != viewModel.CategoryId)
                {
                    _valueService.RemoveByProductId(viewModel.Id);
                    var attributes = _attributeService.GetAttributesByCategoryId(viewModel.CategoryId);
                    _valueService.AddCategoryAttributesToProduct(attributes, viewModel.Id);
                }

                await _unitOfWork.SaveChangesAsync();

                LuceneProducts.UpdateIndex(new ProductLuceneViewModel
                {
                    Name        = viewModel.Name,
                    Id          = viewModel.Id,
                    ImagePath   = viewModel.PrincipleImagePath,
                    Description = viewModel.Description
                });
                CacheManager.InvalidateChildActionsCache();
                return(RedirectToAction(MVC.Admin.Product.ActionNames.Index, MVC.Admin.Product.Name));
            }

            PopulateCategoriesDropDownList(viewModel.CategoryId);
            if (!ModelState.IsValidField("CategoryId"))
            {
                ModelState.AddModelError("", "گروه محصول را مشخص  کنید");
            }
            return(View(viewModel));
        }
Ejemplo n.º 2
0
        public virtual async Task <ActionResult> Delete(long?id)
        {
            if (id == null)
            {
                return(Content(null));
            }
            _productService.Delete(id.Value);
            await _unitOfWork.SaveChangesAsync();

            LuceneProducts.DeleteIndex(id.Value);
            CacheManager.InvalidateChildActionsCache();
            return(Content("ok"));
        }
Ejemplo n.º 3
0
        public virtual ActionResult GetRelatedProducts(long?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            var products = LuceneProducts.ShowMoreLikeThisPostItems(id.Value);

            if (products != null)
            {
                products = products.Where(a => a.Id != id.Value).ToList();
            }
            return(PartialView(MVC.Product.Views._RelatedProductsPartial, products));
        }
Ejemplo n.º 4
0
        public virtual async Task <ActionResult> Create(AddProductViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                var product = new Product
                {
                    Name = viewModel.Name,
                    ApplyCategoryDiscount = viewModel.ApplyCategoryDiscount,
                    CategoryId            = viewModel.CategoryId,
                    Deleted                  = viewModel.Deleted,
                    IsFreeShipping           = viewModel.IsFreeShipping,
                    Description              = viewModel.Description,
                    DiscountPercent          = viewModel.DiscountPercent,
                    MetaDescription          = viewModel.MetaDescription,
                    MetaKeyWords             = viewModel.MetaKeyWords,
                    Price                    = viewModel.Price,
                    NotificationStockMinimum = viewModel.NotificationStockMinimum,
                    PrincipleImagePath       = viewModel.PrincipleImagePath,
                    Ratio                    = viewModel.Ratio,
                    SellCount                = 0,
                    ViewCount                = 0,
                    Reserve                  = 0,
                    Stock                    = viewModel.Stock,
                    Type      = viewModel.Type,
                    Rate      = new Rate(),
                    AddedDate = DateTime.Now
                };
                _productService.Insert(product);
                var attributes = _attributeService.GetAttributesByCategoryId(viewModel.CategoryId);
                _valueService.AddCategoryAttributesToProduct(attributes, product.Id);
                await _unitOfWork.SaveChangesAsync();

                LuceneProducts.AddIndex(new ProductLuceneViewModel
                {
                    Name        = product.Name,
                    Id          = product.Id,
                    ImagePath   = product.PrincipleImagePath,
                    Description = product.Description
                });
                CacheManager.InvalidateChildActionsCache();
                return(RedirectToAction(MVC.Admin.Product.ActionNames.Create, MVC.Admin.Product.Name));
            }
            PopulateCategoriesDropDownList(viewModel.CategoryId);
            if (!ModelState.IsValidField("CategoryId"))
            {
                ModelState.AddModelError("", "گروه محصول را مشخص  کنید");
            }
            return(View(viewModel));
        }
        public virtual ActionResult AutoComplete(string q)
        {
            if (string.IsNullOrWhiteSpace(q))
            {
                Content(null);
            }

            var result = new StringBuilder();
            var items  = LuceneProducts.GetTermsScored(q);

            //foreach (var item in items)
            //{
            //    var postUrl = Url.Action(MVC.Product.ActionNames.Index, MVC.Product.Name, routeValues: new { area = "", id = item.Id, name = item.Name.GenerateSlug() }, protocol: "http");
            //    result.AppendLine(item.Name + "|" + postUrl);
            //}

            return(PartialView(MVC.Search.Views._SearchPartial, items));
        }