protected void btnUpdate_Click(object sender, EventArgs e) { if (userId == 0) { return; } try { UserInfo user = UserController.GetUser(userId); if (user == null) { return; } user.Address1 = txtAddress1.Text.Trim(); user.Address2 = txtAddress2.Text.Trim(); user.City = ConvertUtility.ToInt32(dropCity.SelectedValue); user.Country = ConvertUtility.ToInt32(dropCountry.SelectedValue); user.DisplayName = txtDisplayName.Text.Trim(); user.Email = txtEmail.Text; user.FirstName = txtFirstName.Text.Trim(); user.IsSuperAdmin = chkIsSuperAdmin.Checked; user.LastName = txtLastName.Text.Trim(); user.Mobile = txtMobile.Text.Trim(); user.Tel = txtTel.Text.Trim(); user.ZipCode = txtZipCode.Text.Trim(); user.PartnerID = 0;// ConvertUtility.ToInt32(dropPartner.SelectedValue); if (pnlSuperadmin.Visible) { user.IsSuperAdmin = chkIsSuperAdmin.Checked; } if (pnlAdmin.Visible) { user.IsAdmin = chkIsAdmin.Checked; } UserController.UpdateUser(user); foreach (ListItem item in lstPortal.Items) { if (item.Selected) { RoleController.AddUserToRole(user.UserID, AppEnv.DEFAULT_ROLE, Convert.ToInt32(item.Value)); } else { RoleController.RemoveUserFromRole(user.UserID, AppEnv.DEFAULT_ROLE, Convert.ToInt32(item.Value)); } } lblUpdateStatus.Text = MiscUtility.MSG_UPDATE_SUCCESS; } catch (Exception ex) { Response.Write(ex.Message); } }
public async Task AddUserToRole_NonExistingRole_ReturnsNotFoundObjectResult() { this.roleManagerMock.Setup(r => r.FindByNameAsync(It.IsAny <string>())).ReturnsAsync((ApplicationRole)null); this.localizationMock.SetupGet(x => x.GetLocalizer <RoleController>()[Moq.It.IsAny <string>()]).Returns(new LocalizedString("sometext", "sometext")); var controller = new RoleController(this.roleManagerMock.Object, this.userManagerMock.Object, this.localizationMock.Object, this.mapperMock.Object); var response = await controller.AddUserToRole("testrole", "testuser").ConfigureAwait(false); Assert.IsAssignableFrom <NotFoundObjectResult>(response); }
public async Task AddUserToRole_AddToRoleIsSuccessful_ReturnsOkResult() { var user = new ApplicationUser(); this.roleManagerMock.Setup(r => r.FindByNameAsync(It.IsAny <string>())).ReturnsAsync(new ApplicationRole()); this.userManagerMock.Setup(u => u.FindByNameAsync(It.IsAny <string>())).ReturnsAsync(user); this.userManagerMock.Setup(u => u.AddToRoleAsync(user, It.IsAny <string>())).ReturnsAsync(IdentityResult.Success); this.localizationMock.SetupGet(x => x.GetLocalizer <RoleController>()[Moq.It.IsAny <string>()]).Returns(new LocalizedString("sometext", "sometext")); var controller = new RoleController(this.roleManagerMock.Object, this.userManagerMock.Object, this.localizationMock.Object, this.mapperMock.Object); var result = await controller.AddUserToRole(null, null).ConfigureAwait(false); Assert.IsAssignableFrom <OkResult>(result); }
public async Task AddUserToRole_NonExistingUser_ReturnsBadRequestObjectResult() { this.roleManagerMock.Setup(r => r.FindByNameAsync(It.IsAny <string>())).ReturnsAsync(new ApplicationRole()); this.localizationMock.SetupGet(x => x.GetLocalizer <RoleController>()[Moq.It.IsAny <string>()]).Returns(new LocalizedString("sometext", "sometext")); var controller = new RoleController(this.roleManagerMock.Object, this.userManagerMock.Object, this.localizationMock.Object, this.mapperMock.Object); var ex = await Record.ExceptionAsync(() => controller.AddUserToRole("testrole", "testuser")).ConfigureAwait(false); Assert.IsAssignableFrom <OneFrameWebException>(ex); var oneFrameWebException = ex as OneFrameWebException; Assert.Equal(expected: oneFrameWebException.HttpStatusCode.ToString(), actual: Convert.ToInt32(HttpStatusCode.BadRequest).ToString()); }
public async Task AddUserToRole_AddToRoleIsFailed_ReturnsBadRequestObjectResult() { var user = new ApplicationUser(); this.roleManagerMock.Setup(r => r.FindByNameAsync(It.IsAny <string>())).ReturnsAsync(new ApplicationRole()); this.userManagerMock.Setup(u => u.FindByNameAsync(It.IsAny <string>())).ReturnsAsync(user); this.userManagerMock.Setup(u => u.AddToRoleAsync(user, It.IsAny <string>())).ReturnsAsync(IdentityResult.Failed()); var controller = new RoleController(this.roleManagerMock.Object, this.userManagerMock.Object, this.localizationMock.Object, this.mapperMock.Object); var ex = await Record.ExceptionAsync(() => controller.AddUserToRole("testrole", "testuser")).ConfigureAwait(false); Assert.IsAssignableFrom <OneFrameWebException>(ex); var oneFrameWebException = ex as OneFrameWebException; Assert.Equal(expected: oneFrameWebException.HttpStatusCode.ToString(), actual: Convert.ToInt32(HttpStatusCode.BadRequest).ToString()); }
protected void btnUpdate_Click(object sender, EventArgs e) { if (Page.IsValid) { try { int userId = ConvertUtility.ToInt32(Request.QueryString["uid"]); UserInfo user = new UserInfo(); user.Username = txtUsername.Text.Trim(); user.DisplayName = txtDisplayName.Text.Trim(); user.IsAdmin = chkIsAdmin.Checked; user.IsSuperAdmin = chkIsSuperAdmin.Checked; user.MaSo = txtMaSo.Text.Trim(); user.HoTen = txtFullName.Text.Trim(); user.NgaySinh = ConvertUtility.ToDateTime(txtNgaySinh.Text.Trim()); user.GioiTinh = ConvertUtility.ToInt32(dropGioiTinh.SelectedValue); user.IDChucVu = ConvertUtility.ToInt32(dropChucVu.SelectedValue); user.IDTrungTam = ConvertUtility.ToInt32(dropTrungTam.SelectedValue); user.IDPhong = ConvertUtility.ToInt32(dropPhong.SelectedValue); user.NoiSinh = txtNoiSinh.Text.Trim(); user.NguyenQuan = txtNguyenQuan.Text.Trim(); user.QuocTich = txtQuocTich.Text.Trim(); user.DanToc = txtDanToc.Text.Trim(); user.TonGiao = txtTonGiao.Text.Trim(); user.DiaChiThuongChu = txtDiaChiThuongChu.Text.Trim(); user.DiaChiTamChu = txtDiaChiTamChu.Text.Trim(); user.TrangThai = ConvertUtility.ToInt32(dropTrangThai.SelectedValue); if (userId > 0) { user.UserID = userId; UserController.UpdateUser(user); lblUpdateStatus.Text = MiscUtility.MSG_UPDATE_SUCCESS; } else { if (txtPassword.Text.Trim() != txtPasswordConfirm.Text.Trim()) { return; } user.Password = SecurityMethod.MD5Encrypt(txtPassword.Text.Trim()); userId = UserController.AddUser(user); if (userId > 0) { RoleController.AddUserToRole(userId, AppEnv.DEFAULT_ROLE, AppEnv.PortalId()); Response.Redirect(AppEnv.AdminUrlParams("createuser") + "&uid=" + userId); } else { lblUpdateStatus.Text = "Tên đăng nhập lại đã tồn tại."; } } } catch (Exception ex) { lblUpdateStatus.Text = ex.Message; } } }