public async Task <IActionResult> Edit(int id, [Bind("id,Name,Salers,ProdactType, Weight, Count, Price")] Prodacts prodacts) { if (id != prodacts.id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(prodacts); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ProdactsExists(prodacts.id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(prodacts)); }
public async Task <IActionResult> AddImage(int?id, IFormFile uploads) { if (id != null) { if (uploads != null) { Prodacts prodacts = await _context.Prodacts.Where(x => x.id == id).FirstOrDefaultAsync(); byte[] p1 = null; using (var fs1 = uploads.OpenReadStream()) using (var ms1 = new MemoryStream()) { fs1.CopyTo(ms1); p1 = ms1.ToArray(); } prodacts.ImageMimeTypeOfData = uploads.ContentType; prodacts.Image = p1; _context.Prodacts.Update(prodacts); _context.SaveChanges(); return(RedirectToAction(nameof(Index))); } } return(RedirectToAction(nameof(Index))); }
public async Task <IActionResult> Create([Bind("id,Name,Salers,ProdactType, Weight, Count, Price")] Prodacts prodacts) { if (ModelState.IsValid) { _context.Add(prodacts); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(prodacts)); }
public FileContentResult GetImage(int id) { Prodacts prodacts = _context.Prodacts .FirstOrDefault(g => g.id == id); if (prodacts != null) { var file = File(prodacts.Image, prodacts.ImageMimeTypeOfData); return(file); } else { return(null); } }