/// <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); }
public ActionResult Create(Role role) { if (ModelState.IsValid) { db.Roles.Add(role); db.SaveChanges(); return RedirectToAction("Index"); } return View(role); }
/// <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); }
/// <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 }
/// <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 }
public ActionResult Edit(Role role) { if (ModelState.IsValid) { db.Entry(role).State = EntityState.Modified; db.SaveChanges(); return RedirectToAction("Index"); } return View(role); }