Exemplo n.º 1
0
        public async Task <IActionResult> OnPostAsync(int?id, bool?saveChangesError = false)
        {
            if (id == null)
            {
                return(NotFound("El Id del registro no Existe!"));
            }

            var student = await _context.Students.AsNoTracking().FirstOrDefaultAsync(e => e.StudentId.Equals(id));

            //Student = await _context.Students.FindAsync(id);

            if (Student == null)
            {
                return(NotFound("Student no encontrado  con ese Id."));
            }

            try
            {
                _context.Students.Remove(Student);
                await _context.SaveChangesAsync();

                return(RedirectToPage("./Index"));
            }
            catch (DbUpdateException ex)
            {
                ErrorMessage = ex.Message;

                return(RedirectToAction("./Delete", new { id, saveChangesError = true }));
            }
        }
Exemplo n.º 2
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.Attach(Course).State = EntityState.Modified;

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

            return(RedirectToPage("./Index"));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.Courses.Add(Course);
            await _context.SaveChangesAsync();

            return(RedirectToPage("./Index"));
        }
Exemplo n.º 4
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

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

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

            return(RedirectToPage("./Index"));
        }
Exemplo n.º 5
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            var emptyStudent = new Student();

            if (await TryUpdateModelAsync <Student>(emptyStudent, "student", s => s.FirstMidName, s => s.LastName,
                                                    s => s.EnrollmentDate))
            {
                _context.Students.Add(emptyStudent);

                await _context.SaveChangesAsync();

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

            return(null);
        }
Exemplo n.º 6
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            var studentToUpdate = await _context.Students.FindAsync(id);

            // _context.Attach(Student).State = EntityState.Modified;

            if (await TryUpdateModelAsync <Student>(studentToUpdate, "student", s => s.FirstMidName,
                                                    s => s.LastName, s => s.EnrollmentDate))
            {
                await _context.SaveChangesAsync();

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

            //try
            //{
            //    await _context.SaveChangesAsync();
            //}
            //catch (DbUpdateConcurrencyException)
            //{
            //    if (!StudentExists(Student.StudentId))
            //    {
            //        return NotFound();
            //    }
            //    else
            //    {
            //        throw;
            //    }
            //}

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

            return(Page());
        }