Esempio n. 1
0
        // To protect from overposting attacks, see https://aka.ms/RazorPagesCRUD
        public async Task <IActionResult> OnPostAsync()
        {
            //var emptyStudent = new Student();

            //if (await TryUpdateModelAsync<Student>(
            //    emptyStudent,
            //    "student",   // Prefix for form value.
            //    s => s.FirstName, s => s.LastName, s => s.EnrollmentDate))
            //{
            //    _context.Student.Add(emptyStudent);
            //    await _context.SaveChangesAsync();
            //    return RedirectToPage("./Index");
            //}

            if (!ModelState.IsValid)
            {
                return(Page());
            }

            if (Student.EnrollmentDate < myDate.Subtract(t))
            {
                TempData[MessageKey] = "invalid old date";
                return(Page());
                //return RedirectToAction(Request.Path);
            }


            _context.Student.Add(Student);
            await _context.SaveChangesAsync();

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

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

            if (Student == null)
            {
                return(NotFound());
            }

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

                return(RedirectToPage("./Index"));
            }
            catch (DbUpdateException)
            {
                return(RedirectToAction("./Delete",
                                        new { id, saveChangesError = true }));
            }
        }
Esempio n. 3
0
        // 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(Internship).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!InternshipExists(Internship.StudentID))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("./Index"));
        }
Esempio n. 4
0
        // 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 (Enrollment.midterm != null && Enrollment.final != null)
            {
                grade = (int)(Enrollment.midterm * 0.3 + Enrollment.final * 0.7);
                if (grade >= 90)
                {
                    Enrollment.grade = "AA";
                }
                else if (grade >= 85)
                {
                    Enrollment.grade = "BA";
                }
                else if (grade >= 80)
                {
                    Enrollment.grade = "BB";
                }
                else if (grade >= 70)
                {
                    Enrollment.grade = "CB";
                }
                else if (grade >= 60)
                {
                    Enrollment.grade = "CC";
                }
                else if (grade >= 50)
                {
                    Enrollment.grade = "DD";
                }
                else
                {
                    Enrollment.grade = "FF";
                }
            }
            _context.Attach(Enrollment).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!EnrollmentExists(Enrollment.EnrollmentID))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

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

            var enrollExist = _context.Enrollments
                              .Where(e => e.StudentID == Enrollment.StudentID && e.LessonID == Enrollment.LessonID)
                              .FirstOrDefault <Enrollment>();

            if (enrollExist != null)
            {
                return(Page());
            }

            if (Enrollment.midterm != null && Enrollment.final != null)
            {
                grade = (int)(Enrollment.midterm * 0.3 + Enrollment.final * 0.7);
                if (grade >= 90)
                {
                    Enrollment.grade = "AA";
                }
                else if (grade >= 85)
                {
                    Enrollment.grade = "BA";
                }
                else if (grade >= 80)
                {
                    Enrollment.grade = "BB";
                }
                else if (grade >= 70)
                {
                    Enrollment.grade = "CB";
                }
                else if (grade >= 60)
                {
                    Enrollment.grade = "CC";
                }
                else if (grade >= 50)
                {
                    Enrollment.grade = "DD";
                }
                else
                {
                    Enrollment.grade = "FF";
                }
            }

            _context.Enrollments.Add(Enrollment);
            await _context.SaveChangesAsync();

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

            _context.LessonAssigments.Add(LessonAssigment);
            await _context.SaveChangesAsync();

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

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

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

            Enrollment = await _context.Enrollments.FindAsync(id);

            if (Enrollment != null)
            {
                _context.Enrollments.Remove(Enrollment);
                await _context.SaveChangesAsync();
            }

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

            Lesson = await _context.Lessons.FindAsync(id);

            if (Lesson != null)
            {
                _context.Lessons.Remove(Lesson);
                await _context.SaveChangesAsync();
            }

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

            Internship = await _context.Internships.FindAsync(id);

            if (Internship != null)
            {
                _context.Internships.Remove(Internship);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
Esempio n. 11
0
        // 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(int id)
        {
            var studentToUpdate = await _context.Student.FindAsync(id);

            if (studentToUpdate == null)
            {
                return(NotFound());
            }

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

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

            return(Page());
        }
Esempio n. 12
0
        // To protect from overposting attacks, see https://aka.ms/RazorPagesCRUD
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            var internExist = _context.Internships
                              .Where(I => I.StudentID == Internship.StudentID)
                              .FirstOrDefault <Internship>();

            if (internExist != null)
            {
                return(Page());
            }

            _context.Internships.Add(Internship);
            await _context.SaveChangesAsync();

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