public IActionResult Edit(HamperEditViewModel VM) { if (ModelState.IsValid) { Hamper updatedHamper = new Hamper { HamperId = VM.HamperId, HamperName = VM.HamperName, Description = VM.Description, Products = VM.Products, Supplier = VM.Supplier, Price = VM.Price, ImageUrl = VM.ImageUrl, CategoryId = VM.CategoryId, InUse = true }; _hamperService.Update(updatedHamper); return(RedirectToAction("Edit", "Category", new { CategoryId = VM.CategoryId })); } else { return(View(VM)); } }
// GET: Hampers/Edit/5 public async Task <IActionResult> Edit(int?id) { HamperEditViewModel hamperEditViewModel = new HamperEditViewModel(); if (id == null) { return(NotFound()); } var hamper = await _context.Hamper.SingleOrDefaultAsync(m => m.HamperId == id); if (hamper == null) { return(NotFound()); } hamperEditViewModel.HamperId = hamper.HamperId; hamperEditViewModel.HamperName = hamper.HamperName; hamperEditViewModel.HamperPrice = hamper.HamperPrice; hamperEditViewModel.HamperDetail = hamper.HamperDetail; //hamperEditViewModel.ProductList = _context.Product.ToList(); //hamperEditViewModel.CategoryName = _context.Category.Select(i => i.CategoryName).ToList(); hamperEditViewModel.CategoriesList = _context.Category.ToList(); hamperEditViewModel.CategoryId = hamper.CategoryId; //hamperEditViewModel.ProductId = _context.hamperProducts.Where(i => i.HamperId == id).Select(i => i.ProductId).ToList(); //hamperEditViewModel.ProductNameList = _context.Product // .Where(p => hamperEditViewModel.ProductId.Contains(p.ProductId)) // .Select(n => n.ProductName).ToList(); //hamperEditViewModel.ProductNameList = _context.Product.Where(n => n.ProductCategory == hamperEditViewModel.CategoryName).Select(n => n.ProductName).ToList(); return(View(hamperEditViewModel)); }
public async Task <IActionResult> Edit(HamperEditViewModel vm, IFormFile upload) { if (ModelState.IsValid) { Hamper hamper = _context.TblHamper.Where(h => h.HamperId == vm.HamperId).FirstOrDefault(); if (upload == null) { hamper.HamperName = vm.HamperName; hamper.Details = vm.Details; hamper.Price = vm.Price; } else { // Create a binary read to read the data from the upload file BinaryReader binaryReader = new BinaryReader(upload.OpenReadStream()); // Read the bytes, specifying the length of the content byte[] fileData = binaryReader.ReadBytes((int)upload.Length); // Extract the file name; we don't want the whole path var fileName = Path.GetFileName(upload.FileName); hamper.HamperName = vm.HamperName; hamper.Details = vm.Details; hamper.Price = vm.Price; hamper.FileName = fileName; hamper.FileContent = fileData; hamper.ContentSize = upload.Length; hamper.ContentType = upload.ContentType; } await _context.SaveChangesAsync(); return(RedirectToAction("Details", "Hamper", new { Id = hamper.CategoryId })); } return(View(vm)); }
public IActionResult Edit(int id) { Hamper hamper = _dataService.GetSingle(c => c.HamperId == id); HamperEditViewModel vm = new HamperEditViewModel { HamperId = hamper.HamperId, HamperName = hamper.HamperName, Details = hamper.Details, Price = hamper.Price, CategoryId = hamper.CategoryId, }; return(View(vm)); }
public IActionResult Edit(int HamperId) { Hamper hamper = _hamperService.Query(x => x.HamperId == HamperId).FirstOrDefault(); //TempData["categoryId"] = CategoryId.ToString(); //_httpContextAccessor.HttpContext.Session.SetString("categoryId", CategoryId.ToString()); HamperEditViewModel VM = new HamperEditViewModel { HamperId = HamperId, HamperName = hamper.HamperName, Description = hamper.Description, Products = hamper.Products, Supplier = hamper.Supplier, Price = hamper.Price, ImageUrl = hamper.ImageUrl, CategoryId = hamper.CategoryId }; return(View(VM)); }
public async Task <IActionResult> Edit(int id, HamperEditViewModel hamperEditViewModel) { hamperEditViewModel.HamperId = _context.Hamper.Where(i => i.HamperId == id).Select(i => i.HamperId).FirstOrDefault(); if (id != hamperEditViewModel.HamperId) { return(NotFound()); } var hamper = await _context.Hamper.SingleOrDefaultAsync(m => m.HamperId == id); if (ModelState.IsValid) { try { hamper.HamperId = id; hamper.HamperName = hamperEditViewModel.HamperName; hamper.HamperPrice = hamperEditViewModel.HamperPrice; hamper.HamperDetail = hamperEditViewModel.HamperDetail; hamper.CategoryId = hamperEditViewModel.CategoryId; _context.Update(hamper); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!HamperExists(hamper.HamperId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["CategoryId"] = new SelectList(_context.Set <Category>(), "CategoryId", "CategoryId", hamper.CategoryId); return(View(hamper)); }