简体   繁体   中英

Checking customer data in ASP.NET MVC

I am calling a controller action to check the customer serial number before allowing him/her to open a ticket on Zendesk (we need to check if the customer maintenance contract is active). Below you can find the code.

  • How can I open the URL from the controller action?
  • What ActionResult do I need to return afterward?

Thanks.

public ActionResult OpenTicket(string serialNumber, string version)
{
   if (customerSubscription.IsExpired == false)           
   {
       // need to open this URL
       // https://devdept.zendesk.com/tickets/new?ticket[fields[111111]]=" + serialNumber + "&ticket[fields[222222]]=" + version);
   }
   else
   {
       // display an error page with upsell options
   }   

}

To redirect to some url you could use the Redirect method from base controller. To return some errors to a View, you could add the error on the ModelState and send it to View. Look the code bellow with the comments:

public ActionResult OpenTicket(string serialNumber, string version)
{
   if (!customerSubscription.IsExpired)           
   {
       // use the Redirect method from base controller
       return Redirect("https://devdept.zendesk.com/tickets/new?ticket[fields[111111]]=" + serialNumber + "&ticket[fields[222222]]=" + version);
   }
   else
   {
       // display an error page with upsell options
       ModelState.AddModelError("ErrorKey", "Custom error message");
       // it will return OpenTicket view, otr pass a name you want to return
       return View(); 

       // if you redirect here, you will lose the ModelState.
   }   
}

in your view, you could:

@Html.ValidationSummary()

You have 2 options depending on where you want to put the external service call.

  1. The server detects an expiration and informs the user to refresh their subscription. The user then goes to the external service URL, refreshes subscription and manually returns back to your site.

  2. The server detects an expiration, automatically call the external service to refresh user's subscription and perform consequent business logic having user subscription active. The user is provisioned with ActionResult and interact further on.

CASE 1: Use Redirect and provide external service URL

return Redirect(urlString)

CASE 2: Use external service call within: 1. your controller or 2. delegate to business_logic/service tier. In the case of SOAP communication, add a service reference or generate a proxy using svcutil.exe, otherwise you may use HttpWebRequest ( See ). To gain performance you can consider asynchronous approach for not to block a thread allocated to serve incoming requests.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM