示例#1
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Course = await _context.Students.FindAsync(id);

            if (Course != null)
            {
                _context.Students.Remove(Course);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
示例#2
0
文件: Edit.cshtml.cs 项目: snterg/-_1
        // 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());
            }
            if (Image != null)
            {
                var fileName = $"{Course.studId}" +
                               Path.GetExtension(Image.FileName);
                Course.Image = fileName;
                var path = Path.Combine(_environment.WebRootPath, "Images",
                                        fileName);
                using (var fStream = new FileStream(path, FileMode.Create))
                {
                    await Image.CopyToAsync(fStream);
                }
            }
            _context.Attach(Course).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CourseExists(Course.studId))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("./Index"));
        }
示例#3
0
        // To protect from overposting attacks, see https://aka.ms/RazorPagesCRUD
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.Students.Add(Course);
            if (Image != null)
            {
                var fileName = $"{Course.studId}" +
                               Path.GetExtension(Image.FileName);
                Course.Image = fileName;
                var path = Path.Combine(_environment.WebRootPath, "Images",
                                        fileName);
                using (var fStream = new FileStream(path, FileMode.Create))
                {
                    await Image.CopyToAsync(fStream);
                }
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }