public RoleDetailDTO GetDetail(string ID) { RoleDetailDTO item = new RoleDetailDTO(); try { GetRoleDetailRequest paraBody = new GetRoleDetailRequest(); paraBody.ID = ID; NSLog.Logger.Info("Permission Get Detail Request", paraBody); var result = (NSApiResponse)ApiResponse.Post <NSApiResponse>(Commons.PermissionAPIGetDetail, null, paraBody); NSLog.Logger.Info("Permission Get Detail Response", paraBody); dynamic data = result.Data; var lstDataRaw = data["RoleDetail"]; var lstObject = JsonConvert.SerializeObject(lstDataRaw); item = JsonConvert.DeserializeObject <RoleDetailDTO>(lstObject); NSLog.Logger.Info("RoleGetDetail", item); return(item); } catch (Exception e) { NSLog.Logger.Error("RoleGetDetail_Fail", e); return(item); } }
public ActionResult Create() { RoleDetailDTO model = new RoleDetailDTO(); GetListModule(model); model.Level = CurrentUser.RoleLevel + 1; model.IsActive = true; return(View(model)); }
public void tblRoleDetail_insert(RoleDetailDTO dt) { string sql = "INSERT INTO tblRoleDetail(roleId, departmentId) " + "VALUES(@roleId, @departmentId)"; SqlCommand cmd = new SqlCommand(sql, ConnectionData._MyConnection); cmd.CommandType = CommandType.Text; cmd.Parameters.Add("@roleId", SqlDbType.Int).Value = dt.roleId; cmd.Parameters.Add("@departmentId", SqlDbType.Int).Value = dt.departmentId; cmd.ExecuteNonQuery(); cmd.Dispose(); }
public RoleDetailDTO GetDetail(string id) { try { RoleDetailDTO model = _factory.GetDetail(id); return(model); } catch (Exception ex) { NSLog.Logger.Error("PermissionsDetail: ", ex); return(null); } }
public override object BuildDetail(EntityDTO dto) { RoleDetailDTO detail = new RoleDetailDTO(); EntityData data = new EntityData(); EntityDTO description = data.GetRoleDetail(dto.ID); description.ExtractProperties(); detail.Responsibilities = description.RenderHTML(GlobalStringResource.Responsibilities, RenderOption.Break); detail.Description = BuildDescription(dto); detail.ReferencedDocuments = BuildReferencedDocuments(dto); return(detail); }
public void tblRoleDetail_insert(RoleDetailDTO dt) { string sql = "INSERT INTO tblRoleDetail(roleId, departmentId, limitSendMail, limitCreateCustomer, toDate) " + "VALUES(@roleId, @departmentId, @limitSendMail, @limitCreateCustomer, @toDate)"; SqlCommand cmd = new SqlCommand(sql, ConnectionData._MyConnection); cmd.CommandType = CommandType.Text; cmd.Parameters.Add("@roleId", SqlDbType.Int).Value = dt.roleId; cmd.Parameters.Add("@departmentId", SqlDbType.Int).Value = dt.departmentId; cmd.Parameters.Add("@limitSendMail", SqlDbType.Int).Value = dt.limitSendMail; cmd.Parameters.Add("@limitCreateCustomer", SqlDbType.Int).Value = dt.limitCreateCustomer; cmd.Parameters.Add("@toDate", SqlDbType.DateTime).Value = dt.toDate; cmd.ExecuteNonQuery(); cmd.Dispose(); }
public async Task <RoleDetailDTO> ScreenPermission(Guid?roleId) { List <SitePermissionsDTO> sitePermissionsDTOList = new List <SitePermissions.DTO.SitePermissionsDTO>(); RoleService roleService = new RoleService(); RoleDetailDTO roledto = new RoleDetailDTO(); roledto.Role = new DTO.RoleDTO(); roledto.PermissionMasterList = new List <SitePermissionsDTO>(); roledto.SiteMapRolePermissionList = new List <SiteMapRolePermission>(); roledto.SitemapMasterList = new List <SitemapMaster>(); roledto.Role = await roleService.GetRole(roleId ?? Guid.Empty); roledto.SitemapMasterList = await db.SitemapMasters.ToListAsync(); var sitePermissionList = await(from permission in db.PermissionMasters join permisionSite in db.SitemapPermissionMaps on permission.Id equals permisionSite.PermissionId join sitemap in db.SitemapMasters on permisionSite.SiteMapId equals sitemap.Id select new { permission.Id, permission.Name, permission.DisplayOrder, permisionSite.SiteMapId, permisionSite.IsVisisble, }).Distinct().OrderBy(o => o.DisplayOrder).ToListAsync(); foreach (var item in sitePermissionList) { SitePermissionsDTO sitePermissionsDTO = new SitePermissionsDTO(); sitePermissionsDTO.Id = item.Id; sitePermissionsDTO.Name = item.Name; sitePermissionsDTO.IsVisisble = item.IsVisisble ?? false; sitePermissionsDTO.SiteMapId = item.SiteMapId ?? Guid.Empty; sitePermissionsDTOList.Add(sitePermissionsDTO); } roledto.PermissionMasterList = sitePermissionsDTOList; roledto.SiteMapRolePermissionList = await db.SiteMapRolePermissions.ToListAsync(); return(roledto); }
public ActionResult Create(RoleDetailDTO model) { try { //if (!model.BType) //{ // if (model.Value < 0 || model.Value > 100) // { // ModelState.AddModelError("Value","Value must between 0 and 100"); // } //} if (model.Level <= CurrentUser.RoleLevel) { ModelState.AddModelError("Level", "The level of role must be > " + CurrentUser.RoleLevel); } if (!ModelState.IsValid) { Response.StatusCode = (int)HttpStatusCode.BadRequest; return(View("Create", model)); } string msg = ""; bool result = _factory.CreateOrEdit(model, CurrentUser.UserId, ref msg); if (result) { return(RedirectToAction("Index")); } else { //return RedirectToAction("Create"); ModelState.AddModelError("Name", msg); return(View(model)); } } catch (Exception ex) { NSLog.Logger.Error("PermissionCreate: ", ex); return(new HttpStatusCodeResult(400, ex.Message)); } }
public ActionResult Delete(RoleDetailDTO model) { try { string msg = ""; var result = _factory.Delete(model.ID, CurrentUser.UserId, ref msg); if (!result) { ModelState.AddModelError("Name", msg); Response.StatusCode = (int)HttpStatusCode.BadRequest; return(PartialView("_Delete", model)); } return(new HttpStatusCodeResult(HttpStatusCode.OK)); } catch (Exception ex) { NSLog.Logger.Error("PermissionDelete: ", ex); ModelState.AddModelError("Name", "Have an error when you delete a Permission"); Response.StatusCode = (int)HttpStatusCode.BadRequest; return(PartialView("_Delete", model)); } }
public ActionResult Edit(RoleDetailDTO model) { try { if (string.IsNullOrEmpty(model.Name)) { ModelState.AddModelError("Name", "Permission Name is required"); } if (model.Level <= CurrentUser.RoleLevel) { ModelState.AddModelError("Level", "The level of role must be > " + CurrentUser.RoleLevel); } if (!ModelState.IsValid) { Response.StatusCode = (int)HttpStatusCode.BadRequest; return(PartialView("_Edit", model)); } //==================== string msg = ""; var result = _factory.CreateOrEdit(model, CurrentUser.UserId, ref msg); if (result) { return(RedirectToAction("Index")); } else { ModelState.AddModelError("Name", msg); Response.StatusCode = (int)HttpStatusCode.BadRequest; return(PartialView("_Edit", model)); } } catch (Exception ex) { NSLog.Logger.Error("PermissionEdit: ", ex); return(new HttpStatusCodeResult(400, ex.Message)); } }
public bool CreateOrEdit(RoleDetailDTO model, string userId, ref string msg) { try { CreateOrEditRoleRequest paraBody = new CreateOrEditRoleRequest(); paraBody.RoleDetail = model; paraBody.CreatedUser = userId; //==================== NSLog.Logger.Info("Permission Create Or Edit Request", paraBody); var result = (NSApiResponse)ApiResponse.Post <NSApiResponse>(Commons.PermissionAPICreateOrEdit, null, paraBody); NSLog.Logger.Info("Permission Create Or Edit Response", paraBody); if (result != null) { if (result.Success) { return(true); } else { msg = result.Message; NSLog.Logger.Info("PermissionCreateOrEdit", result.Message); return(false); } } else { NSLog.Logger.Info("PermissionCreateOrEdit", result); return(false); } } catch (Exception e) { NSLog.Logger.Error("PermissionCreateOrEdit_Fail", e); return(false); } }
//private UserLoginDTO getUserLogin() //{ // if (Session["us-login"] != null) // { // return (UserLoginDTO)Session["us-login"]; // } // else Response.Redirect("~");//test confict // return null; //} protected void lbtSubmit_Click(object sender, EventArgs e) { DataTable table = null; DataTable tableStatus = null; int clienID = 0; int status = 0; try { String user = txtUsername.Text; string en_pass = Common.GetMd5Hash(txtPassword.Text.Trim()); ConnectionData.OpenMyConnection(); DataTable tbResult = ulBus.GetByUsernameAndPass(user, en_pass); if (tbResult.Rows.Count > 0) { UserLoginDTO userLogin = new UserLoginDTO(); userLogin.UserId = int.Parse(tbResult.Rows[0]["UserId"].ToString()); userLogin.Username = tbResult.Rows[0]["Username"].ToString(); userLogin.Password = tbResult.Rows[0]["Password"].ToString(); userLogin.DepartmentId = int.Parse(tbResult.Rows[0]["DepartmentId"].ToString()); userLogin.UserType = int.Parse(tbResult.Rows[0]["UserType"].ToString()); if (userLogin.UserType == 3) { table = ulBus.GetClientIdSub(userLogin.UserId); clienID = int.Parse(table.Rows[0]["clientId"].ToString()); tableStatus = ulBus.GetClientId(clienID); status = int.Parse(tableStatus.Rows[0]["Status"].ToString()); } else if (userLogin.UserType == 0) { status = 0; } else if (userLogin.UserType != 0 && userLogin.UserType != 3) { tableStatus = ulBus.GetClientId(userLogin.UserId); status = int.Parse(tableStatus.Rows[0]["Status"].ToString()); } if (status == 0) { try { userLogin.hasSendMail = int.Parse(tbResult.Rows[0]["hasSendMail"].ToString()); } catch (Exception) { userLogin.hasSendMail = 0; } int hasCreatedCustomer = Common.countHasCreateMailByUserId(int.Parse(tbResult.Rows[0]["UserId"].ToString())); userLogin.hasCreatedCustomer = hasCreatedCustomer; // Tạo session user login Session["us-login"] = userLogin; Session["UserName"] = userLogin.Username; Session["UserId"] = userLogin.UserId; // Kiểm tra user này có thuộc phân quyền nâng cao hay không DataTable tblRoleDetail = rdBus.GetByDepartmentIdAndRole(-1, userLogin.DepartmentId); if (tblRoleDetail.Rows.Count > 0) { RoleDetailDTO rdDto = new RoleDetailDTO(); rdDto.roleId = int.Parse(tblRoleDetail.Rows[0]["roleId"].ToString()); rdDto.departmentId = int.Parse(tblRoleDetail.Rows[0]["departmentId"].ToString()); rdDto.limitSendMail = int.Parse(tblRoleDetail.Rows[0]["limitSendMail"].ToString()); rdDto.limitCreateCustomer = int.Parse(tblRoleDetail.Rows[0]["limitCreateCustomer"].ToString()); rdDto.toDate = DateTime.Parse(tblRoleDetail.Rows[0]["toDate"].ToString()); // Tạo session limit Session["limitWithUser"] = rdDto; } logs_info.Info("user login: "******"ID"] = 25; if (userLogin.UserType == 0) Response.Redirect("clientregister.aspx", false); else Response.Redirect("mail-send.aspx", false); } else if (status == -1) { pnError.Visible = true; lblMessage.Text = "Tài khoản đăng nhập chưa kích hoạt."; logs.Error("user not active: " + userLogin.Username); } else { pnError.Visible = true; lblMessage.Text = "Tài khoản đăng nhập đã bị khóa."; logs.Error("user locked: " + userLogin.Username); } } else { pnError.Visible = true; lblMessage.Text = "Email hoặc mật khẩu không đúng."; logs.Error("user worng: " + txtUsername.Text); } } catch (ThreadAbortException ex) { pnError.Visible = true; lblMessage.Text = ex.Message; logs.Error("user login exception: " + txtUsername.Text, ex); } finally { //ConnectionData.CloseMyConnection(); } }
public int tblRoleDetail_update(RoleDetailDTO dt) { string sql = "Update tblRoleDetail set "; sql += "limitSendMail = @limitSendMail, limitCreateCustomer = @limitCreateCustomer, toDate = @toDate "; sql += "WHERE roleId = @roleId AND departmentId = @departmentId"; SqlCommand cmd = new SqlCommand(sql, ConnectionData._MyConnection); cmd.CommandType = CommandType.Text; cmd.Parameters.Add("@roleId", SqlDbType.Int).Value = dt.roleId; cmd.Parameters.Add("@departmentId", SqlDbType.Int).Value = dt.departmentId; cmd.Parameters.Add("@limitSendMail", SqlDbType.Int).Value = dt.limitSendMail; cmd.Parameters.Add("@limitCreateCustomer", SqlDbType.Int).Value = dt.limitCreateCustomer; cmd.Parameters.Add("@toDate", SqlDbType.DateTime).Value = dt.toDate; int rsUpdate = cmd.ExecuteNonQuery(); cmd.Dispose(); return rsUpdate; }
public new PartialViewResult View(string id) { RoleDetailDTO model = GetDetail(id); return(PartialView("_View", model)); }
public int tblRoleDetail_Update(RoleDetailDTO dt) { return rdDao.tblRoleDetail_update(dt); }
public void tblRoleDetail_insert(RoleDetailDTO dt) { rdDao.tblRoleDetail_insert(dt); }
public PartialViewResult Edit(string id) { RoleDetailDTO model = GetDetail(id); return(PartialView("_Edit", model)); }
protected void lbtChangeAdvance_Click(object sender, EventArgs e) { try { RoleDetailBUS rdBus = new RoleDetailBUS(); PanelAdvance.Visible = false; int departmentId = int.Parse(hdfDepartmentId.Value); int limitSendMail = int.Parse(txtLimitMailSend.Text); string toDate = txtToDate.Text; int limitCreateCustomer = int.Parse(txtLimitCreateCustomer.Text); if (chkAdvance.Checked) { // Cap nhat voi hang ngach gui mail, tao khach hang. RoleDetailDTO rdDto = new RoleDetailDTO(); rdDto.roleId = -1; rdDto.departmentId = departmentId; rdDto.limitSendMail = limitSendMail; rdDto.limitCreateCustomer = limitCreateCustomer; rdDto.toDate = convertStringToDate(toDate); ConnectionData.OpenMyConnection(); int rsUpdate = rdBus.tblRoleDetail_Update(rdDto); ConnectionData.CloseMyConnection(); if (rsUpdate <= 0) { // Them voi hang ngach gui mail, tao khach hang. ConnectionData.OpenMyConnection(); rdBus.tblRoleDetail_insert(rdDto); ConnectionData.CloseMyConnection(); } // Reset thong tin so luong da gui mail cua tat ca user trong group. UserLoginBUS ulBus = new UserLoginBUS(); ConnectionData.OpenMyConnection(); ulBus.tblUserLogin_UpdateByDepartmentId(departmentId, 0); ConnectionData.CloseMyConnection(); } else { // Xóa phân quyền nâng cao. ConnectionData.OpenMyConnection(); rdBus.tblRoleDetail_Delete(-1, departmentId); ConnectionData.CloseMyConnection(); } PanelAdvanceSuccess.Visible = true; lblAdvanceSuccess.Text = "Cập nhập thành công !"; } catch (Exception) { PanelAdvanceSuccess.Visible = false; PanelAdvance.Visible = true; lblAdvanceError.Text = "Kiểm tra lại dữ liệu nhập !"; } }
public PartialViewResult Delete(string id) { RoleDetailDTO model = GetDetail(id); return(PartialView("_Delete", model)); }
public void GetListModule(RoleDetailDTO model) { model.ListPermission = _factory.GetListModule(); }
protected void lbtChangeRole_Click(object sender, EventArgs e) { try { // Get role list by departmentId int departId = int.Parse(hdfDepartmentId.Value.ToString()); rdBus = new RoleDetailBUS(); DataTable dtOldRole = rdBus.GetByDepartmentId(departId); DataTable insertRole = new DataTable(); insertRole.Columns.Add("roleId", typeof(int)); //iterator to check new_role with old_role for (int i = 0; i < dlRoleList.Items.Count; i++) { CheckBox chkCheck = (CheckBox)dlRoleList.Items[i].FindControl("chkCheck"); HiddenField hdfRoleId = (HiddenField)dlRoleList.Items[i].FindControl("hdfRoleId"); if (chkCheck.Checked) { checkNewOldRole(dtOldRole, insertRole, int.Parse(hdfRoleId.Value)); } } //delete old role if (dtOldRole.Rows.Count > 0) { for (int j = 0; j < dtOldRole.Rows.Count; j++) { int roleId = int.Parse(dtOldRole.Rows[j]["roleId"].ToString()); ConnectionData.OpenMyConnection(); rdBus.tblRoleDetail_Delete(roleId, departId); ConnectionData.CloseMyConnection(); } } //insert new role if (insertRole.Rows.Count > 0) { for (int k = 0; k < insertRole.Rows.Count; k++) { int roleId = int.Parse(insertRole.Rows[k]["roleId"].ToString()); RoleDetailDTO rdDto = new RoleDetailDTO(); rdDto.roleId = roleId; rdDto.departmentId = departId; rdDto.limitSendMail = 0; // Set default value. rdDto.limitCreateCustomer = 0; // Set default value rdDto.toDate = DateTime.Now; // Set default value ConnectionData.OpenMyConnection(); rdBus.tblRoleDetail_insert(rdDto); ConnectionData.CloseMyConnection(); } } pnSuccess.Visible = true; pnError.Visible = false; lblSuccess.Text = "Đã thay đổi quyền thành công !"; } catch (Exception) { throw; } }