public async Task <IActionResult> Edit(int id, [Bind("ID,LastName,FirstName,UserName,Password,Email")] InstructorM instructor)
        {
            if (id != instructor.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(instructor);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!InstructorExists(instructor.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction("Index"));
            }
            return(View(instructor));
        }
        public IActionResult Preferences([Bind("FirstName,LastName,UserName,Password,Email")] InstructorM instructor)
        {
            /*var PassID = (int)HttpContext.Session.GetInt32(SessionLoggedID);
             * if (PassID != instructor.ID)
             * {
             *  return NotFound();
             * }*/
            var PassID = HttpContext.Session.GetInt32(SessionLoggedID);

            instructor.ID = (int)PassID;

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(instructor);
                    _context.SaveChanges();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!InstructorExists(instructor.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                ViewBag.Success = "Preferences Updated";
                return(View("InstructorIndex"));
            }
            ViewBag.Error = "Model State Invalid";
            return(View("InstructorIndex"));
        }
        public IActionResult InstructorLogin(InstructorM i)
        {
            bool find = _context.Instructors.ToList().Any(m => m.UserName == i.UserName && m.Password == i.Password);

            if (find)
            {
                //ViewBag.error = "Name Already exists";
                //TODO: Update Return Action to go to the Student Controller
                return(RedirectToAction("Contact", "Home"));
            }
            else
            {
                ViewBag.error = "User Name Or Password is wrong or does not exist!";
                return(View("InstructorLogin"));
            }
            //return View();
        }
        public IActionResult InstructorLogin(InstructorM i)
        {
            bool find = _context.Instructors.ToList().Any(m => m.UserName == i.UserName && m.Password == i.Password);

            if (find)
            {
                //ViewBag.error = "Name Already exists";

                //TODO: Update Return Action to go to the Student Controller
                var instructor = _context.Instructors.ToList().SingleOrDefault(m => m.UserName == i.UserName && m.Password == i.Password);
                HttpContext.Session.SetInt32(SessionLoggedID, instructor.ID);
                return(RedirectToAction("InstructorIndex"));
            }
            else
            {
                ViewBag.error = "User Name Or Password is wrong or does not exist!";
                return(View("InstructorLogin"));
            }
            //return View();
        }
        public async Task <IActionResult> InstructorRegister([Bind("ID,LastName,FirstName,UserName,Password,Email")] InstructorM instructor)
        {
            bool find = _context.Instructors.ToList().Any(m => m.UserName == instructor.UserName);

            if (find)
            {
                ViewBag.Error       = "User Name already exists, Please choose a different User Name";
                instructor.UserName = "";
                return(View());
            }
            else if (ModelState.IsValid)
            {
                ViewBag.success = instructor.FirstName + " Your Account Has Been Succesfully Created!";
                _context.Add(instructor);
                await _context.SaveChangesAsync();

                ModelState.Clear();
                return(View("InstructorLogin"));
            }
            return(View(instructor));
        }
Exemple #6
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();
        }
        // GET: Instructors/Create
        public IActionResult InstructorRegister()
        {
            InstructorM instructor = new InstructorM();

            return(View());
        }