예제 #1
0
        public void SaveMember(Member member)
        {
            if (member.MemberId == 0)
            {
                context.Members.Add(member);

                if (member.Password != null && member.Password.PasswordId == 0)
                {;
                    context.Passwords.Add(member.Password);
                }
            }
            else
            {
                if (member.Password != null)
                {
                    context.Entry(member.Password).State = EntityState.Modified;
                }

                if (member.Profile != null)
                {
                    context.Entry(member.Profile).State = EntityState.Modified;
                }

                context.Entry(member).State = EntityState.Modified;
            }

            context.SaveChanges();
        }
예제 #2
0
        public MemberViewModel(Member member)
        {
            MemberId = member.MemberId;
            UserName = member.UserName;
            Email = member.Email;
            FirstName = member.Profile.FirstName;
            LastName = member.Profile.LastName;
            Description = member.Profile.Description;
            Phone = member.Profile.Phone;
            Address = member.Profile.Address;
            Building = member.Profile.Building;
            Floor = member.Profile.Floor;
            Office = member.Profile.Office;

            // Token Password, just to validate the model
            // in Edit View.
            Password = "******";
            PasswordConfirmation = "2225839578C8D1B6AB0C97DA4E5FC77601D9926";
        }
예제 #3
0
        public void SaveMember(Member member)
        {
            if (member.MemberId == 0)
            {
                Member lastMember = members.Last<Member>();
                int id = lastMember.MemberId + 1;

                member.MemberId = id;
                member.Password.PasswordId = id;
                member.PasswordId = id;
                member.PasswordId = id;

                members.Add(member);
            }
            else
            {
                Member memberToRemove = members.FirstOrDefault(m => m.MemberId == member.MemberId);
                members.Remove(memberToRemove);
                members.Add(member);
            }
        }
예제 #4
0
파일: Seeder.cs 프로젝트: cigno/ReSolution
        public static void SeedData()
        {
            RSDbContext context = new RSDbContext();

            Member member;
            Role[] roles;

            if (context.Members.Count() == 0)
            {
                member = new Member
                {
                    MemberGuid = Guid.NewGuid(),
                    UserName = "******",
                    Email = "*****@*****.**",
                    Profile = new Profile
                    {
                        FirstName = "Admin",
                        LastName = "Root",
                        Description = "Application Administrator",
                        Phone = "",
                        Address = "",
                        Building = "",
                        Floor = "",
                        Office = ""
                    },
                    Password = new Password
                    {
                        Hash = "BB595D807F9615796C9B99A52CE4E8F07347C899",
                        Salt = "sVGQGTu+CZH8axS6QWNMm3IZ6PdKA89HE2Ju3vs0LK8="
                    }

                };

                RoleSet user = new RoleSet { Name = "Users" };
                RoleSet powerUser = new RoleSet { Name = "Power Users" };
                RoleSet admin = new RoleSet { Name = "Administrators" };

                roles = new Role[] {
                    new Role { Name = "Can_Access_Application",
                        Description = "Can access this application",
                        },
                    new Role { Name = "Can_Access_Control_Panel",
                        Description = "Can access Control Panel",
                        },
                    new Role { Name = "Can_Access_Home_Controller",
                        Description = "Can access Control's Panel Home Page",
                        },
                    new Role { Name = "Can_Access_Member_Controller",
                        Description = "Can access Member Settings",
                        },
                    new Role { Name = "Can_Create_Member",
                        Description = "Can add members",
                        },
                    new Role { Name = "Can_Edit_Member",
                        Description = "Can edit member's details",
                        },
                    new Role { Name = "Can_Delete_Member",
                        Description = "Can remove members",
                        },
                    new Role { Name = "Can_Access_Role_Controller",
                        Description = "Can access Role Settings",
                        },
                    new Role { Name = "Can_Create_Role_Set",
                        Description = "Can add roles",
                        },
                    new Role { Name = "Can_Edit_Role_Set",
                        Description = "Can edit role's settings",
                        },
                    new Role { Name = "Can_Delete_Role_Set",
                        Description = "Can remove roles" }
                };

                int currentRoles = context.Roles.Count() > 0 ? (context.Roles.Count() - 1) : 0;

                foreach (Role role in roles)
                {
                    context.Roles.Add(role);
                }

                List<RoleSetting> adminRoles = new List<RoleSetting>();
                foreach (Role role in roles)
                {
                    RoleSetting roleValue = new RoleSetting();
                    roleValue.Role = role;
                    roleValue.IsActive = true;

                    adminRoles.Add(roleValue);
                }
                admin.Roles = adminRoles;

                List<RoleSetting> powerUserRoles = new List<RoleSetting>();
                foreach (Role role in roles)
                {
                    RoleSetting roleValue = new RoleSetting();
                    roleValue.Role = role;
                    roleValue.IsActive = true;

                    powerUserRoles.Add(roleValue);
                }
                powerUser.Roles = powerUserRoles;

                List<RoleSetting> userRoles = new List<RoleSetting>();
                foreach (Role role in roles)
                {
                    RoleSetting roleValue = new RoleSetting();
                    roleValue.Role = role;
                    roleValue.IsActive = false;

                    userRoles.Add(roleValue);
                }
                user.Roles = userRoles;

                foreach (RoleSet item in new RoleSet[] { admin, powerUser, user })
                {
                    context.RoleSets.Add(item);
                }

                member.RoleSet = admin;

                context.Members.Add(member);

                context.SaveChanges();
            }
        }
예제 #5
0
        public void Check_UserId_Email_Edit_Uniqueness()
        {
            // ARRANGE
            Member toy = new Member()
            {
                MemberId = 0,
                UserName = "******",
                Email = "*****@*****.**",
                Password = new Password(),
                Profile = new Profile()
                {
                    FirstName = "Toy",
                    LastName = "Boy",
                }
            };

            repo.SaveMember(toy);

            MemberViewModel model = new MemberViewModel(
                repo.Members.FirstOrDefault(m => m.MemberId == 3));

            model.UserName = toy.UserName;
            model.Email = toy.Email;

            // ACT
            ViewResult expected = (ViewResult)target.Create(model);

            // ASSERT
            Assert.IsTrue(target.ModelState.Keys.Contains("UserAlreadyExist"));
        }
예제 #6
0
        public void Check_UserId_Email_Create_Uniqueness()
        {
            // ARRANGE
            Member toy = new Member()
            {
                MemberId = 0,
                UserName = "******",
                Email = "*****@*****.**",
                Password = new Password(),
                Profile = new Profile()
                {
                    FirstName = "Toy",
                    LastName = "Boy",
                }
            };

            repo.SaveMember(toy);

            MemberViewModel model = new MemberViewModel()
            {
                MemberId = 0,
                UserName = "******",
                Email = "*****@*****.**",
                FirstName = "NewFirstName",
                LastName = "NewLastName",
                Description = "",
                Address = "",
                Building = "",
                Floor = "",
                Office = "",
                Password = "******",
                PasswordConfirmation = "Password"
            };

            // ACT
            target.Create(model);

            // ASSERT
            Assert.IsTrue(target.ModelState.Keys.Contains("UserAlreadyExist"));
        }
예제 #7
0
 public void DeleteMember(Member member)
 {
     Member memberToRemove = members.FirstOrDefault(m => m.MemberId == member.MemberId);
     members.Remove(memberToRemove);
 }
예제 #8
0
 public void DeleteMember(Member member)
 {
     context.Members.Remove(member);
     context.SaveChanges();
 }
예제 #9
0
        public ActionResult Create(MemberViewModel model)
        {
            if (ModelState.IsValid)
            {
                Member member;

                if (UserExists(model.UserName, model.Email))
                {
                    ModelState.AddModelError("UserAlreadyExist", "Username or Email already in use.");
                    ShowUserAlreadyExistAlert();
                    return View();
                }

                // Check if passwords matches
                if (model.Password == model.PasswordConfirmation)
                {
                    string salt = PasswordHelper.CreateSalt();
                    string hashedPassword = PasswordHelper.CreatePasswordHash(model.Password, salt);

                    member = new Member()
                    {
                        MemberId = 0,
                        MemberGuid = Guid.NewGuid(),
                        UserName = model.UserName,
                        Email = model.Email,
                        Profile = new Profile()
                        {
                            FirstName = model.FirstName,
                            LastName = model.LastName,
                            Description = model.Description,
                            Phone = model.Phone,
                            Address = model.Address,
                            Building = model.Building,
                            Floor = model.Floor,
                            Office = model.Office
                        },
                        Password = new Password()
                        {
                            Salt = salt,
                            Hash = hashedPassword
                        }
                    };

                }
                else
                {
                    ModelState.AddModelError("PasswordConfirmation", "Confirmation Password doesn't match your Password.");
                    return View();
                }

                try
                {
                    repository.SaveMember(member);

                    TempData["message"] = new Alert()
                    {
                        Class = "Success",
                        Title = "New member created.",
                        Description = string.Format("{0} {1}",
                          model.LastName.ToUpper(),
                          model.FirstName)
                    };

                }
                catch (Exception e)
                {
                    TempData["message"] = new Alert(e);
                }

                return RedirectToAction("Index");
            }
            else
            {
                return View("Create", model);
            }
        }