public override void AddUsersToRoles(string[] usernames, string[] roleNames) { using (var db = new DataAccess.CSSDataContext()) { foreach (string username in usernames) { DataAccess.Login login = db.Logins.FirstOrDefault(p => p.Username == username.Trim()); if (login != null) { foreach (string roleName in roleNames) { DataAccess.Role role = db.Roles.FirstOrDefault(p => p.Name == roleName.Trim()); if (login.Login_Roles.Count(p => p.LoginId == login.Id && p.RoleId == role.Id) > 0) { continue; } db.Login_Roles.InsertOnSubmit(new DataAccess.Login_Role() { Login = login, LoginId = login.Id, Role = role, RoleId = role.Id }); } } } db.SubmitChanges(); } }
void LoadRecords() { dgDetails.Rows.Clear(); oRole = new DataAccess.Role(); foreach (DataRow row in oRole.GetRole("", "").Rows) { dgDetails.Rows.Add(row[0], row[1], row[2]); } }
void LoadRole() { oRole = new DataAccess.Role(); cboRole.Items.Clear(); cboRole.DataSource = oRole.GetRole("", ""); cboRole.DisplayMember = "ROLE"; cboRole.ValueMember = "ROLE"; cboRole.Text = string.Empty; }
public DTO.Role CreateRole(DataAccess.Role role, bool includeOnlyActive = true) { CheckHelper.ArgumentNotNull(role, "role"); CheckHelper.ArgumentWithinCondition(!role.IsNew(), "!role.IsNew()"); return (_dtoCache.Get( role, r => new DTO.Role { Id = r.Id, Name = r.Name })); }
public void LoadRole() { try { oRole = new DataAccess.Role(); dgDetails.Rows.Clear(); eVariable.DisableGridColumnSort(dgDetails); foreach (DataRow row in oRole.GetRole("", "").Rows) { dgDetails.Rows.Add(row[0], row[1], row[2]); } } catch (Exception ex) { } }
public ActionResult Create(CreateEditViewModel model) { var role = new DataAccess.Role(); mapper.Map(model, role); try { securityProvider.AddRole(role); } catch (Exception ex) { return(HandleException(ex)); } var jsonViewModel = new AjaxViewModel(true, model, null); return(Json(jsonViewModel)); }
/// <summary> /// /// </summary> /// <param name="p"></param> /// <returns></returns> public override bool Save(DataAccess.Role p) { if (string.IsNullOrEmpty(p.Id)) { p.Id = null; DbManager.Roles.InsertOne(new Role() { RoleName = p.RoleName, Description = p.Description }); p.Id = DbManager.Roles.Find(r => r.RoleName == p.RoleName && r.Description == p.Description).FirstOrDefault().Id; } else { DbManager.Roles.UpdateOne(md => md.Id == p.Id, Builders <Role> .Update.Set(md => md.RoleName, p.RoleName).Set(md => md.Description, p.Description)); } return(true); }
private void btnSave_Click(object sender, EventArgs e) { oMRole = new Model.Role(); oRole = new DataAccess.Role(); if (IsRecordEmpty()) { oFrmMsgBox = new frmMessageBox(eVariable.TransactionMessage.ALL_FIELDS_ARE_REQUIRED.ToString().Replace("_", " ")); oFrmMsgBox.m_MessageType = frmMessageBox.MESSAGE_TYPE.INFO; oFrmMsgBox.ShowDialog(); return; } if (eVariable.m_ActionType == eVariable.ACTION_TYPE.EDIT) { oMRole.ID = eVariable.sUniqueID; oMRole.ROLE = txtRole.Text; oMRole.STATUS = chkActive.Checked == true ? "ACTIVE" : "INACTIVE"; oRole.UpdateRole(oMRole); } else { oMRole.ROLE = txtRole.Text; oMRole.STATUS = chkActive.Checked == true ? "ACTIVE" : "INACTIVE"; if (oRole.isRecordExists(oMRole)) { oFrmMsgBox = new frmMessageBox(eVariable.TransactionMessage.RECORD_IS_ALREADY_EXISTS.ToString().Replace("_", " ")); oFrmMsgBox.m_MessageType = frmMessageBox.MESSAGE_TYPE.INFO; oFrmMsgBox.ShowDialog(); return; } oRole.InsertRole(oMRole); } oFrmMsgBox = new frmMessageBox(eVariable.TransactionMessage.RECORD_HAS_BEEN_SUCESSFULLY_SAVED.ToString().Replace("_", " ")); oFrmMsgBox.m_MessageType = frmMessageBox.MESSAGE_TYPE.INFO; oFrmMsgBox.ShowDialog(); eVariable.ClearText(pnlBody); eVariable.m_ActionType = eVariable.ACTION_TYPE.ADD; LoadRole(); }