Performing Transactions

The interactions with the AB Suite system are performed by using the IConnection interface of the AB Suite Access Layer that exposes a property called DataHandler. The DataHandler property is designed to perform operations, such as exchanging data with the AB Suite system through the DataModels generated for the system.

To process data sent from the <MVCViewName> View in the browser, a new Controller method named ProcessContact() is added to the HomeController. The ProcessContact() method accepts an instance of a ContactModel as a parameter that can be sent directly to the AB Suite Access Layer API by using the Transmit() method of the DataHandler interface.

public ActionResult ProcessContact(ContactModel mdl)
        {
            // Retrieve objects from Session State
            IConnection ABSConnection = (IConnection) Session["ABSConnection"];
         
            TransmissionObject trObj = null;
 
            if (ModelState.IsValid)
            {
                if (ABSConnection.IsConnected)
                {
                    trObj = ABSConnection.DataHandler.Transmit(mdl);
           if (trObj != null &&  (trObj.State == TransmissionReturnCode.Ok 
             || trObj.State == TransmissionReturnCode.OkWithSwitch))
                    {
                        ViewBag.Status = "Transaction Failed!";
                        return View("Error");                   
                    }
                }
                // Save Session details
                Session["ABSConnection"] = ABSConnection;
                Session["CurrentTO"] = trObj;

                return RedirectToAction ("MyContact", trObj.Datamodel);
            }

            // Save Session details
            Session["ABSConnection"] = ABSConnection;
            Session["CurrentTO"] = trObj;

            ViewBag.Status = "Errors on Page!";
            return View("MyContact", mdl);

        }

As shown in the code, the main aspects of the ProcessContact() method involves the following:

  1. Retrieve the Connection object from SessionState.

  2. If the ModelState is valid, use the DataHandler Transmit() method to transmit the data contained in the received DataModel to the runtime system.

  3. Check the return status of the Transmit() method and if it is successful, redirect it to the <MVCViewName> View with the newly acquired DataModel that is populated with data from the runtime.

  4. If the ModelState is not valid, that is, if validation errors occur in the View, return the <MVCViewName> View to display the error messages.

The following ProcessContact() method is triggered from the View by setting the corresponding Action name in the Html.Begin statement of the View:

@using (Html.BeginForm("ProcessContact", "Home", FormMethod.Post))

When the View is submitted, the MVC Routing directs the process to the ProcessContact() action, with the data encapsulated in an instance of the ContactModel.