Exemplo n.º 1
0
        public IActionResult Edit(ProductViewModel model)
        {
            if (ModelState.IsValid)
            {
                string uniqueFileName = new FileUpload().UploadedFile(model.ProductImages.FirstOrDefault(), _webHostEnvironment);


                if (model.Id == 0)
                {
                    Product product = new Product
                    {
                        Name        = model.Name,
                        CategoryId  = model.SubSubCategoryId,
                        Description = model.Description,
                        Discount    = model.Discount,
                        Stock       = model.Stock,
                        Price       = model.Price,
                        BrandId     = _brandService.Insert(new Brand {
                            Name = model.BrandName
                        }).Id
                    };
                    var          newProduct = _productService.Insert(product);
                    ProductImage image      = new ProductImage
                    {
                        Path      = uniqueFileName,
                        ProductId = newProduct.Id
                    };
                    _productImageService.Insert(image);
                }
                else
                {
                    var product = _productService.Get(model.Id);
                    product.Name        = model.Name;
                    product.CategoryId  = model.SubSubCategoryId;
                    product.Description = model.Description;
                    product.Discount    = model.Discount;
                    product.Stock       = model.Stock;
                    product.Price       = model.Price;
                    product.BrandId     = _brandService.Insert(new Brand {
                        Name = model.BrandName
                    }).Id;
                    ProductImage image = new ProductImage
                    {
                        Path      = uniqueFileName,
                        ProductId = model.Id
                    };
                    _productImageService.Insert(image);
                    _productService.Update(product);
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(model));
        }
Exemplo n.º 2
0
        public virtual async Task <ActionResult> AddPictures(AddProductPicturesViewModel viewModel)
        {
            _productImageService.Insert(viewModel);
            await _unitOfWork.SaveChangesAsync();

            return(RedirectToAction(MVC.Admin.Product.ActionNames.Index, MVC.Admin.Product.Name));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Add many image in product image table
        /// </summary>
        /// <param name="httpPostedFileBases">list image post</param>
        /// <param name="ProVaId">Product variation id</param>
        public void AddImageOnProductImageTable(IEnumerable <HttpPostedFileBase> httpPostedFileBases, Guid ProVaId)
        {
            string local = Server.MapPath("~/Content/img/product-men");

            foreach (var file in httpPostedFileBases)
            {
                var model = new ProductImage
                {
                    Id                  = Guid.NewGuid(),
                    ImagePath           = _productImageService.UpFile(file, local),
                    ProductVariation_Id = ProVaId,
                    CreatedDate         = DateTime.Now,
                    IsActive            = true
                };
                _productImageService.Insert(model);
            }
        }
Exemplo n.º 4
0
        public JsonResult Edit(ProductImage model)
        {
            try
            {
                if (model.ProductImageId > 0)
                {
                    var entity = _ProductImageService.GetById(model.ProductImageId);

                    //修改
                    entity.BaseImageId = model.BaseImageId;
                    entity.Type        = model.Type;

                    model.EditPersonId = Loginer.AccountId;
                    model.EditTime     = DateTime.Now;
                    _ProductImageService.Update(model);
                    return(Json(new { Status = Successed.Ok }, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    //if (_ProductImageService.CheckBusinessName(model.Name) > 0)
                    //    return Json(new { Status = Successed.Repeat }, JsonRequestBehavior.AllowGet);
                    //添加
                    model.Status         = (int)EnabledEnum.效;
                    model.IsDelete       = (int)IsDeleteEnum.效;
                    model.CreatePersonId = Loginer.AccountId;
                    model.CreateTime     = DateTime.Now;
                    model.EditPersonId   = Loginer.AccountId;
                    model.EditTime       = DateTime.Now;
                    model = _ProductImageService.Insert(model);
                    if (model.ProductImageId > 0)
                    {
                        return(Json(new { Status = Successed.Ok }, JsonRequestBehavior.AllowGet));
                    }
                    else
                    {
                        return(Json(new { Status = Successed.Error }, JsonRequestBehavior.AllowGet));
                    }
                }
            }
            catch (Exception ex)
            {
                return(Json(new { Status = Successed.Error }, JsonRequestBehavior.AllowGet));
            }
        }