context: // ReSharper disable All
  using System.Collections.Generic;
  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 Party Purchase Chart Views.
      /// </summary>
      [RoutePrefix("api/v1.5/transactions/party-purchase-chart-view")]
      public class PartyPurchaseChartViewController : ApiController
      {
          /// <summary>
          ///     The PartyPurchaseChartView repository.
          /// </summary>
          private readonly IPartyPurchaseChartViewRepository PartyPurchaseChartViewRepository;
  
          public PartyPurchaseChartViewController()
          {
              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.PartyPurchaseChartViewRepository = new MixERP.Net.Schemas.Transactions.Data.PartyPurchaseChartView
              {
                  _Catalog = this._Catalog,
                  _LoginId = this._LoginId,
                  _UserId = this._UserId
              };
          }
  
          public PartyPurchaseChartViewController(IPartyPurchaseChartViewRepository repository, string catalog, LoginView view)
          {
              this._LoginId = view.LoginId.ToLong();
              this._UserId = view.UserId.ToInt();
              this._OfficeId = view.OfficeId.ToInt();
              this._Catalog = catalog;
  
              this.PartyPurchaseChartViewRepository = repository;
          }
  
          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 party purchase chart views.
          /// </summary>
          /// <returns>Returns the count of the party purchase chart views.</returns>
          [AcceptVerbs("GET", "HEAD")]
          [Route("count")]
          [Route("~/api/transactions/party-purchase-chart-view/count")]
          public long Count()
          {
              try
              {
                  return this.PartyPurchaseChartViewRepository.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 collection of party purchase chart view for export.
          /// </summary>
          /// <returns></returns>
          [AcceptVerbs("GET", "HEAD")]
          [Route("export")]
          [Route("all")]
          [Route("~/api/transactions/party-purchase-chart-view/export")]
          [Route("~/api/transactions/party-purchase-chart-view/all")]
          public IEnumerable<MixERP.Net.Entities.Transactions.PartyPurchaseChartView> Get()
          {
              try
              {
                  return this.PartyPurchaseChartViewRepository.Get();
              }
              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 party purchase chart views on each page, sorted by the property .
          /// </summary>
          /// <returns>Returns the first page from the collection.</returns>
          [AcceptVerbs("GET", "HEAD")]
          [Route("")]
          [Route("~/api/transactions/party-purchase-chart-view")]
          public IEnumerable<MixERP.Net.Entities.Transactions.PartyPurchaseChartView> GetPaginatedResult()
          {
              try
              {
                  return this.PartyPurchaseChartViewRepository.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 party purchase chart views on each page, sorted by the property .
          /// </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/party-purchase-chart-view/page/{pageNumber}")]
          public IEnumerable<MixERP.Net.Entities.Transactions.PartyPurchaseChartView> GetPaginatedResult(long pageNumber)
          {
              try
              {
                  return this.PartyPurchaseChartViewRepository.GetPaginatedResult(pageNumber);
              }
              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>
          ///     Displayfield is a lightweight key/value collection of party purchase chart views.
          /// </summary>
          /// <returns>Returns an enumerable key/value collection of party purchase chart views.</returns>
          [AcceptVerbs("GET", "HEAD")]
          [Route("display-fields")]
          [Route("~/api/transactions/party-purchase-chart-view/display-fields")]
          public IEnumerable<DisplayField> GetDisplayFields()
          {
              try
              {
                  return this.PartyPurchaseChartViewRepository.GetDisplayFields();
              }
              catch (UnauthorizedException)
              {
                  throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.Forbidden));
              }
              catch (MixERPException ex)
              {
                  throw new HttpResponseException(new HttpResponseMessage
                  {
  
gt:                     Content = new StringContent(ex.Message),