Example #1
0
        private SqlCommand DeclareSqlCmdParameter(SqlCommand SqlCmd, DEUserPermission userPermission)
        {
            SqlCmd.Parameters.AddWithValue("@UserId", userPermission.UserId);
            SqlCmd.Parameters.AddWithValue("@PermissionId", userPermission.PermissionId);

            return(SqlCmd);
        }
Example #2
0
        public int UpdateData(DEUser user, DataTable dt_Permission)
        {
            int int_Result = 0;

            DALUserPermission obj_DALUserPermission = new DALUserPermission();

            DEUserPermission userPermission = new DEUserPermission();

            userPermission.UserId = user.UserId;

            SqlConnection SqlCon = new SqlConnection(SqlConjunction.DataConn);

            try
            {
                if (SqlCon.State != ConnectionState.Open)
                {
                    SqlCon.Open();
                }
            }

            catch (SqlException ex)
            {
                Console.WriteLine(ex);
            }

            SqlTransaction tn = SqlCon.BeginTransaction();

            {
                try
                {
                    this.UpdateData(user, SqlCon, tn);

                    obj_DALUserPermission.DeleteData(userPermission, SqlCon, tn);

                    for (int i = 0; i < dt_Permission.Rows.Count; i++)
                    {
                        userPermission.PermissionId = Convert.ToInt32(dt_Permission.Rows[i][0].ToString());
                        obj_DALUserPermission.InsertData(userPermission, SqlCon, tn);
                    }

                    tn.Commit();
                    int_Result = 1;
                }
                catch (Exception ex)
                {
                    tn.Rollback();
                    int_Result = 0;
                    throw (ex);
                }
                finally
                {
                    obj_DALUserPermission = null;

                    SqlCon.Close();
                    tn.Dispose();
                }

                return(int_Result);
            }
        }
Example #3
0
        public int DeleteData(DEUserPermission userPermission, SqlConnection SqlCon, SqlTransaction tn)
        {
            int int_Result;

            SqlCommand sqlCmd = new SqlCommand(" ", SqlCon, tn);

            sqlCmd.CommandText = "Delete  tbl_UserPermission  where UserId = @UserId";

            DeclareSqlCmdParameter(sqlCmd, userPermission);

            int_Result = SqlConjunction.GetSQLTransVoid(sqlCmd);

            sqlCmd = null;

            return(int_Result);
        }
Example #4
0
        public int InsertData(DEUserPermission userPermission, SqlConnection SqlCon, SqlTransaction tn)
        {
            int int_Result;

            SqlCommand sqlCmd = new SqlCommand(" ", SqlCon, tn);

            sqlCmd.CommandText = "INSERT  tbl_UserPermission  VALUES(@UserId,@PermissionId)";

            DeclareSqlCmdParameter(sqlCmd, userPermission);

            int_Result = SqlConjunction.GetSQLTransVoid(sqlCmd);

            sqlCmd = null;

            return(int_Result);
        }