Custom endpoint for Connect

This is the sample on how to add a custom enpoint for Litium Connect. 

  1. Download SampleOrderController here . 
  2. Put it in Controllers/Api folder of Litium 7.5 Accelerator.
  3. Update project's reference - Litium.Connect.Abstraction is required.

CustomConnectApi.PNG

 

The sample code will return all orders within the last 24hrs using order api, and then convert the result to Litium Connect Order using automapper.

        /// <summary>
        /// Gets the order.
        /// </summary>
        [Route("", Name = "Order_Get24hrs")]
        [HttpGet]
        [ResponseType(typeof(Order))]
        public IHttpActionResult Get24Hrs()
        {
            if (!ModelState.IsValid)
            {
                return BadRequest();
            }
            if (!_authorizationService.HasOperation(Operations.Function.Sales.Content))
            {
                return Unauthorized();
            }

            var filterInfo = new OrderViewFilteringInfo(
                DateTime.Now.AddDays(-1),
                DateTime.Now,
                 -1,
                "",
                null,
                null, // orderids
                "", // payment statues
                "", // deliverystatuses
                Guid.Empty,
                Sales.OrderType.None);

            var pageInfo = new PagingInfo(1, 50 , 0);

            var sortInfo = new OrderViewSortingInfo(
                SortOrder.ASC,
                OrderViewSortingInfo.OrderBy.OrderID);

            QueryInfo queryInfo = new QueryInfo(
                new AdditionalInfo(new List<string>()),
                filterInfo,
                pageInfo,
                sortInfo
                );

            var orderViewRows = ModuleECommerce.Instance.Orders.GetOrderViewRows(queryInfo, SecurityToken.CurrentSecurityToken);
            var orders = ModuleECommerce.Instance.Orders.GetOrders(orderViewRows.Select(x => x.OrderID), SecurityToken.CurrentSecurityToken).ToList();
            var orderCarriers = orders.Select(x => x.GetAsCarrier(true, true, true, true, true, true)).ToList();
            return Ok(orders.Select(t=> t.MapTo<Order>()));
        }

 

Testing using postman :

 

PostmanCall.PNG