protected override void btnSave_Click(object sender, EventArgs e) { List <cmsUserRole> ls = new List <cmsUserRole>(); foreach (ListItem item in cblRoles.Items) { if (item.Selected) { cmsUserRole ur = new cmsUserRole(); ur.UserId = Convert.ToInt64(id); ur.RoleId = Convert.ToInt64(item.Value); ls.Add(ur); } } int r = 0; try { r = urs.Add(Convert.ToInt64(id), ls); ScriptUtil.AlertAndCloseDialog("角色分配成功!"); } catch (Exception ex) { ScriptUtil.Alert("服务器发生未知错误!"); Logger.Error(ex.Message); } }
public ActionResult Create(UserRole model) { try { service.Add(model); } catch (Exception ex) { //return View(); Success = false; Message = ex.Message; } return(EasyUIResult()); }
public void UserRoleService_Add() { UserRoleService service = new UserRoleService(mockRepository.Object, mockMapper.Object); UserRole role = new UserRole() { UserRoleId = 1, UserId = 1, ModifiedDate = DateTime.Now, IsActive = 1, ModifiedUser = "******" }; bool result = service.Add(role); Assert.IsFalse(result); }
public ActionResult UserAuthorizationEdit(int userId, AuthorizationModel authorizationModel) { try { var oldUserRoles = UserRoleService.GetAll(userId); foreach (var authorization in oldUserRoles) { UserRoleService.Delete(authorization.Id); } var userModules = authorizationModel.UserModules?.ToList(); if (userModules != null) { foreach (var item in userModules) { var a = new UserRole { ModuleId = item, UserId = userId }; UserRoleService.Add(a); } } var userRoles = authorizationModel.UserRoles?.ToList(); if (userRoles != null) { foreach (var item in userRoles) { var a = new UserRole { RoleId = item, UserId = userId }; UserRoleService.Add(a); } } } catch (Exception e) { Logger.Error("Hata oluştu - " + new StackTrace().GetFrame(0).GetMethod().Name, e); } return(RedirectToAction("UserList")); }
public User Add(User user) { if (user != null) { //INSERT INTO users OUTPUT INSERTED.* VALUES ('aaaa', 'asdsdad', 1) sqlCommand.CommandText = "INSERT INTO users VALUES(@user_name, @password, @state)"; sqlCommand.Parameters.AddWithValue("@user_name", user.Username); sqlCommand.Parameters.AddWithValue("@password", new PasswordHasher().HashPassword(user.Password));// new PasswordHasher().HashPassword(model.Password)); sqlCommand.Parameters.AddWithValue("@state", State.ACTIVO); try { Connection.Open(); if (_roleService.Find(user.roleId) == null) { return(null); } int result = sqlCommand.ExecuteNonQuery(); if (result > 0) { user.Id = GetInsert(); Console.WriteLine(user.Id); if (_roleUserService.Add(new RoleUser(user.roleId, user.Id)) == null) { return(null); } return(user); } return(null); } catch (Exception e) { Console.WriteLine(e.Message); Connection.Close(); return(null); } } return(null); }
public void Post(ViewModels.UserRoleEditViewModel model) { UserRoleService.Add(model); }
public ActionResult UserEdit(int UserId, AccountModel accountModel) { try { GenarateCommonModel(accountModel); if (accountModel.CaptchaStatus == "Her Zaman Aktif" || (accountModel.CaptchaStatus == "Hatalı Girişte Aktif" && accountModel.HasError)) { if (!GoogleReCaptchaHelper.IsValidCaptcha()) { accountModel.HasError = true; accountModel.ErrorMessage = "Kutuyu işaretlemeniz gerekmektedir."; return(View(accountModel)); } } try { if (UserId == 0) { var Email = accountModel.User.Email; var authUser = UserService.GetByEmail(Email); if (authUser == null) { var registerUser = new User(); if (accountModel.User.Password != accountModel.PasswordConfirmation) { accountModel.HasError = true; accountModel.ErrorMessage = "Şifreler uyuşmuyor."; accountModel.PasswordConfirmation = string.Empty; return(View(accountModel)); } registerUser.FullName = accountModel.User.FullName; registerUser.Email = accountModel.User.Email; registerUser.Password = md5Helper.GetMD5_2(accountModel.User.Password); registerUser.Adress = accountModel.User.Adress; registerUser.PhoneNumber = PhoneMaskHelper.FormatPhoneNumber(accountModel.User.PhoneNumber); registerUser.MailPermission = accountModel.User.MailPermission; registerUser.IsActive = accountModel.User.IsActive; registerUser.IsAdmin = accountModel.User.IsAdmin; registerUser.CompanyName = accountModel.User.CompanyName; registerUser.TCKN = accountModel.User.TCKN; registerUser.IsTestUser = false; registerUser.MailConfirmation = true; UserService.Add(registerUser); var userGroup = RoleService.GetByName("Standart Kullanıcı"); if (userGroup != null) { UserRoleService.Add(new UserRole { RoleId = userGroup.Id, UserId = registerUser.Id, IsActive = true, IsDeleted = false }); } return(View(accountModel)); } else { accountModel.HasError = true; accountModel.ErrorMessage = "Bu E-Mail " + accountModel.SiteHeader + " Portal'ine daha önceden kayıt yaptırmıştır."; return(View(accountModel)); } } else { var authUser = UserService.Get(UserId); if (authUser != null) { var userOther = UserService.GetByEmail(accountModel.User.Email); if (userOther != null && userOther.Id != authUser.Id) { accountModel.HasError = true; accountModel.ErrorMessage = "E-Mail Adresi Uyngun Değil!"; return(View(accountModel)); } authUser.FullName = accountModel.User.FullName; authUser.Password = md5Helper.GetMD5_2(accountModel.User.Password); authUser.PhotoPath = accountModel.User.PhotoPath; authUser.Adress = accountModel.User.Adress; authUser.PhoneNumber = PhoneMaskHelper.FormatPhoneNumber(accountModel.User.PhoneNumber); authUser.CompanyName = accountModel.User.CompanyName; authUser.TCKN = accountModel.User.TCKN; authUser.MailPermission = accountModel.User.MailPermission; authUser.IsActive = accountModel.User.IsActive; authUser.IsAdmin = accountModel.User.IsAdmin; authUser.IsTestUser = false; authUser.MailConfirmation = true; authUser.Email = accountModel.User.Email; UserService.Update(authUser); return(View(accountModel)); } else { accountModel.HasError = true; accountModel.ErrorMessage = "Hata Oluştu."; return(View(accountModel)); } } } catch (Exception e) { Logger.Error("Hata oluştu - " + new StackTrace().GetFrame(0).GetMethod().Name, e); return(View(accountModel)); } } catch (Exception e) { Logger.Error("Hata oluştu - " + new StackTrace().GetFrame(0).GetMethod().Name, e); return(View(accountModel)); } }