context: using System.Collections.Generic;
  using System.Net;
  using System.Net.Http;
  using System.Web.Http;
  using MixERP.Net.ApplicationState.Cache;
  using MixERP.Net.Common.Extensions;
  using MixERP.Net.EntityParser;
  using Newtonsoft.Json;
  using PetaPoco;
  
  namespace MixERP.Net.Api.Core
  {
      /// <summary>
      ///     Provides a direct HTTP access to perform various tasks such as adding, editing, and removing Shippers.
      /// </summary>
      [RoutePrefix("api/v1.5/core/shipper")]
      public class ShipperController : ApiController
      {
          /// <summary>
          ///     The Shipper data context.
          /// </summary>
          private readonly MixERP.Net.Schemas.Core.Data.Shipper ShipperContext;
  
          public ShipperController()
          {
              this.LoginId = AppUsers.GetCurrent().View.LoginId.ToLong();
              this.UserId = AppUsers.GetCurrent().View.UserId.ToInt();
              this.OfficeId = AppUsers.GetCurrent().View.OfficeId.ToInt();
              this.Catalog = AppUsers.GetCurrentUserDB();
  
              this.ShipperContext = new MixERP.Net.Schemas.Core.Data.Shipper
              {
                  Catalog = this.Catalog,
                  LoginId = this.LoginId
              };
          }
  
          public long LoginId { get; }
          public int UserId { get; private set; }
          public int OfficeId { get; private set; }
          public string Catalog { get; }
  
          /// <summary>
          ///     Counts the number of shippers.
          /// </summary>
          /// <returns>Returns the count of the shippers.</returns>
          [AcceptVerbs("GET", "HEAD")]
          [Route("count")]
          [Route("~/api/core/shipper/count")]
          public long Count()
          {
              try
              {
                  return this.ShipperContext.Count();
              }
              catch (UnauthorizedException)
              {
                  throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.Forbidden));
              }
              catch
              {
                  throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError));
              }
          }
  
          /// <summary>
          ///     Returns an instance of shipper.
          /// </summary>
          /// <param name="shipperId">Enter ShipperId to search for.</param>
          /// <returns></returns>
          [AcceptVerbs("GET", "HEAD")]
          [Route("{shipperId}")]
          [Route("~/api/core/shipper/{shipperId}")]
          public MixERP.Net.Entities.Core.Shipper Get(int shipperId)
          {
              try
              {
                  return this.ShipperContext.Get(shipperId);
              }
              catch (UnauthorizedException)
              {
                  throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.Forbidden));
              }
              catch
              {
                  throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError));
              }
          }
  
          /// <summary>
          ///     Creates a paginated collection containing 25 shippers on each page, sorted by the property ShipperId.
          /// </summary>
          /// <returns>Returns the first page from the collection.</returns>
          [AcceptVerbs("GET", "HEAD")]
          [Route("")]
          [Route("~/api/core/shipper")]
          public IEnumerable<MixERP.Net.Entities.Core.Shipper> GetPagedResult()
          {
              try
              {
                  return this.ShipperContext.GetPagedResult();
              }
              catch (UnauthorizedException)
              {
                  throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.Forbidden));
              }
              catch
              {
                  throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError));
              }
          }
  
          /// <summary>
          ///     Creates a paginated collection containing 25 shippers on each page, sorted by the property ShipperId.
          /// </summary>
          /// <param name="pageNumber">Enter the page number to produce the resultset.</param>
          /// <returns>Returns the requested page from the collection.</returns>
          [AcceptVerbs("GET", "HEAD")]
          [Route("page/{pageNumber}")]
          [Route("~/api/core/shipper/page/{pageNumber}")]
          public IEnumerable<MixERP.Net.Entities.Core.Shipper> GetPagedResult(long pageNumber)
          {
              try
              {
                  return this.ShipperContext.GetPagedResult(pageNumber);
              }
              catch (UnauthorizedException)
              {
                  throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.Forbidden));
              }
              catch
              {
                  throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError));
              }
          }
  
          /// <summary>
          ///     Creates a filtered and paginated collection containing 25 shippers on each page, sorted by the property ShipperId.
          /// </summary>
          /// <param name="pageNumber">Enter the page number to produce the resultset.</param>
          /// <param name="filters">The list of filter conditions.</param>
          /// <returns>Returns the requested page from the collection using the supplied filters.</returns>
          [AcceptVerbs("POST")]
          [Route("get-where/{pageNumber}")]
          [Route("~/api/core/shipper/get-where/{pageNumber}")]
          public IEnumerable<MixERP.Net.Entities.Core.Shipper> GetWhere(long pageNumber, [FromBody]dynamic filters)
          {
              try
              {
                  List<EntityParser.Filter> f = JsonConvert.DeserializeObject<List<EntityParser.Filter>>(filters);
                  return this.ShipperContext.GetWhere(pageNumber, f);
              }
              catch (UnauthorizedException)
              {
                  throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.Forbidden));
              }
              catch
              {
                  throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError));
              }
          }
  
          /// <summary>
          ///     Displayfields is a lightweight key/value collection of shippers.
          /// </summary>
          /// <returns>Returns an enumerable key/value collection of shippers.</returns>
          [AcceptVerbs("GET", "HEAD")]
          [Route("display-fields")]
          [Route("~/api/core/shipper/display-fields")]
          public IEnumerable<DisplayField> GetDisplayFields()
          {
              try
              {
                  return this.ShipperContext.GetDisplayFields();
              }
              catch (UnauthorizedException)
              {
                  throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.Forbidden));
              }
              catch
              {
                  throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError));
              }
          }
  
          /// <summary>
          ///     Adds your instance of Account class.
          /// </summary>
          /// <param name="shipper">Your instance of shippers class to add.</param>
          [AcceptVerbs("POST")]
          [Route("add/{shipper}")]
          [Route("~/api/core/shipper/add/{shipper}")]
          public void Add(MixERP.Net.Entities.Core.Shipper shipper)
          {
              if (shipper == null)
              {
                  throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.MethodNotAllowed));
              }
  
              try
              {
                  this.ShipperContext.Add(shipper);
              }
              catch (UnauthorizedException)
              {
                  throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.Forbidden));
              }
              catch
              {
                  throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError));
              }
          }
  
          /// <summary>
          ///     Edits existing record with your instance of Account class.
          /// </summary>
          /// <param name="shipper">Your instance of Account class to edit.</param>
          /// <param name="shipperId">Enter the value for ShipperId in order to find and edit the existing record.</param>
          [AcceptVerbs("PUT")]
          [Route("edit/{shipperId}/{shipper}")]
          [Route("~/api/core/shipper/edit/{shipperId}/{shipper}")]
          public void Edit(int shipperId, MixERP.Net.Entities.Core.Shipper shipper)
          {
  
gt:             if (shipper == null)