Help With instering a custom controller for a button.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
11 years ago
Hi, i want to either insert some code into the catalog controller or make another controller depending on what would be the best method.

I am after a punch out solution. i have got the code i need in order to produce this solution
but i am having trouble where to insert it. i have come to the conclusion that i need to insert code into both a view and a controller:

The code for controller:

<!--
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.IO;
using System.Net;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Text;

namespace PunchOutTester
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string baseUrl = Request.Url.GetLeftPart(UriPartial.Authority);
            ReturnURL.Text = baseUrl + "/PunchOut/Response.aspx";
        }

        protected void SubmitCreateEdit_Click(object sender, EventArgs e)
        {
            StringBuilder sbURL = new StringBuilder();
            sbURL.Append(SFURL.Text);
            if (Action.Text == "create" || Action.Text == "edit")
            {
                sbURL.Append("/SSPMCreateEdit.aspx");
            }
            else if(Action.Text == "delete" || Action.Text == "commit")
            {
                sbURL.Append("/SSPMCommitDelete.aspx");
            }

            string url = sbURL.ToString();

            StringBuilder sbData = new StringBuilder();
            sbData.Append("ReturnUrl=");
            sbData.Append(ReturnURL.Text);
            sbData.Append("&");
            sbData.Append("AdminUser=");
            sbData.Append(AdminUser.Text);
            sbData.Append("&");
            sbData.Append("AdminPass=");
            sbData.Append(AdminPass.Text);
            sbData.Append("&");
            sbData.Append("UserName=");
            sbData.Append(UserName.Text);
            sbData.Append("&");
            sbData.Append("Action=");
            sbData.Append(Action.Text);
            sbData.Append("&");
            sbData.Append("DocumentID=");
            sbData.Append(DocumentID.Text);
            if (Action.Text == "commit")
            {
                sbData.Append("&returnOrderId=y");
            }
            string data = sbData.ToString();

            string fullURL = url + "?"+ data;

            string dataToPost = PostData(url, data);

            FullURL.Text = fullURL;
            Result.Text = dataToPost;  
        }

        private string PostData(string url,string data)
        {
            string result = "";

            HttpWebRequest httpReq = (HttpWebRequest)WebRequest.Create(url);
            httpReq.Method = "POST";
            httpReq.ContentType = "application/x-www-form-urlencoded";
            httpReq.ContentLength = data.Length;

            StreamWriter sWriter = new StreamWriter(httpReq.GetRequestStream());
            sWriter.Write(data);
            sWriter.Close();

            HttpWebResponse httpResp = null;
            try
            {
                httpResp = (HttpWebResponse)httpReq.GetResponse();
            }
            catch (Exception ex)
            {
                //
            }

            try
            {
                using (StreamReader sr = new StreamReader(httpResp.GetResponseStream()))
                {
                    result = sr.ReadToEnd();
                    sr.Close();
                }
            }
            catch (Exception ex)
            {
                Result.Text = "Exception: " + ex.Message;
            }

            return result;

        }

        protected void getDocURL_Click(object sender, EventArgs e)
        {
            string[] newResult = Result.Text.Split(':');
            StringBuilder sb = new StringBuilder();
            sb.Append(SFURL.Text);
            sb.Append("/UserPMCreateEdit.aspx");
            sb.Append("?ticket=");
            sb.Append(newResult[1]);

            FullURL.Text = sb.ToString();
            Result.Text = "";
        }

        protected void GoToSF_Click(object sender, EventArgs e)
        {
            if (Action.Text == "create" || Action.Text == "edit")
            {
                string url = FullURL.Text;
                string fullURL = "window.open('" + url + "', '_blank');";
                ScriptManager.RegisterStartupScript(this, typeof(string), "OPEN_WINDOW", fullURL, true);
            }
            else if (Action.Text == "commit" || Action.Text == "delete")
            {
                Result.Text = "Wrong button";
            }
        }

        protected void getCatURL_Click(object sender, EventArgs e)
        {
            StringBuilder sbURL = new StringBuilder();
            sbURL.Append(SFURL.Text);
            sbURL.Append("/SSPMCreateEdit.aspx");
            string url = sbURL.ToString();

            StringBuilder sbData = new StringBuilder();
            sbData.Append("ReturnUrl=");
            sbData.Append(ReturnURL.Text);
            sbData.Append("&");
            sbData.Append("AdminUser=");
            sbData.Append(AdminUser.Text);
            sbData.Append("&");
            sbData.Append("AdminPass=");
            sbData.Append(AdminPass.Text);
            sbData.Append("&");
            sbData.Append("UserName=");
            sbData.Append(UserName.Text);
            sbData.Append("&");
            sbData.Append("Action=");
            sbData.Append("viewCategory");
            sbData.Append("&");
            if(!String.IsNullOrEmpty(CatID.Text))
            {
                sbData.Append("CategoryID=");
                sbData.Append(CatID.Text);
            }
            else if (!String.IsNullOrEmpty(CatName.Text))
            {
                sbData.Append("CategoryName=");
                sbData.Append(CatID.Text.Replace(" ","+"));
            }
            string data = sbData.ToString();

            string fullURL = url + "?" + data;

            string dataToPost = PostData(url, data);

            FullURL.Text = fullURL;
            Result.Text = dataToPost;  
        }

        protected void goToCat_Click(object sender, EventArgs e)
        {
            string url = FullURL.Text;
            string fullURL = "window.open('" + url + "', '_blank');";
            ScriptManager.RegisterStartupScript(this, typeof(string), "OPEN_WINDOW", fullURL, true);
        }

        protected void getURLTix_Click(object sender, EventArgs e)
        {
            string[] newResult = Result.Text.Split(':');
            StringBuilder sb = new StringBuilder();
            sb.Append(SFURL.Text);
            sb.Append("/UserPMViewCatGateway.aspx");
            sb.Append("?ticket=");
            sb.Append(newResult[1]);

            FullURL.Text = sb.ToString();
            Result.Text = "";
        }
    }
}

-->

The code for the view:

<!--

<form name="form1" method="post" action="punchouttest.aspx" id="form1">
<div>
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwULLTE5NDk0OTU0MTlkZCkD+/HJaLwRLR6L0Bx7Sf0Fq7X+2EpK3TyWlpBYmbAL" />
</div>

<div>

  <input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEdABYpIVF7+01+LuToE8w7/h8OIXbleySYVe8RlQuhJ/HL1FGQUtR3OQ3MVHeDoe9Sx6CHKuOtTqhhhm7oMwN5epaOVvsR216A5mSaLwlLGAbqp0dSwSl9T9cYdvdEUMk3rEUFXCf+252yNTk0c2gcuNmpv622PmQiSm20i3PyQ+CCZ5LFvW+05khQ0FnBwpQ4aEuCEiLhtNbEQqw5h26YNq0Zk46LRgT8Cehg2RH5Q6+QhgcsZABHu0IrJyRDYwYnlbWTjMdaP+d1K5n85ba1ifirIyrPqN6MaeH6PAPBf7JGQQO0aS2ak3TK52kAmEyGxXehCgNoYVOzF90GgqTKZpTGr/rEt7vve/XEDUP+FZWoubXmtw9z6tzZqgcBYAu+EwYnNZO924ur0dmYQdk4tpI3f2N0R+C0aABQbAySPxatBhPfPmQRgI5XIx7h/guLatEZimeOxb6Ijijx9+SmzvMZfLLoHfLuoFnWVei3cim5bf8sgSn+oO4Iy7KYRiRZ6Qo=" />
</div>
    <div>
        <span id="Label9">Get a ticket to create, edit, commit, delete or reorder a document</span>
        <br/><br/>
        
        <span id="Label1">URL of Test Server</span>
        <span id="Label11">  </span>
        <input name="SFURL" type="text" value="http://oscaweb.pageflex.co.uk/" id="SFURL" style="width:600px;" />
        <br />
        
        <span id="Label7">Return URL</span>
        <span id="Label12">  </span>
        <input name="ReturnURL" type="text" value="http://localhost/PunchOut/Response.aspx" id="ReturnURL" style="width:600px;" />
        <br />
        
        <span id="Label2">Admin User Name</span>
        <span id="Label13">  </span>
        <input name="AdminUser" type="text" value="admin" id="AdminUser" />
        <br />
        
        <span id="Label3">Admin Password</span>
        <span id="Label14">  </span>
        <input name="AdminPass" type="text" value="admin" id="AdminPass" />
        <br />
            
        <span id="Label4">User Name</span>
        <span id="Label15">  </span>
        <input name="UserName" type="text" value="testuser2" id="UserName" />
        <br />
        
        <span id="Label5">Action</span>
        <span id="Label16">  </span>
        <select name="Action" id="Action">
  <option selected="selected" value="create">create</option>
  <option value="edit">edit</option>
  <option value="delete">delete</option>
  <option value="commit">commit</option>
  <option value="reorder">reorder</option>

</select>
        <br /><br />
        
        <span id="Label6">Document ID</span>
        <span id="Label17">  </span>
        <input name="DocumentID" type="text" value="OGC-PCORN" id="DocumentID" />
        <br />
        <span id="Label22">NOTE: this is the SKU when creating a document,
                its the ID returned from Storefront if editing, commiting, reordering or deleting a document</span>
        <br /><br />
        
        <span id="Label19">Generated URL</span>
        <span id="Label20">  </span>
        <input name="FullURL" type="text" value="http://oscaweb.pageflex.co.uk//UserPMCreateEdit.aspx?ticket=47389e03-ac52-4845-949c-90cf9f0a7866" id="FullURL" style="width:1000px;" />
        <br />
        
        <span id="Label8">Result</span>
        <span id="Label18">  </span>
        <textarea name="Result" rows="2" cols="20" id="Result" style="width:1000px;">
</textarea>
        <br /><br />
        
        <input type="submit" name="SubmitCreateEdit" value="Get a ticket/Commit/Delete" id="SubmitCreateEdit" />
            <span id="Label10">  </span>
        <input type="submit" name="getDocURL" value="Get URL for Document" id="getDocURL" />
        <span id="Label21">  </span>
        <input type="submit" name="GoToSF" value="Go To Storefront" id="GoToSF" />
        <br />
    </div>
    <p>
        <span id="Label23">Test Categories</span>
    </p>
        <span id="Label24">Category ID</span>
        <span id="Label27">  </span>
        <input name="CatID" type="text" id="CatID" style="width:228px;" />
        <br />
        <span id="Label25">or</span>
        <br />
        <span id="Label26">Category Name</span>
        <span id="Label28">  </span>
        <input name="CatName" type="text" id="CatName" style="width:224px;" />
        <br />
        <input type="submit" name="getCatURL" value="Build Category URL" id="getCatURL" />
        <span id="Label29">  </span>
        <input type="submit" name="getURLTix" value="Get URL with Ticket" id="getURLTix" style="width:166px;" />
        <span id="Label30">  </span>
        <input type="submit" name="goToCat" value="Go to category" id="goToCat" />
    

<script type="text/javascript">
//<![CDATA[
</script>
</form>

-->

How would i achieve this. would i need to create a new controller or could i add this to an existing controller?


Thanks
11 years ago
The code shown is for asp.net forms (aspx) not for asp.net MVC (cshtml), I suggest you read up on MVC because it differs from web forms
11 years ago
keesjan wrote:
The code shown is for asp.net forms (aspx) not for asp.net MVC (cshtml), I suggest you read up on MVC because it differs from web forms



Oh god your joking lol, i am really lost then


im really new to MVC so out on a limb.

Thanks
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.