public IActionResult Edit(Guid?id) { if (id == null) { return(NotFound()); } var categories = this.dbContext.Categories.ToList(); var product = this.dbContext.Products.FirstOrDefault(m => m.Id == id); if (product == null) { return(NotFound()); } var model = new ProductEditVm() { Id = product.Id, Name = product.Name, Image = product.Image, PriceGoods = product.PriceGoods, Discription = product.Discription, DiscriptionFull = product.DiscriptionFull, Number = product.Number, CategoryName = product.Category.Name, Categories = categories.Select(cat => new SelectListItem() { Value = cat.Id.ToString(), Text = cat.Name }).ToList() }; return(View(model)); }
public IActionResult Edit(ProductEditVm model) { if (ModelState.IsValid) { Product product = _productRepository.GetProduct(model.Id); product.Name = model.Name; product.Price = model.Price; product.ShortDescription = model.ShortDescription; product.LongDescription = model.LongDescription; if (model.Photo != null) { if (model.ExistingPhotoPath != null) { string filePath = Path.Combine(_webHostEnvironment.WebRootPath, "images", model.ExistingPhotoPath); System.IO.File.Delete(filePath); } product.PhotoPath = ProcessUploadedFile(model); } var updatedProduct = _productRepository.Update(product); return(RedirectToAction("Index")); } return(View(model)); }
public IActionResult Edit(int id) { NorthwndContext ctx = new NorthwndContext(); ProductEditVm vm = new ProductEditVm(); vm.ProducttoEdit = ctx.Products.SingleOrDefault(prd => prd.ProductID == id); vm.Categories = ctx.Categories.Select(cat => new SelectListItem() { Text = cat.CategoryName, Value = cat.CategoryID.ToString(), Selected = cat.CategoryID == vm.ProducttoEdit.CategoryId }).ToList(); vm.Categories.Insert(0, new SelectListItem() { Text = "Seçiniz...", Value = "-1" }); vm.Suppliers = ctx.Suppliers.Select(sup => new SelectListItem() { Text = sup.CompanyName, Value = sup.SupplierID.ToString(), Selected = sup.SupplierID == vm.ProducttoEdit.SupplierID }).ToList(); vm.Suppliers.Insert(0, new SelectListItem() { Text = "Seçiniz...", Value = "-1" }); return(View(vm)); }
public IActionResult Edit(ProductEditVm model) { if (HttpContext.Session.GetInt32("LoginLevel") != 2) { ViewBag.checkLogin = 0; return(View("../Home/AddCart")); } if (ModelState.IsValid) { var products = _service.GetAll(); foreach (ProductDto item in products) { if (model.Name.ToLower().Equals(item.Name.ToLower()) && model.ID != item.ID) { var x = _productService.GetList(); ViewBag.BrandList = x.BrandList; ViewBag.CategoryList = x.CategoryList; ViewBag.StatusList = x.StatusList; ViewBag.ProductEditUnchangedErrorMessage = "Error"; return(View(model)); } } ProductDto productDto = _service.GetProduct(model.ID); SaveProductDto saveProductDto = _mapper.Map <ProductDto, SaveProductDto>(productDto); saveProductDto.Name = model.Name; saveProductDto.Price = model.Price; saveProductDto.Sale = model.Sale; saveProductDto.Amount = model.Amount; saveProductDto.Hot = model.Hot; saveProductDto.BrandID = model.BrandID; saveProductDto.CategoryID = model.CategoryID; saveProductDto.Content = model.Content; saveProductDto.Status = model.Status; if (model.Image != null) { if (model.ExistImagePath != null) { string filePath = Path.Combine(_hostingEnvironment.WebRootPath, "images", model.ExistImagePath); System.IO.File.Delete(filePath); } saveProductDto.ImagePath = ProcessUploadedFile(model); } _service.Update(saveProductDto); return(View("Detail", _service.GetProduct(saveProductDto.ID))); } return(View()); }
public ViewResult Edit(int id) { Product product = _productRepository.GetProduct(id); ProductEditVm productEditVm = new ProductEditVm { Id = product.Id, Name = product.Name, Price = product.Price, ShortDescription = product.ShortDescription, LongDescription = product.LongDescription, ExistingPhotoPath = product.PhotoPath }; return(View(productEditVm)); }
public async Task <IActionResult> EditSubmit(ProductEditVm model, IFormFile Image) { var upProduct = this.dbContext.Products .FirstOrDefault(c => c.Id == model.Id); if (upProduct == null) { return(NotFound()); } // if (ModelState.IsValid) { if (Image != null) { string name = Image.FileName; string path = $"/files/{name}"; string serverPath = $"{this.environment.WebRootPath}{path}"; FileStream fs = new FileStream(serverPath, FileMode.Create, FileAccess.Write); await Image.CopyToAsync(fs); fs.Close(); upProduct.Image = path; } } upProduct.Name = model.Name; if (model.CategoryId != Guid.Empty) { upProduct.CategoryId = model.CategoryId; } upProduct.Discription = model.Discription; upProduct.DiscriptionFull = model.DiscriptionFull; upProduct.PriceGoods = model.PriceGoods; this.dbContext.Products.Update(upProduct); this.dbContext.SaveChanges(); return(RedirectToAction(nameof(ProductListForAdmin), new { categoryId = upProduct.CategoryId })); }
public IActionResult Edit(int?id) { if (HttpContext.Session.GetInt32("LoginLevel") != 2) { ViewBag.checkLogin = 0; return(View("../Home/AddCart")); } if (id == null) { return(NotFound()); } var product = _service.GetProduct(id.Value); if (product == null) { return(NotFound()); } ProductEditVm ProductEditVM = new ProductEditVm() { ID = product.ID, // hidden ExistImagePath = product.ImagePath, // hidden Name = product.Name, Amount = product.Amount, Price = product.Price, Sale = product.Sale, Hot = product.Hot, Content = product.Content, BrandID = product.BrandID, CategoryID = product.CategoryID, Status = product.Status, }; var x = _productService.GetList(); ViewBag.BrandList = x.BrandList; ViewBag.CategoryList = x.CategoryList; ViewBag.StatusList = x.StatusList; return(View(ProductEditVM)); }