context: // ReSharper disable All
  using System.Collections.Generic;
  using System.Dynamic;
  using System.Net;
  using System.Net.Http;
  using System.Web.Http;
  using MixERP.Net.Api.Framework;
  using MixERP.Net.ApplicationState.Cache;
  using MixERP.Net.Common.Extensions;
  using MixERP.Net.EntityParser;
  using MixERP.Net.Framework;
  using Newtonsoft.Json;
  using Newtonsoft.Json.Linq;
  using PetaPoco;
  using MixERP.Net.Schemas.Transactions.Data;
  
  namespace MixERP.Net.Api.Transactions
  {
      /// <summary>
      ///     Provides a direct HTTP access to perform various tasks such as adding, editing, and removing Inventory Transfer Delivery Details.
      /// </summary>
      [RoutePrefix("api/v1.5/transactions/inventory-transfer-delivery-detail")]
      public class InventoryTransferDeliveryDetailController : ApiController
      {
          /// <summary>
          ///     The InventoryTransferDeliveryDetail repository.
          /// </summary>
          private readonly IInventoryTransferDeliveryDetailRepository InventoryTransferDeliveryDetailRepository;
  
          public InventoryTransferDeliveryDetailController()
          {
              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.InventoryTransferDeliveryDetailRepository = new MixERP.Net.Schemas.Transactions.Data.InventoryTransferDeliveryDetail
              {
                  _Catalog = this._Catalog,
                  _LoginId = this._LoginId,
                  _UserId = this._UserId
              };
          }
  
          public InventoryTransferDeliveryDetailController(IInventoryTransferDeliveryDetailRepository repository, string catalog, LoginView view)
          {
              this._LoginId = view.LoginId.ToLong();
              this._UserId = view.UserId.ToInt();
              this._OfficeId = view.OfficeId.ToInt();
              this._Catalog = catalog;
  
              this.InventoryTransferDeliveryDetailRepository = repository;
          }
  
          public long _LoginId { get; }
          public int _UserId { get; private set; }
          public int _OfficeId { get; private set; }
          public string _Catalog { get; }
  
          /// <summary>
          ///     Creates meta information of "inventory transfer delivery detail" entity.
          /// </summary>
          /// <returns>Returns the "inventory transfer delivery detail" meta information to perform CRUD operation.</returns>
          [AcceptVerbs("GET", "HEAD")]
          [Route("meta")]
          [Route("~/api/transactions/inventory-transfer-delivery-detail/meta")]
          public EntityView GetEntityView()
          {
              if (this._LoginId == 0)
              {
                  return new EntityView();
              }
  
              return new EntityView
              {
                  PrimaryKey = "inventory_transfer_delivery_detail_id",
                  Columns = new List<EntityColumn>()
                                  {
                                          new EntityColumn { ColumnName = "inventory_transfer_delivery_detail_id",  PropertyName = "InventoryTransferDeliveryDetailId",  DataType = "long",  DbDataType = "int8",  IsNullable = false,  IsPrimaryKey = true,  IsSerial = true,  Value = "",  MaxLength = 0 },
                                          new EntityColumn { ColumnName = "inventory_transfer_delivery_id",  PropertyName = "InventoryTransferDeliveryId",  DataType = "long",  DbDataType = "int8",  IsNullable = false,  IsPrimaryKey = false,  IsSerial = false,  Value = "",  MaxLength = 0 },
                                          new EntityColumn { ColumnName = "value_date",  PropertyName = "ValueDate",  DataType = "DateTime",  DbDataType = "date",  IsNullable = false,  IsPrimaryKey = false,  IsSerial = false,  Value = "",  MaxLength = 0 },
                                          new EntityColumn { ColumnName = "item_id",  PropertyName = "ItemId",  DataType = "int",  DbDataType = "int4",  IsNullable = false,  IsPrimaryKey = false,  IsSerial = false,  Value = "",  MaxLength = 0 },
                                          new EntityColumn { ColumnName = "quantity",  PropertyName = "Quantity",  DataType = "int",  DbDataType = "int4",  IsNullable = false,  IsPrimaryKey = false,  IsSerial = false,  Value = "",  MaxLength = 0 },
                                          new EntityColumn { ColumnName = "unit_id",  PropertyName = "UnitId",  DataType = "int",  DbDataType = "int4",  IsNullable = false,  IsPrimaryKey = false,  IsSerial = false,  Value = "",  MaxLength = 0 },
                                          new EntityColumn { ColumnName = "base_quantity",  PropertyName = "BaseQuantity",  DataType = "decimal",  DbDataType = "numeric",  IsNullable = false,  IsPrimaryKey = false,  IsSerial = false,  Value = "",  MaxLength = 0 },
                                          new EntityColumn { ColumnName = "base_unit_id",  PropertyName = "BaseUnitId",  DataType = "int",  DbDataType = "int4",  IsNullable = false,  IsPrimaryKey = false,  IsSerial = false,  Value = "",  MaxLength = 0 }
                                  }
              };
          }
  
          /// <summary>
          ///     Counts the number of inventory transfer delivery details.
          /// </summary>
          /// <returns>Returns the count of the inventory transfer delivery details.</returns>
          [AcceptVerbs("GET", "HEAD")]
          [Route("count")]
          [Route("~/api/transactions/inventory-transfer-delivery-detail/count")]
          public long Count()
          {
              try
              {
                  return this.InventoryTransferDeliveryDetailRepository.Count();
              }
              catch (UnauthorizedException)
              {
                  throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.Forbidden));
              }
              catch (MixERPException ex)
              {
                  throw new HttpResponseException(new HttpResponseMessage
                  {
                      Content = new StringContent(ex.Message),
                      StatusCode = HttpStatusCode.InternalServerError
                  });
              }
              catch
              {
                  throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError));
              }
          }
  
          /// <summary>
          ///     Returns all collection of inventory transfer delivery detail.
          /// </summary>
          /// <returns></returns>
          [AcceptVerbs("GET", "HEAD")]
          [Route("all")]
          [Route("~/api/transactions/inventory-transfer-delivery-detail/all")]
          public IEnumerable<MixERP.Net.Entities.Transactions.InventoryTransferDeliveryDetail> GetAll()
          {
              try
              {
                  return this.InventoryTransferDeliveryDetailRepository.GetAll();
              }
              catch (UnauthorizedException)
              {
                  throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.Forbidden));
              }
              catch (MixERPException ex)
              {
                  throw new HttpResponseException(new HttpResponseMessage
                  {
                      Content = new StringContent(ex.Message),
                      StatusCode = HttpStatusCode.InternalServerError
                  });
              }
              catch
              {
                  throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError));
              }
          }
  
          /// <summary>
          ///     Returns collection of inventory transfer delivery detail for export.
          /// </summary>
          /// <returns></returns>
          [AcceptVerbs("GET", "HEAD")]
          [Route("export")]
          [Route("~/api/transactions/inventory-transfer-delivery-detail/export")]
          public IEnumerable<dynamic> Export()
          {
              try
              {
                  return this.InventoryTransferDeliveryDetailRepository.Export();
              }
              catch (UnauthorizedException)
              {
                  throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.Forbidden));
              }
              catch (MixERPException ex)
              {
                  throw new HttpResponseException(new HttpResponseMessage
                  {
                      Content = new StringContent(ex.Message),
                      StatusCode = HttpStatusCode.InternalServerError
                  });
              }
              catch
              {
                  throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError));
              }
          }
  
          /// <summary>
          ///     Returns an instance of inventory transfer delivery detail.
          /// </summary>
          /// <param name="inventoryTransferDeliveryDetailId">Enter InventoryTransferDeliveryDetailId to search for.</param>
          /// <returns></returns>
          [AcceptVerbs("GET", "HEAD")]
          [Route("{inventoryTransferDeliveryDetailId}")]
          [Route("~/api/transactions/inventory-transfer-delivery-detail/{inventoryTransferDeliveryDetailId}")]
          public MixERP.Net.Entities.Transactions.InventoryTransferDeliveryDetail Get(long inventoryTransferDeliveryDetailId)
          {
              try
              {
                  return this.InventoryTransferDeliveryDetailRepository.Get(inventoryTransferDeliveryDetailId);
              }
              catch (UnauthorizedException)
              {
                  throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.Forbidden));
              }
              catch (MixERPException ex)
              {
                  throw new HttpResponseException(new HttpResponseMessage
                  {
                      Content = new StringContent(ex.Message),
                      StatusCode = HttpStatusCode.InternalServerError
                  });
              }
              catch
              {
                  throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError));
              }
          }
  
          [AcceptVerbs("GET", "HEAD")]
          [Route("get")]
          [Route("~/api/transactions/inventory-transfer-delivery-detail/get")]
          public IEnumerable<MixERP.Net.Entities.Transactions.InventoryTransferDeliveryDetail> Get([FromUri] long[] inventoryTransferDeliveryDetailIds)
          {
              try
              {
                  return this.InventoryTransferDeliveryDetailRepository.Get(inventoryTransferDeliveryDetailIds);
              }
              catch (UnauthorizedException)
              {
                  throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.Forbidden));
              }
              catch (MixERPException ex)
              {
                  throw new HttpResponseException(new HttpResponseMessage
                  {
                      Content = new StringContent(ex.Message),
                      StatusCode = HttpStatusCode.InternalServerError
                  });
              }
              catch
              {
                  throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError));
              }
          }
  
          /// <summary>
          ///     Creates a paginated collection containing 10 inventory transfer delivery details on each page, sorted by the property InventoryTransferDeliveryDetailId.
          /// </summary>
          /// <returns>Returns the first page from the collection.</returns>
          [AcceptVerbs("GET", "HEAD")]
          [Route("")]
          [Route("~/api/transactions/inventory-transfer-delivery-detail")]
          public IEnumerable<MixERP.Net.Entities.Transactions.InventoryTransferDeliveryDetail> GetPaginatedResult()
          {
              try
              {
                  return this.InventoryTransferDeliveryDetailRepository.GetPaginatedResult();
              }
              catch (UnauthorizedException)
              {
                  throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.Forbidden));
              }
              catch (MixERPException ex)
              {
                  throw new HttpResponseException(new HttpResponseMessage
                  {
                      Content = new StringContent(ex.Message),
                      StatusCode = HttpStatusCode.InternalServerError
                  });
              }
              catch
              {
                  throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError));
              }
          }
  
          /// <summary>
          ///     Creates a paginated collection containing 10 inventory transfer delivery details on each page, sorted by the property InventoryTransferDeliveryDetailId.
          /// </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/transactions/inventory-transfer-delivery-detail/page/{pageNumber}")]
          public IEnumerable<MixERP.Net.Entities.Transactions.InventoryTransferDeliveryDetail> GetPaginatedResult(long pageNumber)
          {
              try
              {
                  return this.InventoryTransferDeliveryDetailRepository.GetPaginatedResult(pageNumber);
              }
              catch (UnauthorizedException)
              {
                  throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.Forbidden));
              }
              catch (MixERPException ex)
              {
                  throw new HttpResponseException(new HttpResponseMessage
                  {
  
gt:                     Content = new StringContent(ex.Message),