Sorry if double, but the answer is to find and failed.
It looks like my code create a group on the forum:
public async Task<ActionResult> Create(ForumGroups fg)
{
if (ModelState.IsValid)
{
ApplicationUser user = ad.Users.Where(m => m.UserName == HttpContext.User.Identity.Name).FirstOrDefault();
db.Organizations.Add(fg);
db.SaveChanges();
await RoleManager.CreateAsync(new ApplicationRole { Name = string.Format("GroupAdministrator{0}", organization.Id) });
await UserManager.AddToRoleAsync(user.Id, string.Format("GroupAdministrator{0}", organization.Id));
return RedirectToAction("Index");
}
return View(fg);
}
The role is created fine but the problem is that the access to the newly created forum does not appear immediately. Taking inventory is standard here such code:
@if (Request.IsAuthenticated && User.IsInRole(string.Format("GroupAdministrator{0}", Model.Id)))
{
<h4>Administrator</h4>
<p>
@Html.ActionLink("Edit", "Edit", new { id = Model.Id }) |
@Html.ActionLink("Back to List", "Index")
</p>
}
How to make so when you create a group, the user will instantly have access to it ?