示例#1
0
 /// <summary>
 /// Adds a role with specific name to the user with usedId.
 /// </summary>
 /// <param name="roleName"></param>
 /// <param name="userId"></param>
 public void AddRoleToUser(string roleName, int userId)
 {
     var user = _userDb.Users.SingleOrDefault(u => u.UserId == userId);
     var role = GetRoleByName(roleName);
     if (role == null)
     {
         role = new Role {RoleName = roleName};
         AddRole(role);
     }
     role.Users.Add(user);
 }
示例#2
0
        public ActionResult Create(Role role)
        {
            if (ModelState.IsValid)
            {
                db.Roles.Add(role);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(role);
        }
示例#3
0
 /// <summary>
 /// Adds a new role to the database.
 /// </summary>
 /// <param name="roleName">Name of role to be added.</param>
 public void AddRoleWidthName(string roleName)
 {
     var role = new Role { RoleName = roleName };
     AddRole(role);
 }
示例#4
0
 /// <summary>
 /// Adds a new role to the database.
 /// </summary>
 /// <param name="role">Role to be added.</param>
 public void AddRole(Role role)
 {
     if (GetRoleByName(role.RoleName) != null) throw new AddRoleException(string.Format("User with name {0} already exists.", role.RoleName));
     _userDb.Roles.Add(role); //EFCodeFirst
 }
示例#5
0
 /// <summary>
 /// Removes the role from the database.
 /// </summary>
 /// <param name="role">Role to be removed.</param>
 public void RemoveRole(Role role)
 {
     _userDb.Roles.Remove(role); //EFCodeFirst
 }
示例#6
0
 public ActionResult Edit(Role role)
 {
     if (ModelState.IsValid)
     {
         db.Entry(role).State = EntityState.Modified;
         db.SaveChanges();
         return RedirectToAction("Index");
     }
     return View(role);
 }