Esempio n. 1
0
        public async Task <IActionResult> Edit(int id, [Bind("StudentID,FirstName,LastName,InstructorID")] StudentM student)
        {
            if (id != student.StudentID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(student);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!StudentExists(student.StudentID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction("Index"));
            }
            return(View(student));
        }
        public async Task <IActionResult> Create([Bind("StudentID,FirstName,LastName,InstructorID")] StudentM student)
        {
            //TODO: Need ref. to Instructor TD from Login Instructor//

            if (ModelState.IsValid)
            {
                _context.Add(student);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(student));
        }
Esempio n. 3
0
        public async Task <IActionResult> Create([Bind("StudentID,FirstName,LastName,InstructorID")] StudentM student)
        {
            //TODO: Need ref. to Instructor TD from Login Instructor//

            if (ModelState.IsValid)
            {
                if (HttpContext.Session.GetInt32(SessionLoggedID) != null)
                {
                    var PassID = HttpContext.Session.GetInt32(SessionLoggedID);
                    student.InstructorID = (int)PassID;
                    _context.Add(student);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction("Index"));
                }
            }
            ViewBag.Error("An Error Occured, Please Re-Log into your account");
            return(RedirectToAction("Logout", "Instructors"));
        }
Esempio n. 4
0
        //Code Initilizes the database, ensuring it is created and populating the database for testing
        public static void Initialize(IceCreamContext context)
        {
            context.Database.EnsureCreated();

            if (context.Instructors.Any())
            {
                return;
            }

            var instructors = new InstructorM[]
            {
                new InstructorM {
                    LastName = "Meyers", FirstName = "Bob", UserName = "******", Password = "******", Email = "*****@*****.**"
                },
                new InstructorM {
                    LastName = "Meyers", FirstName = "Sally", UserName = "******", Password = "******", Email = "*****@*****.**"
                }
            };

            foreach (InstructorM i in instructors)
            {
                context.Instructors.Add(i);
            }
            context.SaveChanges();

            var students = new StudentM[]
            {
                new StudentM {
                    LastName = "Sue", FirstName = "Mary", InstructorID = 1
                },
                new StudentM {
                    LastName = "Miller", FirstName = "Tim", InstructorID = 1
                },
                new StudentM {
                    LastName = "Shriver", FirstName = "Kathy", InstructorID = 1
                },
                new StudentM {
                    LastName = "Flynn", FirstName = "Michael", InstructorID = 2
                },
                new StudentM {
                    LastName = "Undead", FirstName = "Chosen", InstructorID = 2
                },
                new StudentM {
                    LastName = "Punisher", FirstName = "The", InstructorID = 2
                }
            };

            foreach (StudentM s in students)
            {
                context.Students.Add(s);
            }
            context.SaveChanges();

            var scores = new Score[]
            {
                new Score {
                    ScoreNum = 9, StudentID = 6, Date = DateTime.Parse("2017-05-04")
                },
                new Score {
                    ScoreNum = 5, StudentID = 2, Date = DateTime.Parse("2017-05-04")
                },
                new Score {
                    ScoreNum = 8, StudentID = 3, Date = DateTime.Parse("2017-05-04")
                },
                new Score {
                    ScoreNum = 4, StudentID = 4, Date = DateTime.Parse("2017-05-04")
                },
                new Score {
                    ScoreNum = 7, StudentID = 1, Date = DateTime.Parse("2017-05-04")
                }
            };

            foreach (Score c in scores)
            {
                context.Scores.Add(c);
            }
            context.SaveChanges();
        }