protected void InitializeCheckBox(int roleId)
 {
     RolesModuleAccess moduleAccess = new RolesModuleAccess();
     modalChkboxAll.Checked = false;
     for (int i = 0; i < gridViewModuleAccess.Rows.Count; i++)
     {
         CheckBox cbView = (CheckBox)gridViewModuleAccess.Rows[i].FindControl("chkBoxView");
         CheckBox cbAdd = (CheckBox)gridViewModuleAccess.Rows[i].FindControl("chkBoxAdd");
         CheckBox cbUpdate = (CheckBox)gridViewModuleAccess.Rows[i].FindControl("chkBoxUpdate");
         CheckBox cbDelete = (CheckBox)gridViewModuleAccess.Rows[i].FindControl("chkBoxDelete");
         Label labelModuleId = (Label)gridViewModuleAccess.Rows[i].FindControl("modalLabelModuleId");
         var data = moduleAccess.GetRolesModuleAccess(roleId, Convert.ToInt32(labelModuleId.Text));
         if (data != null)
         {
             if (data.CanAdd == true)
                 cbAdd.Checked = true;
             else
                 cbAdd.Checked = false;
             if (data.CanDelete == true)
                 cbDelete.Checked = true;
             else
                 cbDelete.Checked = false;
             if (data.CanUpdate == true)
                 cbUpdate.Checked = true;
             else
                 cbUpdate.Checked = false;
             if (data.CanView == true)
                 cbView.Checked = true;
             else
                 cbView.Checked = false;
             labelModuleId.ToolTip = data.Id.ToString();
         }
     }
 }
 protected void GetMyAccessRights()
 {
     int userid = Convert.ToInt32(Session["UserId"]);
     User user = new User();
     user = user.GetUser(userid);
     Module module = new Module();
     module = module.GetModule("SetupUserRate.aspx");
     myAccessRights = myAccessRights.GetRolesModuleAccess(Convert.ToInt32(user.RoleId), module.Id);
 }
 protected bool hasAccess(string modulename)
 {
     bool result = false;
     User user = new User();
     user = user.GetUser(Convert.ToInt32(HttpContext.Current.Session["UserId"]));
     Module module = new Module();
     var list = module.GetModuleList(Convert.ToInt32(user.RoleId),modulename);
     RolesModuleAccess moduleAccess = new RolesModuleAccess();
     if (list.Count > 0)
         result = true;
     return result;
 }
 protected void GetMyAccessRights()
 {
     int userid = Convert.ToInt32(Session["UserId"]);
     User user = new User();
     user = user.GetUser(userid);
     TimeTracker.Model.Module module = new TimeTracker.Model.Module();
     module = module.GetModule("ReportLaborCost.aspx");
     myAccessRights = myAccessRights.GetRolesModuleAccess(Convert.ToInt32(user.RoleId), module.Id);
 }
        protected void modalBtnSubmit_Command(object sender, CommandEventArgs e)
        {
            int roleId = Convert.ToInt32(modalDropDownRoles.SelectedItem.Value);
            RolesModuleAccess moduleAccess = new RolesModuleAccess();
            for (int i = 0; i < gridViewModuleAccess.Rows.Count; i++)
            {
                CheckBox cbAdd = (CheckBox)gridViewModuleAccess.Rows[i].FindControl("chkBoxAdd");
                CheckBox cbView = (CheckBox)gridViewModuleAccess.Rows[i].FindControl("chkBoxView");
                CheckBox cbUpdate = (CheckBox)gridViewModuleAccess.Rows[i].FindControl("chkBoxUpdate");
                CheckBox cbDelete = (CheckBox)gridViewModuleAccess.Rows[i].FindControl("chkBoxDelete");
                Label labelModuleId = (Label)gridViewModuleAccess.Rows[i].FindControl("modalLabelModuleId");

                moduleAccess.CanAdd = cbAdd.Checked;
                moduleAccess.CanDelete = cbDelete.Checked;
                moduleAccess.CanUpdate = cbUpdate.Checked;
                moduleAccess.CanView = cbView.Checked;
                moduleAccess.ModuleId = Convert.ToInt32(labelModuleId.Text);
                moduleAccess.RoleId = roleId;

                if (IsCheckBoxEmpty(gridViewModuleAccess.Rows[i]) && labelModuleId.ToolTip != "ToolTip") //Delete
                {
                    moduleAccess.Delete(Convert.ToInt32(labelModuleId.ToolTip));
                }
                else if ((!IsCheckBoxEmpty(gridViewModuleAccess.Rows[i])) && labelModuleId.ToolTip == "ToolTip") //Add
                {

                    moduleAccess.Insert(moduleAccess);
                }
                else if ((!IsCheckBoxEmpty(gridViewModuleAccess.Rows[i])) && labelModuleId.ToolTip != "ToolTip") //Update
                {
                    moduleAccess.Id = Convert.ToInt32(labelModuleId.ToolTip);
                    moduleAccess.Update(moduleAccess);
                }
            }
            this.programmaticModalPopup.Hide();
            InitializeGridRoles();
        }
 private void Parse(T_RolesModuleAccess t_rolemoduleaccess, RolesModuleAccess rolemoduleaccess)
 {
     t_rolemoduleaccess.RoleId = rolemoduleaccess.RoleId;
     t_rolemoduleaccess.ModuleId = rolemoduleaccess.ModuleId;
     t_rolemoduleaccess.CanAdd = rolemoduleaccess.CanAdd;
     t_rolemoduleaccess.CanView = rolemoduleaccess.CanView;
     t_rolemoduleaccess.CanUpdate = rolemoduleaccess.CanUpdate;
     t_rolemoduleaccess.CanDelete = rolemoduleaccess.CanDelete;
 }
 public void Update(RolesModuleAccess rolemoduleaccess)
 {
     using (TimeTrackerEntities db = new TimeTrackerEntities())
     {
         try
         {
             T_RolesModuleAccess t_rolemoduleaccess = db.T_RolesModuleAccess.FirstOrDefault(p => p.Id == rolemoduleaccess.Id);
             Parse(t_rolemoduleaccess, rolemoduleaccess);
             db.SaveChanges();
         }
         catch (Exception ex)
         {
             string msg = ex.Message;
         }
     }
 }
        public void Insert(RolesModuleAccess rolemoduleaccess)
        {
            T_RolesModuleAccess t_rolemoduleaccess = new T_RolesModuleAccess();
            Parse(t_rolemoduleaccess, rolemoduleaccess);

            using (TimeTrackerEntities db = new TimeTrackerEntities())
            {
                try
                {
                    db.T_RolesModuleAccess.Add(t_rolemoduleaccess);
                    db.SaveChanges();
                }
                catch (Exception ex)
                {
                    string msg = ex.Message;
                }
            }
        }