Ejemplo n.º 1
0
        public void CreateOrganization()
        {
            UserModel user = new UserModel();

            user.Email = "*****@*****.**";
            user.Password = "******";

            using (var db = new DataContext())
            {
                try
                {
                    if (db.Users.FirstOrDefault(u => u.Email == user.Email) == null)
                    {
                        var crypto = new SimpleCrypto.PBKDF2();

                        var encryptPass = crypto.Compute(user.Password);

                        var u = new UserModel();

                        u.Email = user.Email;
                        u.Password = encryptPass;
                        u.PasswordSalt = crypto.Salt;
                        db.Users.Add(u);
                        db.SaveChanges();

                        UserRole UR = new UserRole();
                        UR.UserId = u.UserId;

                        Role R = new Role();
                        foreach (var role in db.Roles.ToList())
                        {
                            if (role.RoleName == "Organization")
                            {
                                R = role;
                                break;
                            }
                        }

                        UR.RoleId = R.RoleId;
                        UR.Role = R;

                        db.UserRoles.Add(UR);
                        db.SaveChanges();
                    }
                }
                catch (Exception ex)
                {
                }
            }
        }
Ejemplo n.º 2
0
        public ActionResult CreateUser(UserModel user)
        {
            if (ModelState.IsValid)
            {

                using (var db = new DataContext())
                {
                    //By default all registration of any user will start off as a normal user till they decide to request for a operator role
                    //in manage a site/resort or both.
                    if (db.Users.FirstOrDefault(u => u.Email == user.Email) == null)
                    {
                        var crypto = new SimpleCrypto.PBKDF2();

                        var encryptPass = crypto.Compute(user.Password);

                        var u = new UserModel();

                        u.Email = user.Email;
                        u.Password = encryptPass;
                        u.PasswordSalt = crypto.Salt;
                        db.Users.Add(u);
                        db.SaveChanges();

                        UserRole UR = new UserRole();
                        UR.UserId = u.UserId;

                        //Get from User input upon creating a new User
                        //u.UserRoles = user.UserRoles;

                        //Role R = new Role();
                        //foreach (var role in db.Roles.ToList())
                        //{
                        //    if (role.RoleName == u.UserRoles.ToString())
                        //    {
                        //        R = role;
                        //        break;
                        //    }
                        //}

                        Role R = new Role();
                        foreach (var role in db.Roles.ToList())
                        {
                            if (role.RoleName == "Organization")
                            {
                                R = role;
                                break;
                            }
                        }

                        UR.RoleId = R.RoleId;
                        UR.Role = R;
                        db.UserRoles.Add(UR);
                        db.SaveChanges();

                        OrganizationModel info = new OrganizationModel();
                        db.OrganizationInfo.Add(info);
                        db.SaveChanges();

                        u.OrganizationId = info.OrganizationId;
                        db.SaveChanges();

                        return Login(user);
                    }
                }
            }
            else
            {
                ModelState.AddModelError("", "Data input is incorrect!");
            }
            return View();
        }
Ejemplo n.º 3
0
        //public void CreateDiveResortOp()
        //{
        //    UserModel user = new UserModel();
        //    user.Email = "*****@*****.**";
        //    user.Password = "******";
        //    using (var db = new DataContext())
        //    {
        //        try
        //        {
        //            if (db.Users.FirstOrDefault(u => u.Email == user.Email) == null)
        //            {
        //                var crypto = new SimpleCrypto.PBKDF2();
        //                var encryptPass = crypto.Compute(user.Password);
        //                var u = new UserModel();
        //                u.Email = user.Email;
        //                u.Password = encryptPass;
        //                u.PasswordSalt = crypto.Salt;
        //                db.Users.Add(u);
        //                db.SaveChanges();
        //                UserRole UR = new UserRole();
        //                UR.UserId = u.UserId;
        //                Role R = new Role();
        //                foreach (var role in db.Roles.ToList())
        //                {
        //                    if (role.RoleName == "ResortOperator")
        //                    {
        //                        R = role;
        //                        break;
        //                    }
        //                }
        //                UR.RoleId = R.RoleId;
        //                UR.Role = R;
        //                db.UserRoles.Add(UR);
        //                db.SaveChanges();
        //            }
        //        }
        //        catch (Exception ex)
        //        {
        //        }
        //    }
        //}
        //public void CreateDiveSiteOp()
        //{
        //    UserModel user = new UserModel();
        //    user.Email = "*****@*****.**";
        //    user.Password = "******";
        //    using (var db = new DataContext())
        //    {
        //        try
        //        {
        //            if (db.Users.FirstOrDefault(u => u.Email == user.Email) == null)
        //            {
        //                var crypto = new SimpleCrypto.PBKDF2();
        //                var encryptPass = crypto.Compute(user.Password);
        //                var u = new UserModel();
        //                u.Email = user.Email;
        //                u.Password = encryptPass;
        //                u.PasswordSalt = crypto.Salt;
        //                db.Users.Add(u);
        //                db.SaveChanges();
        //                UserRole UR = new UserRole();
        //                UR.UserId = u.UserId;
        //                Role R = new Role();
        //                foreach (var role in db.Roles.ToList())
        //                {
        //                    if (role.RoleName == "DiveCenterOperator")
        //                    {
        //                        R = role;
        //                        break;
        //                    }
        //                }
        //                UR.RoleId = R.RoleId;
        //                UR.Role = R;
        //                db.UserRoles.Add(UR);
        //                db.SaveChanges();
        //            }
        //        }
        //        catch (Exception ex)
        //        {
        //        }
        //    }
        //}
        //---------------Testing Purposes--------------------
        public void AddRole()
        {
            DataContext db = new DataContext();
            try
            {
                if (db.Roles.ToList().Count == 0)
                {
                    Role r = new Role();

                    r.RoleName = "Administrator";

                    db.Roles.Add(r);
                    db.SaveChanges();

                    r = new Role();
                    r.RoleName = "Organization";

                    db.Roles.Add(r);
                    db.SaveChanges();

                    //r = new Role();
                    //r.RoleName = "DiveCenterOperator";

                    //db.Roles.Add(r);
                    //db.SaveChanges();

                    //r = new Role();
                    //r.RoleName = "ResortOperator";

                    //db.Roles.Add(r);
                    //db.SaveChanges();

                    r = new Role();
                    r.RoleName = "User";

                    db.Roles.Add(r);
                    db.SaveChanges();
                }
            }
            catch (Exception ex)
            {
            }
        }