// To protect from overposting attacks, please 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(Content).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ContentExists(Content.ID)) { return(NotFound()); } else { throw; } } return(RedirectToPage("./Index")); }
// To protect from overposting attacks, please enable the specific properties you want to bind to, for // more details see https://aka.ms/RazorPagesCRUD. public async Task <IActionResult> OnPostAsync() { string webRootPath = _hostingEnvironment.WebRootPath; var files = HttpContext.Request.Form.Files; if (!ModelState.IsValid) { return(Page()); } Content.ContentTime = DateTime.Now; Content.ContentHit = 0; string fileName = Guid.NewGuid().ToString(); var uploads = Path.Combine(webRootPath, @"images\content"); var extension = Path.GetExtension(files[0].FileName); using (var fileStream = new FileStream(Path.Combine(uploads, fileName + extension), FileMode.Create)) { files[0].CopyTo(fileStream); } Content.ContentImg = @"\images\content\" + fileName + extension; _context.Content.Add(Content); await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); }
// To protect from overposting attacks, please 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.Category.Add(Category); await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } Content = await _context.Content.FindAsync(id); if (Content != null) { _context.Content.Remove(Content); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }