Ejemplo n.º 1
0
        public ActionResult EditProduct(Guid id)
        {
            var product = _productSevice.Get(id);

            if (product == null)
            {
                return(RedirectToAction("index"));
            }

            var cats = _categoryService.GetAllowedEditCategories(UsersRole, true);

            var model = new AdminEditProductViewModel
            {
                ProductClass = product.ProductClassId,
                Id           = product.Id,
                Category     = product.Category_Id,
                Image        = product.Image,
                IsLocked     = product.IsLocked,
                Name         = product.Name,
                Categories   = _categoryService.GetBaseSelectListCategories(cats),
                AllAttribute = new List <AdminAttributeViewModel>()
            };


            ProductPost post;

            if (product.ProductPost_Id != null)
            {
                post          = _productPostSevice.Get((Guid)product.ProductPost_Id);
                model.Content = post.PostContent;
            }

            var attr = _productSevice.GetListProductClassAttributeForProductClassId(product.ProductClassId);

            foreach (var it in attr)
            {
                var a = _productSevice.GetAttribute(it.ProductAttributeId);

                var m = new AdminAttributeViewModel
                {
                    AttriId   = a.Id,
                    Name      = a.LangName,
                    ValueType = a.ValueType,
                    IsNull    = a.IsNull
                };


                var p = _productSevice.GetAttributeValue(product.Id, a.Id);
                if (p != null)
                {
                    m.Id    = p.Id;
                    m.Value = p.Value;
                }
                model.AllAttribute.Add(m);
            }

            return(View(model));
        }
Ejemplo n.º 2
0
        public ActionResult EditProduct(Guid id)
        {
            var product = _productSevice.Get(id);

            if (product == null)
            {
                return(RedirectToAction("index"));
            }

            var cats = _categoryService.GetAllowedEditCategories(UsersRole, true);

            var model = new AdminEditProductViewModel
            {
                ProductClass = product.ProductClassId,
                Id           = product.Id,
                Category     = product.Category_Id,
                Image        = product.Image,
                IsLocked     = product.IsLocked,
                Name         = product.Name,
                Categories   = _categoryService.GetBaseSelectListCategories(cats),
                AllAttribute = new List <AdminAttributeViewModel>()
            };


            ProductPost post;

            if (product.ProductPost_Id != null)
            {
                post          = _productPostSevice.Get((Guid)product.ProductPost_Id);
                model.Content = post.PostContent;
            }

            var attr = _productSevice.GetListProductClassAttributeForProductClassId(product.ProductClassId);

            foreach (var it in attr)
            {
                var a = _productSevice.GetAttribute(it.ProductAttributeId);

                var m = new AdminAttributeViewModel
                {
                    AttriId   = a.Id,
                    Name      = a.LangName,
                    ValueType = a.ValueType,
                    IsNull    = a.IsNull
                };

                var p = _productSevice.GetAttributeValue(product.Id, a.Id);
                if (p != null)
                {
                    m.Id    = p.Id;
                    m.Value = p.Value;
                }

                if (!a.ValueOption.IsNullEmpty() && a.ValueType == 2)
                {
                    dynamic json = JsonConvert.DeserializeObject(a.ValueOption);
                    if (json != null)
                    {
                        m.ValueOptions = new List <string>();
                        foreach (var itt in json)
                        {
                            m.ValueOptions.Add((string)itt);
                        }
                    }
                }

                //if (!a.ValueFindter.IsNullEmpty())
                //{
                //	dynamic json = JsonConvert.DeserializeObject(a.ValueFindter);
                //	if (json != null)
                //	{
                //		m.FindterNums = new List<AdminAttributeNumberFindter>();
                //		foreach (dynamic itt in json)
                //		{
                //			m.FindterNums.Add(new AdminAttributeNumberFindter { Name = (string)itt.Name });
                //		}
                //	}
                //}

                model.AllAttribute.Add(m);
            }

            return(View(model));
        }
Ejemplo n.º 3
0
        public ActionResult CreateProduct(Guid g)
        {
            var cats = _categoryService.GetAllowedEditCategories(UsersRole, true);

            var model = new AdminEditProductViewModel
            {
                ProductClass = g,
                Categories   = _categoryService.GetBaseSelectListCategories(cats),
                AllAttribute = new List <AdminAttributeViewModel>()
            };

            var attr = _productSevice.GetListProductClassAttributeForProductClassId(g);

            if (attr != null)
            {
                foreach (var it in attr)
                {
                    var a    = _productSevice.GetAttribute(it.ProductAttributeId);
                    var aavm = new AdminAttributeViewModel
                    {
                        AttriId       = a.Id,
                        Name          = a.LangName,
                        ValueType     = a.ValueType,
                        IsNull        = a.IsNull,
                        IsShowFindter = a.IsShowFindter
                    };

                    model.AllAttribute.Add(aavm);


                    if (!a.ValueOption.IsNullEmpty() && a.ValueType == 2)
                    {
                        dynamic json = JsonConvert.DeserializeObject(a.ValueOption);
                        if (json != null)
                        {
                            aavm.ValueOptions = new List <string>();
                            foreach (var itt in json)
                            {
                                aavm.ValueOptions.Add((string)itt);
                            }
                        }
                    }

                    //if (!a.ValueFindter.IsNullEmpty())
                    //{
                    //	dynamic json = JsonConvert.DeserializeObject(a.ValueFindter);
                    //	if (json != null)
                    //	{
                    //		aavm.FindterNums = new List<AdminAttributeNumberFindter>();
                    //		foreach (dynamic itt in json)
                    //		{
                    //			aavm.FindterNums.Add(new AdminAttributeNumberFindter { Name = (string)itt.Name });
                    //		}
                    //	}
                    //}
                }
            }


            return(View(model));
        }