Exemplo n.º 1
0
        public Result <Product> UploadImage(ProductCrudViewModel model)
        {
            var result = new Result <Product>();

            try
            {
                var _saveData = new Product();
                _saveData = _productManager.GetById(model.Id);
                if (model.FileCollection != null && model.FileCollection.Count > 0)
                {
                    _saveData.Thumbnail = string.Format("{0}/{1}.{2}", _saveData.Id, _saveData.Alias, "png");
                    UploadFile.UploadProductImage(model.FileCollection, _saveData.Alias, _saveData.Id.ToString());
                }
                _productManager.Update(_saveData);
                _productManager.Save();
                return(result = new Result <Product>()
                {
                    StatusCode = 0,
                    Results = _saveData,
                });
            }
            catch (EntityException ex)
            {
                return(result);
            }
            catch (Exception ex)
            {
                return(result);
            }
        }
Exemplo n.º 2
0
        public Result <Product> Upload360(ProductCrudViewModel model)
        {
            var result = new Result <Product>();

            try
            {
                var _saveData = new Product();
                _saveData = _productManager.GetById(model.Id);
                if (model.File_360 != null && !string.IsNullOrEmpty(model.File_360.FileName))
                {
                    _saveData.Link = string.Format("{0}/{1}.{2}", _saveData.Id.ToString(), _saveData.Alias, "html");
                    UploadFile.UploadProduct360File(model.File_360, _saveData.Alias, _saveData.Id.ToString());
                }
                _productManager.Update(_saveData);
                _productManager.Save();
                return(result = new Result <Product>()
                {
                    StatusCode = 0,
                    Results = _saveData,
                });
            }
            catch (EntityException ex)
            {
                return(result);
            }
            catch (Exception ex)
            {
                return(result);
            }
        }
Exemplo n.º 3
0
        public Result <Product> UpdateProduct(ProductCrudViewModel model)
        {
            var result = new Result <Product>();

            try
            {
                var _saveData = new Product();
                _saveData                  = _productManager.GetById(model.Id);
                _saveData.Name             = model.Name;
                _saveData.CategoryId       = model.CategoryId;
                _saveData.ServiceId        = model.ServiceId;
                _saveData.Alias            = model.Name.GenerateFriendlyName();
                _saveData.Status           = model.Status;
                _saveData.ShortDescription = WebUtility.HtmlEncode(model.ShortDescription);
                _saveData.Description      = WebUtility.HtmlEncode(model.Description);
                _saveData.MetaKeyWord      = model.MetaKeyWord;
                _saveData.MetaDescription  = model.MetaDescription;
                _productManager.Update(_saveData);
                _productManager.Save();
                return(result = new Result <Product>()
                {
                    StatusCode = 0,
                    Results = _saveData,
                });
            }
            catch (EntityException ex)
            {
                return(result);
            }
            catch (Exception ex)
            {
                return(result);
            }
        }
Exemplo n.º 4
0
 public int CreateProduct(ProductCrudViewModel model)
 {
     try
     {
         var _saveData = new Product();
         _saveData.Name             = model.Name;
         _saveData.Alias            = model.Name.GenerateFriendlyName();
         _saveData.Status           = model.Status;
         _saveData.CategoryId       = model.CategoryId;
         _saveData.ServiceId        = model.ServiceId;
         _saveData.ShortDescription = WebUtility.HtmlEncode(model.ShortDescription);
         _saveData.Description      = WebUtility.HtmlEncode(model.Description);
         _saveData.MetaKeyWord      = model.MetaKeyWord;
         _saveData.MetaDescription  = model.MetaDescription;
         _productManager.Add(_saveData);
         _productManager.Save();
         return(_saveData.Id);
     }
     catch (EntityException ex)
     {
         return(0);
     }
     catch (Exception ex)
     {
         return(0);
     }
 }
Exemplo n.º 5
0
        public ActionResult Create()
        {
            var model = new ProductCrudViewModel();

            ViewBag.Title = "Thêm mới mẫu thiết kế";
            return(View("~/Areas/Admin/Views/Product/Crud.cshtml", model));
        }
Exemplo n.º 6
0
        public ActionResult Edit(int id)
        {
            var model = new ProductCrudViewModel();

            model         = _project_Service.Find(id);
            ViewBag.Title = "Cập nhật mẫu thiết kế";
            return(View("~/Areas/Admin/Views/Product/Crud.cshtml", model));
        }
Exemplo n.º 7
0
        // GET
        public async Task <IActionResult> Index()
        {
            var products = new ProductCrudViewModel
            {
                Products = await _context.Products.ToListAsync()
            };

            return(View(products));
        }
Exemplo n.º 8
0
        public ActionResult Save(ProductCrudViewModel model)
        {
            int id = 0;

            if (!string.IsNullOrEmpty(model.Id.ToString()) && model.Id > 0)
            {
                id = _project_Service.UpdateProduct(model).Results.Id;
            }
            else
            {
                id = _project_Service.CreateProduct(model);
            }
            return(RedirectToAction("Edit", new { id = id }));
        }
Exemplo n.º 9
0
        public ProductCrudViewModel Find(int id)
        {
            var _data = _productManager.GetById(id);
            var model = new ProductCrudViewModel();

            model.Id               = _data.Id;
            model.Name             = _data.Name;
            model.Alias            = _data.Alias;
            model.Status           = _data.Status;
            model.ShortDescription = _data.ShortDescription;
            model.Description      = _data.Description;
            model.Link             = Url.Product360Url(_data.Link);
            model.Thumbnail        = Url.ProductImgUrl(_data.Thumbnail);
            model.CategoryId       = _data.CategoryId;
            model.ListCategory     = this.GetCategorySelectList(_data.CategoryId);
            model.ServiceId        = _data.ServiceId;
            model.ListService      = this.GetServiceSelectList(_data.ServiceId);
            return(model);
        }