public ActionResult RoleAddToUser(AssignRoleVM objvm) { if (objvm.RoleName == "0") { ModelState.AddModelError("RoleName", "Please select RoleName"); } if (objvm.UserName == "0") { ModelState.AddModelError("UserName", "Please select Username"); } if (ModelState.IsValid) { if (objIAccountData.Get_CheckUserRoles(objvm.UserName) == true) { ViewBag.ResultMessage = "This user already has the role specified !"; } else { var UserName = objIAccountData.GetUserName_BY_UserID(objvm.UserName); Roles.AddUserToRole(UserName, objvm.RoleName); ViewBag.ResultMessage = "Username added to the role succesfully !"; } objvm.RolesList = GetAll_Roles(); objvm.Userlist = GetAll_Users(); return(View(objvm)); } else { objvm.RolesList = GetAll_Roles(); objvm.Userlist = GetAll_Users(); ModelState.AddModelError("Error", "Please enter Username and Password"); } return(View(objvm)); }
public ActionResult RoleAddToUser(AssignRoleVM objvm) { if (objvm.RoleName == "0") { ModelState.AddModelError("RoleName", "Favor Seleccione Nombre de Rol"); } if (objvm.UserName == "0") { ModelState.AddModelError("UserName", "Favor Seleccione el Nombre de Usuario"); } if (ModelState.IsValid) { if (objIAccountData.Get_CheckUserRoles(objvm.UserName) == true) { ViewBag.ResultMessage = "Este Usuario ya Tiene el Rol Especificado!"; } else { var UserName = objIAccountData.GetUserName_BY_UserID(objvm.UserName); Roles.AddUserToRole(UserName, objvm.RoleName); ViewBag.ResultMessage = "¡Nombre de Usuario Agregado Con Éxito!"; } objvm.RolesList = GetAll_Roles(); objvm.Userlist = GetAll_Users(); return(View(objvm)); } else { objvm.RolesList = GetAll_Roles(); objvm.Userlist = GetAll_Users(); ModelState.AddModelError("Error", "Por favor, Introduzca el Nombre de Usuario y la Contraseña"); } return(View(objvm)); }