The server-side API Controller

Back to Content

The angular.js file contains client side code. If you look at the Save() function you can see how you can call server-side code by using AJAX:

$http({
method: ‘POST’,
url: ‘api/Planning/PostPlanning/’,
data: $scope.Planning
})

We have defined an API controller named Planning with a method PostPlanning to which we pas the model object Planning. You can find the code of the server-side API controller in the Controller folder next to the client-side MVC controller.
The model object Planning is contained in the folder Model and has the same format as the Angular.js object Planning.

namespace Nav4PS.Controllers
{
public class PlanningController : ApiController
{

// POST api/<controller>
public string PostPlanning(Planning item)
{

//Code to post bijstelling
Planning_OS_XOPRequest planberichtFull;
PlanberichtXOPType planbericht;
ChannelFactory<Planning_OS_XOPChannel> factory;
Planning_OS_XOPChannel channel;

try
{

planberichtFull = new Planning_OS_XOPRequest();

planbericht = new PlanberichtXOPType();
planbericht.OpdrachtID = item.opdrachtid;
planbericht.Versienummer = item.versienummer;
if (item.typeTijdstip == Nav4PS.Models.PlanningTijdstipType.Beletmelding)
{
BeletType beletMelding = new BeletType();
beletMelding.Contacttijdstip = DateTime.Parse(item.contacttijdstip);
beletMelding.TypeContactpoging = (DSPPlanningReference.TypeContactpogingType)item.typeContactpoging;
beletMelding.Opmerking = item.opmerking;
planbericht.Item = beletMelding;
}
else
{
PlanningType planning = new PlanningType();
planning.TypeTijdstip = (DSPPlanningReference.PlanningTijdstipType)item.typeTijdstip;
planning.Starttijd = DateTime.Parse(System.String.Concat(item.startdatum, ” “, item.starttijd, “:00″));
planning.Eindtijd = DateTime.Parse(System.String.Concat(item.einddatum, ” “, item.eindtijd, “:00”));
planning.Redencode = (DSPPlanningReference.RedencodeType)item.redencode;
planning.Toelichting = item.toelichting;
planning.IsOpdrachtgeverBenodigd = (item.isBenodigd == “true” ? true : false);
planbericht.Item = planning;
}

planberichtFull.Planbericht = planbericht;


}

Back to Content

Leave a Reply

Your email address will not be published. Required fields are marked *