public bool AddUserForRole(int roleId, int userId) { UserRoleManager userRoleManager = new UserRoleManager(); WXQ.Enties.UserRole rm = new Enties.UserRole { UserId = userId, RoleId = roleId, AddDateTime = DateTime.Now, AddUser = this.OpUserId.ToString() }; return(userRoleManager.Insert(rm)); }
public ActionResult EditUser(EditUserViewModel model) { if (ModelState.IsValid) { Guid roleId; switch (model.RoleId) { case 1: roleId = _roleManager.GetUserRoleId(); break; case 2: roleId = _roleManager.GetAuthorUserRoleId(); break; case 3: roleId = _roleManager.GetAdminRoleId(); break; default: return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } UserRole userRole = new UserRole() { AppUserId = model.UserId, AppRoleId = roleId }; BusinessLayerResult <UserRole> res = _userRoleManager.Insert(userRole); if (res.Errors.Count > 0) { // başarısız res.Errors.ForEach(x => ModelState.AddModelError("", x.Message)); } else { // başarılı return(RedirectToAction("EditUser", "SystemTool", new { @userId = model.UserId })); } } var user = _userManager.Find(x => x.Id == model.UserId); model.UserRoles = user.UserRoles; List <SelectListItem> RoleListId = new List <SelectListItem>() { new SelectListItem() { Text = "Kullanıcı", Value = "1" }, new SelectListItem() { Text = "Yazar", Value = "2" }, new SelectListItem() { Text = "Yönetici", Value = "3" } }; ViewBag.RoleId = new SelectList(RoleListId, "Value", "Text", model.RoleId); return(View(model)); }