Exemplo n.º 1
0
        public List <EntityRoleModel> GetList(int?deptId = null)
        {
            List <EntityRoleModel> output = new  List <EntityRoleModel>();

            this.DBConnection.OpenDBConnect();
            if (this.DBConnection.ERROR != null)
            {
                this.DBConnection.CloseDBConnect();
                throw new Exception("Can't connect to db");
            }
            ;

            try
            {
                DBConnection.command.Parameters.Clear();
                DBConnection.command.CommandText = USP_GET_ROLES_BY_ORGID;
                DBConnection.command.CommandType = CommandType.StoredProcedure;
                DBConnection.command.Parameters.AddWithValue("@deptID", (object)deptId ?? DBNull.Value);



                using (SqlDataReader reader = DBConnection.command.ExecuteReader())
                {
                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            EntityRoleModel entityRole = new EntityRoleModel();
                            entityRole.RoleId         = reader.GetInt32(reader.GetOrdinal("RoleId"));
                            entityRole.Name           = reader.GetString(reader.GetOrdinal("Name"));
                            entityRole.Description    = reader.GetString(reader.GetOrdinal("Description"));
                            entityRole.DepartmentName = reader.GetString(reader.GetOrdinal("OrganizationName"));
                            entityRole.DepartId       = reader.GetInt32(reader.GetOrdinal("DepartId"));
                            output.Add(entityRole);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                this.ERROR = ex.ToString();
            }
            finally
            {
                this.DBConnection.CloseDBConnect();
            }
            return(output);
        }
Exemplo n.º 2
0
        public BlockDataUserCreateModel GetEntityById(int id)
        {
            BlockDataUserCreateModel output = new BlockDataUserCreateModel();

            try
            {
                DBConnection.OpenDBConnect();
                if (this.DBConnection.ERROR != null)
                {
                    throw new Exception("Can't connect to db");
                }
                //STEP1:  ***************************************************************/


                Dictionary <string, object> dicParas    = new Dictionary <string, object>();
                Dictionary <string, object> dicParaOuts = new Dictionary <string, object>();
                dicParas.Add("USERID", id);
                DataSet dataSet = DBConnection.ExecSelectSP("SP_USER_GET_BY_ID", dicParas, ref dicParaOuts, true);
                //**********************TABLE: ROLE***************************************
                DataTable table1 = dataSet.Tables[0];
                foreach (DataRow row in table1.Rows)
                {
                    output.Email    = row["Email"].ToString();
                    output.Phone    = row["Phone"].ToString();
                    output.IsAdmin  = (bool)row["IsAdmin"];
                    output.UserName = (string)row["UserName"];
                    output.UserId   = (int)row["UserId"];
                    output.DeptId   = (int)row["deptID"];
                }
                output.IsSuperAdmin = output.IsAdmin && (output.DeptId == 0);
                //**********************TABLE: ROLEMENU ***********************************************
                DataTable table2 = dataSet.Tables[1];

                foreach (DataRow row in table2.Rows)
                {
                    output.LstSelectedMenu.Add(Int32.Parse(row["menuid"].ToString()));
                }

                foreach (DataRow row in dataSet.Tables[2].Rows)
                {
                    output.LstSelectedRole.Add(Int32.Parse(row["roleid"].ToString()));
                }
                //**********************TABLE: ROLE ***********************************************
                DataTable table3 = dataSet.Tables[2];
                foreach (DataRow row in table3.Rows)
                {
                    BI_Project.Models.EntityModels.EntityRoleModel entityRoleModel = new EntityRoleModel();
                    //entityRoleModel.Name = row["Name"].ToString();
                    entityRoleModel.RoleId = (int)row["RoleId"];

                    output.ListAllRoles.Add(entityRoleModel);
                }
            }
            catch (Exception ex)
            {
                this.ERROR = ex.ToString();
            }
            finally
            {
                this.DBConnection.CloseDBConnect();
            }
            return(output);
        }