コード例 #1
0
        //TODO Just like editing
        public ActionResult Sold(int id)
        {
            if (id <= 0)
            {
                return(NotFound());
            }
            else
            {
                Product model = _productRepository.GetProductById(id);

                EditProductVM edit = new EditProductVM
                {
                    Id            = model.Id,
                    ProductName   = model.ProductName,
                    Description   = model.Description,
                    Price         = model.Price,
                    Color         = model.Color,
                    Quantity      = model.Quantity,
                    NumberSold    = model.NumberSold,
                    Size          = model.Size,
                    ExistingImage = model.ImageUrl,
                    CategoryId    = model.CategoryId,
                    _Category     = model._Category,
                };

                ViewBag.CategoryId = new SelectList(_categoryRepository.AllCategories(), "Id", "Name", edit.CategoryId);
                return(View(edit));
            }
        }
コード例 #2
0
        public async Task <IActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var product = await _context.Products.FindAsync(id);

            if (product == null)
            {
                return(NotFound());
            }

            EditProductVM editProductVM = new EditProductVM {
                ProductId          = product.ProductId,
                ProductName        = product.ProductName,
                ProductDescription = product.ProductDescription,
                ProductArtNumber   = product.ProductArtNumber,
                ExistingPhoto      = product.ProductImage,
                IsFeatured         = product.IsFeatured,
                InStock            = product.InStock,
                CategoryId         = product.CategoryId
            };

            ViewData["CategoryId"] = new SelectList(_context.Categories, "CartegoryId", "Name", product.CategoryId);
            return(View(editProductVM));
        }
コード例 #3
0
        public async Task <ActionResult> EditProduct(EditProductVM productVM)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(Json(new { error = true, message = "model is not valid" }));
                }

                if (productVM == null)
                {
                    return(Json(new { error = true, message = "model is null" }));
                }
                var result = await _productService.UpdateAsync(_mapper.Map <ProductDto>(productVM))
                             .ConfigureAwait(false);

                if (!result)
                {
                    return(Json(new { error = true, message = "product is not modified" }));
                }

                return(Json(new
                {
                    error = false
                }));
            }
            catch (Exception ex)
            {
                _logger.LogError("EditProduct fail", ex);
                return(Json(new { error = true, message = $"{ex?.ToString()}" }));
            }
        }
コード例 #4
0
        // GET: Products/Edit/5
        public IActionResult Edit(Guid id)
        {
            if (id == null)
            {
                return(NotFound());
            }
            var product = _product.GetById(id);

            EditProductVM edit = new EditProductVM
            {
                Id            = product.ProductId,
                ProductName   = product.Name,
                Description   = product.LongDescription,
                Price         = product.Price,
                ExistingImage = product.ImageUrl,
                CategoryId    = product.CategoryId,
                Category      = product.Category,
                InStock       = product.InStock,
            };

            if (product == null)
            {
                return(NotFound());
            }
            ViewData["CategoryId"] = new SelectList(_category.AllCategories(), "CategoryId", "CategoryName", product.Category);
            return(View(edit));
        }
コード例 #5
0
        public OperationResult Edit(EditProductVM command)
        {
            OperationResult result = new OperationResult();

            if (_productRepository.IsExist(p => p.Name == command.Name && p.Id != command.Id))
            {
                return(result.Failed(ValidateMessage.IsDuplicatedName));
            }

            var product = _productRepository.GetProductWithCategoryBy(command.Id);

            if (product == null)
            {
                return(result.Failed(ValidateMessage.IsExist));
            }

            var slug         = command.Slug.Slugify();
            var categorySlug = _categoryRepository.GetCategorySlugBy(command.CategoryId);
            var folderName   = $"{categorySlug}//{slug}";

            var pictureName = Uploader.ImageUploader(command.Picture, folderName, product.Picture);

            product.Edit(command.Name, command.Code, command.ShortDescription,
                         command.Description, pictureName, command.PictureAlt,
                         command.PictureTitle, command.CategoryId, slug, command.Keywords,
                         command.MetaDescription);

            _productRepository.SaveChanges();

            return(result.Succeeded());
        }
コード例 #6
0
        public IActionResult OnPostEdit(EditProductVM command)
        {
            if (!ModelState.IsValid)
            {
                return(RedirectToPage("Index"));
            }
            var result = _productApplication.Edit(command);

            return(new JsonResult(result));
        }
コード例 #7
0
        public IActionResult Edit(EditProductVM model)
        {
            Product product = _context.Products.Find(model.ProductId);

            if (product == null)
            {
                return(NotFound());
            }
            if (ModelState.IsValid)
            {
                if (model.Photo != null)
                {
                    if (model.ExistingPhoto != null)
                    {
                        string filePath = Path.Combine(_hostingEnv.WebRootPath,
                                                       "img", model.ExistingPhoto);
                        System.IO.File.Delete(filePath);
                    }

                    string uniqueFileName = null;

                    if (model.Photo != null)
                    {
                        string uploadsFolder = Path.Combine(_hostingEnv.WebRootPath, "img");
                        uniqueFileName = Guid.NewGuid().ToString() + "_" + model.Photo.FileName;
                        string filePath = Path.Combine(uploadsFolder, uniqueFileName);
                        using (var fileStream = new FileStream(filePath, FileMode.Create))
                        {
                            model.Photo.CopyTo(fileStream);
                        }

                        product.ProductImage = uniqueFileName;
                    }
                }
                product.ProductName        = model.ProductName;
                product.ProductArtNumber   = model.ProductArtNumber;
                product.ProductDescription = model.ProductDescription;
                product.CategoryId         = model.CategoryId;
                product.Price      = model.Price;
                product.IsFeatured = model.IsFeatured;
                product.InStock    = model.InStock;

                ViewData["CategoryId"] = new SelectList(_context.Categories, "CartegoryId", "Name", model.CategoryId);


                _context.Products.Update(product);
                _context.SaveChanges();

                return(RedirectToAction("Index"));
            }
            ViewData["CategoryId"] = new SelectList(_context.Categories, "CartegoryId", "Name", model.CategoryId);
            return(View(model));
        }
コード例 #8
0
        public ActionResult Edit(int id)
        {
            EditProductVM productVM = this.service.GetEditProductVM(id);

            if (productVM == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            if (this.Request.IsAjaxRequest())
            {
                return(this.PartialView(productVM));
            }

            return(this.View(productVM));
        }
コード例 #9
0
        public IActionResult Edit(EditProductVM model)
        {
            if (ModelState.IsValid)
            {
                var entity = _productRepository.Get(model.Id);
                CheckIfNotNull(entity);

                entity = _mapper.Map(model, entity);
                _imageService.Upload(entity, model.Front, model.Back, EImageType.Product);
                _productRepository.Update(entity);
                _unitOfWork.Commit();

                return(RedirectToAction("Index"));
            }

            PrepareViewModel(model);
            return(View(model));
        }
コード例 #10
0
        public ActionResult Edit(EditProductVM model)
        {
            if (ModelState.IsValid)
            {
                Product product = new Product
                {
                    Id          = model.Id,
                    ProductName = model.ProductName,
                    Description = model.Description,
                    Price       = model.Price,
                    Color       = model.Color,
                    Quantity    = model.Quantity,
                    NumberSold  = model.NumberSold,
                    Size        = model.Size
                };


                if (model.Photo != null)
                {
                    if (model.ExistingImage != null)
                    {
                        string filep = Path.Combine(_environment.WebRootPath, "images/", model.ExistingImage);
                        System.IO.File.Delete(filep);
                    }
                    product.ImageUrl = FileCheck(model);
                }
                else
                {
                    product.ImageUrl = model.ExistingImage;
                }

                product.CategoryId = model.CategoryId;
                product._Category  = model._Category;

                _productRepository.Edit(product);
            }

            ViewBag.CategoryId = new SelectList(_categoryRepository.AllCategories(), "Id", "Name", model.CategoryId);

            return(RedirectToAction("ManageProduct"));
        }
        public ActionResult Edit(int id)
        {
            var pDetails = _repository.ProductDetails(id);
            var vm       = new EditProductVM();

            //Filling Required DropdownList's
            Populatelookups(vm);
            if (pDetails != null)
            {
                vm.ProductId     = pDetails.ProductId;
                vm.Name          = pDetails.Name;
                vm.Description   = pDetails.Description;
                vm.Quantity      = pDetails.Quantity;
                vm.Price         = pDetails.Price;
                vm.CategoryId    = pDetails.CategoryId;
                vm.SubCategoryId = pDetails.SubCategoryId;
                //This is Subcategory list form  pDetails which is got from pDetails
                vm.SubcategoryList = GetSubCategoryListByCategory(pDetails.CategoryId);
            }
            return(View(vm));
        }
        public ActionResult Edit(EditProductVM vm)
        {
            if (!ModelState.IsValid)
            {
                //Filling Required DropdownList's
                Populatelookups(vm);
                return(View(vm));
            }
            var product = new Product
            {
                Name          = vm.Name,
                AddDate       = vm.AddDate,
                Description   = vm.Description,
                Price         = vm.Price,
                Quantity      = vm.Quantity,
                CategoryId    = vm.CategoryId,
                SubCategoryId = vm.SubCategoryId,
                ModifyDate    = DateTime.Now
            };

            _repository.UpdateProduct(vm.ProductId, product);
            return(RedirectToAction("Index", "Product"));
        }
コード例 #13
0
        public ActionResult Sold(EditProductVM model, int Sold)
        {
            if (ModelState.IsValid)
            {
                Product product = new Product
                {
                    Id          = model.Id,
                    ProductName = model.ProductName,
                    Description = model.Description,
                    Price       = model.Price,
                    Color       = model.Color,
                    Quantity    = model.Quantity,
                    Size        = model.Size,
                    ImageUrl    = model.ExistingImage,
                    CategoryId  = model.CategoryId,
                    _Category   = model._Category,
                    NumberSold  = model.NumberSold + Sold
                };
                _productRepository.Edit(product);
            }

            return(RedirectToAction("ManageProduct"));
        }
コード例 #14
0
        public IActionResult Edit(Guid id, EditProductVM product)
        {
            if (ModelState.IsValid)
            {
                Product prod = new Product
                {
                    Name            = product.ProductName,
                    InStock         = product.InStock,
                    LongDescription = product.Description,
                    Price           = product.Price,
                };


                if (product.Photo != null)
                {
                    if (product.ExistingImage != null)
                    {
                        string filep = Path.Combine(_environment.WebRootPath, "images/", product.ExistingImage);
                        System.IO.File.Delete(filep);
                    }
                    prod.ImageUrl = FileCheck(product);
                }
                else
                {
                    prod.ImageUrl = product.ExistingImage;
                }

                prod.CategoryId = product.CategoryId;
                prod.Category   = product.Category;

                _product.UpDate(prod);

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CategoryId"] = new SelectList(_category.AllCategories(), "CategoryId", "CategoryId", product.CategoryId);
            return(View(product));
        }