// 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(News).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!NewsExists(News.Id)) { return(NotFound()); } else { throw; } } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } string filePath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "images", Product.Name + ".jpg"); if (System.IO.File.Exists(filePath)) { System.IO.File.Delete(filePath); } Product = await _context.products.FindAsync(id); if (Product != null) { _context.products.Remove(Product); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }
// To protect from overposting attacks, see https://aka.ms/RazorPagesCRUD public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } _context.products.Add(Product); await _context.SaveChangesAsync(); if (Productse.Picture?.Length > 0) { string filePath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "images", Product.Name + Path.GetExtension(Productse.Picture.FileName)); using (var stream = new FileStream(filePath, FileMode.Create)) { Productse.Picture.CopyTo(stream); } } if (Product.Number != 0) { return(RedirectToPage("./CreateCTP")); } else { return(RedirectToPage("./Index")); } }
// To protect from overposting attacks, see https://aka.ms/RazorPagesCRUD public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } _context.categories.Add(Category); await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } News = await _context.News.FindAsync(id); if (News != null) { _context.News.Remove(News); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } Category = await _context.categories.FindAsync(id); if (Category != null) { _context.categories.Remove(Category); await _context.SaveChangesAsync(); } 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) { ViewData["ProductId"] = new SelectList(_context.products, "Id", "Id"); return(Page()); } _context.Attach(Product).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ProductExists(Product.Id)) { return(NotFound()); } else { throw; } } if (Productse.Picture?.Length > 0) { string filePath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "images", Product.Name + Path.GetExtension(Productse.Picture.FileName)); using (var stream = new FileStream(filePath, FileMode.Create)) { Productse.Picture.CopyTo(stream); } } return(RedirectToPage("./Index")); }