Ejemplo n.º 1
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

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

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

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

            //_db.Attach(Instructor).State = EntityState.Modified;

            try
            {
                Instructor instructorFromDb = await _db.Instructors.FirstOrDefaultAsync(m => m.Id == Instructor.Id);

                instructorFromDb.FirstName      = Instructor.FirstName;
                instructorFromDb.LastName       = Instructor.LastName;
                instructorFromDb.Department     = Instructor.Department;
                instructorFromDb.NumYearsWorked = Instructor.NumYearsWorked;
                await _db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!InstructorExists(Instructor.Id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

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

            _db.Instructors.Add(Instructor);
            await _db.SaveChangesAsync();

            return(RedirectToPage("./Index"));
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }
            // Select can only pass strings so convert it to bool
            Student.Gender = Convert.ToBoolean(Request.Form["Gender"]);
            Random random = new Random();

            Student.StudentId = random.Next(10000000, 99999999); // Randomly generate the student a studentId
            _context.Students.Add(Student);
            await _context.SaveChangesAsync();

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

            var    ClaimsIdentity = (ClaimsIdentity)User.Identity;
            var    claim          = ClaimsIdentity.FindFirst(ClaimTypes.NameIdentifier);
            string instructorId   = claim.Value;

            Class.InstructorId = instructorId;

            _context.Classes.Add(Class);
            await _context.SaveChangesAsync();

            return(RedirectToPage("/Instructors/Classes"));
        }
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }


            try
            {
                Student dbStudent = await _context.Students.FirstOrDefaultAsync(i => i.Id == Student.Id);

                dbStudent.FirstName  = Student.FirstName;
                dbStudent.LastName   = Student.LastName;
                dbStudent.Year       = Student.Year;
                dbStudent.House      = Student.House;
                dbStudent.IsMudBlood = Student.IsMudBlood;
                dbStudent.StudentId  = Student.StudentId;
                dbStudent.Gender     = Student.Gender;

                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException e)
            {
                if (!StudentExists(Student.Id))
                {
                    return(NotFound());
                }
                else
                {
                    Console.WriteLine(e.StackTrace);
                    throw;
                }
            }

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