// To protect from overposting attacks, enable the specific properties you want to bind to. // For more details, see https://aka.ms/RazorPagesCRUD. public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } _context.Attach(CategoryToproduct).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CategoryToproductExists(CategoryToproduct.Id)) { return(NotFound()); } else { throw; } } return(RedirectToPage("./Index")); }
// To protect from overposting attacks, enable the specific properties you want to bind to. // For more details, see https://aka.ms/RazorPagesCRUD. public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } _context.Attach(Product).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ProductExists(Product.ProductId)) { return(NotFound()); } else { throw; } } if (Productse.Picture?.Length > 0) { string filePath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "img", Product.Title + Path.GetExtension(Productse.Picture.FileName)); using (var stream = new FileStream(filePath, FileMode.Create)) { Productse.Picture.CopyTo(stream); } } return(RedirectToPage("./Index")); }