Пример #1
0
        public ActionResult Signup(Accounts _user)
        {
            // Check if any errors occur
            if (ModelState.IsValid)
            {
                var check = _context.Accounts.Where(a => a.Email.Equals(_user.Email) || a.Username.Equals(_user.Username)).ToList();

                // Checks if an email address and username was found
                if (check.Count == 0)
                {
                    _context.Accounts.Add(_user);
                    _context.SaveChanges();

                    return(RedirectToAction("Login"));
                }
                else
                {
                    var errorCheck = _context.Accounts.Where(a => a.Email.Equals(_user.Email) || a.Username.Equals(_user.Username)).Single();

                    // Double check fields
                    if (regex.Replace(_user.Username, string.Empty) != regex.Replace(errorCheck.Username, string.Empty))
                    {
                        if (regex.Replace(_user.Email, string.Empty) != regex.Replace(errorCheck.Email, string.Empty))
                        {
                            _context.Accounts.Add(_user);
                            _context.SaveChanges();

                            return(RedirectToAction("Login"));
                        }
                        else
                        {
                            ViewBag.Error = "Email address should be unique";

                            return(View());
                        }
                    }
                    else
                    {
                        ViewBag.Error = "Username should be unique";

                        return(View());
                    }
                }
            }

            return(View());
        }
        /// <summary>
        /// Adds default data to the Courses table when no data is present
        /// </summary>
        /// <param name="serviceProvider">Used to provide custom support to objects</param>
        public static void InitializeCourses(IServiceProvider serviceProvider)
        {
            using var context = new GroupProjectContext(
                      serviceProvider.GetRequiredService <
                          DbContextOptions <GroupProjectContext> >());

            // Checks if any courses are in the DB
            if (context.Courses.Any())
            {
                return; // means that the DB has been seeded
            }

            context.Courses.AddRange(
                new Courses
            {
                CourseID   = "CIS001",
                CourseName = "Intro to Logic",
                Credits    = 3,
                Online     = false
            },
                new Courses
            {
                CourseID   = "CIS002",
                CourseName = "C#",
                Credits    = 4,
                Online     = true
            },
                new Courses
            {
                CourseID   = "CIS003",
                CourseName = "COBOL II",
                Credits    = 3,
                Online     = true
            },
                new Courses
            {
                CourseID   = "CIS004",
                CourseName = "Java",
                Credits    = 4,
                Online     = false
            },
                new Courses
            {
                CourseID   = "CIS005",
                CourseName = "ASP .NET",
                Credits    = 3,
                Online     = false
            }
                );

            context.SaveChanges();
        }
Пример #3
0
        /// <summary>
        /// Adds default data to he Accounts table when no data is present
        /// </summary>
        /// <param name="serviceProvider">Used to provide custom support to objects</param>
        public static void InitializeAccounts(IServiceProvider serviceProvider)
        {
            using var context = new GroupProjectContext(
                      serviceProvider.GetRequiredService <
                          DbContextOptions <GroupProjectContext> >());

            // Checks if any accounts are in the DB
            if (context.Accounts.Any())
            {
                return; // means that the DB has been seeded
            }

            context.Accounts.AddRange(
                new Accounts
            {
                Username = "******",
                Email    = "*****@*****.**",
                Password = "******",
                IsAdmin  = true
            },
                new Accounts
            {
                Username = "******",
                Email    = "*****@*****.**",
                Password = "******",
                IsAdmin  = true
            },
                new Accounts
            {
                Username = "******",
                Email    = "*****@*****.**",
                Password = "******",
                IsAdmin  = false
            }
                );

            context.SaveChanges();
        }
Пример #4
0
        public ActionResult SignUp(Accounts _user)
        {
            // Check if any errors occur
            if (ModelState.IsValid)
            {
                var check = _context.Accounts.Where(a => a.Email != _user.Email);

                // Checks if an email address was found
                if (check != null)
                {
                    _user.Password = EncryptPassword(_user.Password);
                    _context.Accounts.Add(_user);
                    _context.SaveChanges();
                    return(RedirectToAction("Index"));
                }
                else
                {
                    ViewBag["Error"] = "Email address is not unique";
                    return(View());
                }
            }

            return(View());
        }
Пример #5
0
        public ActionResult Signup(Accounts _user)
        {
            // Check if any errors occur
            if (ModelState.IsValid)
            {
                var check = _context.Accounts.Where(a => a.Email == _user.Email && a.Username == _user.Username).ToList();

                // Checks if an email address and username was found
                if (check.Count == 0)
                {
                    _context.Accounts.Add(_user);
                    _context.SaveChanges();

                    return(RedirectToAction("Login"));
                }
                else
                {
                    ViewBag.Error = "Email address or username is not unique";
                    return(View());
                }
            }

            return(View());
        }