Пример #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);
 }