I made a table of users, however I use helper
to insert the same user in aspnetuser
also, so I save a user I create a permission in both, how do I edit the permission of that?
public async Task<ActionResult> Edit([Bind(Include = "UserId,UserName,FirstName,LastName,Analista,Parceiro,Vendedor")] User user, string rolename)
{
if (ModelState.IsValid)
{
var db2 = new MacPartnerContext();
var currentUser = db2.Users.Find(user.UserId);
if (currentUser.UserName != user.UserName)
{ if (user.Analista)
{
UserHelper.UpRoleToUser(user.UserName, "Analista");
}
if (user.Parceiro)
{
UserHelper.UpRoleToUser(user.UserName, "Parceiro");
}
if (user.Vendedor)
{
UserHelper.UpRoleToUser(user.UserName, "Vendedor");
}
UserHelper.UpdateUserName(currentUser.UserName, user.UserName);
}
db2.Dispose();
db.Entry(user).State = EntityState.Modified;
await db.SaveChangesAsync();
return RedirectToAction("Index");
}
return View(user);
}