예제 #1
0
        public int Create(BlockDataRoleCreateModel model)
        {
            int    output          = 0;
            string strLstOfMenuIds = "";

            try
            {
                strLstOfMenuIds = model.StrAllowedMenus;
                DBConnection.OpenDBConnect();
                //STEP1:  ***************************************************************/


                Dictionary <string, object> dicParas    = new Dictionary <string, object>();
                Dictionary <string, object> dicParaOuts = new Dictionary <string, object>();
                if (model.Name != null && model.Description != null && strLstOfMenuIds != null)
                {
                    dicParas.Add("Name", model.Name);
                    //dicParas.Add("Description", model.Description);
                    dicParas.Add("Description", String.IsNullOrEmpty(model.Description) ? "" : model.Description);
                    dicParas.Add("LstOfMenuIds", strLstOfMenuIds);
                    dicParas.Add("DepartId", model.DeptID);
                    if (model.RoleId == 0)
                    {
                        //dicParas.Add("")
                        output = DBConnection.ExecSPNonQuery("SP_ROLE_INSERT", dicParas, ref dicParaOuts, true);
                    }
                    else
                    {
                        dicParas.Add("RoleId", model.RoleId);
                        output = DBConnection.ExecSPNonQuery("SP_ROLE_UPDATE", dicParas, ref dicParaOuts, true);
                    }
                }

                //STEP2:  ***************************************************************/
            }
            catch (Exception ex)
            {
                this.ERROR = ex.ToString();
                output     = -1;
            }
            finally
            {
                DBConnection.CloseDBConnect();
            }


            return(output);
        }
예제 #2
0
        public BlockDataRoleCreateModel GetEntityById(int id)
        {
            BlockDataRoleCreateModel output = new BlockDataRoleCreateModel();

            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("ROLEID", id);
                DataSet dataSet = DBConnection.ExecSelectSP("SP_ROLE_GET_BY_ID", dicParas, ref dicParaOuts, true);
                //**********************TABLE: ROLE***************************************
                DataTable table1 = dataSet.Tables[0];
                foreach (DataRow row in table1.Rows)
                {
                    output.Name        = row["Name"].ToString();
                    output.Description = row["Description"].ToString();
                    output.RoleId      = Int32.Parse(row["RoleId"].ToString());
                    output.DeptID      = Int32.Parse(row["DepartId"].ToString());
                }
                //**********************TABLE: ROLEMENU ***********************************************
                DataTable table2 = dataSet.Tables[1];

                foreach (DataRow row in table2.Rows)
                {
                    output.ListRoleMenus.Add(Int32.Parse(row["menuid"].ToString()));
                }
            }
            catch (Exception ex)
            {
                this.ERROR = ex.ToString();
            }
            finally
            {
                this.DBConnection.CloseDBConnect();
            }
            return(output);
        }