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.Transactions
  {
      /// <summary>
      ///     Provides a direct HTTP access to perform various tasks such as adding, editing, and removing Late Fees.
      /// </summary>
      [RoutePrefix("api/v1.5/transactions/late-fee")]
      public class LateFeeController : ApiController
      {
          /// <summary>
          ///     The LateFee data context.
          /// </summary>
          private readonly MixERP.Net.Schemas.Transactions.Data.LateFee LateFeeContext;
  
          public LateFeeController()
          {
              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.LateFeeContext = new MixERP.Net.Schemas.Transactions.Data.LateFee
              {
                  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 late fees.
          /// </summary>
          /// <returns>Returns the count of the late fees.</returns>
          [AcceptVerbs("GET", "HEAD")]
          [Route("count")]
          [Route("~/api/transactions/late-fee/count")]
          public long Count()
          {
              try
              {
                  return this.LateFeeContext.Count();
              }
              catch (UnauthorizedException)
              {
                  throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.Unauthorized));
              }
              catch
              {
                  throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError));
              }
          }
  
          /// <summary>
          ///     Returns an instance of late fee.
          /// </summary>
          /// <param name="transactionMasterId">Enter TransactionMasterId to search for.</param>
          /// <returns></returns>
          [AcceptVerbs("GET", "HEAD")]
          [Route("{transactionMasterId}")]
          [Route("~/api/transactions/late-fee/{transactionMasterId}")]
          public MixERP.Net.Entities.Transactions.LateFee Get(long transactionMasterId)
          {
              try
              {
                  return this.LateFeeContext.Get(transactionMasterId);
              }
              catch (UnauthorizedException)
              {
                  throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.Unauthorized));
              }
              catch
              {
                  throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError));
              }
          }
  
          /// <summary>
          ///     Creates a paginated collection containing 25 late fees on each page, sorted by the property TransactionMasterId.
          /// </summary>
          /// <returns>Returns the first page from the collection.</returns>
          [AcceptVerbs("GET", "HEAD")]
          [Route("")]
          [Route("~/api/transactions/late-fee")]
          public IEnumerable<MixERP.Net.Entities.Transactions.LateFee> GetPagedResult()
          {
              try
              {
                  return this.LateFeeContext.GetPagedResult();
              }
              catch (UnauthorizedException)
              {
                  throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.Unauthorized));
              }
              catch
              {
                  throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError));
              }
          }
  
          /// <summary>
          ///     Creates a paginated collection containing 25 late fees on each page, sorted by the property TransactionMasterId.
          /// </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/late-fee/page/{pageNumber}")]
          public IEnumerable<MixERP.Net.Entities.Transactions.LateFee> GetPagedResult(long pageNumber)
          {
              try
              {
                  return this.LateFeeContext.GetPagedResult(pageNumber);
              }
              catch (UnauthorizedException)
              {
                  throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.Unauthorized));
              }
              catch
              {
                  throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError));
              }
          }
  
          /// <summary>
          ///     Creates a filtered and paginated collection containing 25 late fees on each page, sorted by the property TransactionMasterId.
          /// </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/transactions/late-fee/get-where/{pageNumber}")]
          public IEnumerable<MixERP.Net.Entities.Transactions.LateFee> GetWhere(long pageNumber, [FromBody]dynamic filters)
          {
              try
              {
                  List<EntityParser.Filter> f = JsonConvert.DeserializeObject<List<EntityParser.Filter>>(filters);
                  return this.LateFeeContext.GetWhere(pageNumber, f);
              }
              catch (UnauthorizedException)
              {
                  throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.Unauthorized));
              }
              catch
              {
                  throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError));
              }
          }
  
          /// <summary>
          ///     Displayfields is a lightweight key/value collection of late fees.
          /// </summary>
          /// <returns>Returns an enumerable key/value collection of late fees.</returns>
          [AcceptVerbs("GET", "HEAD")]
          [Route("display-fields")]
          [Route("~/api/transactions/late-fee/display-fields")]
          public IEnumerable<DisplayField> GetDisplayFields()
          {
              try
              {
                  return this.LateFeeContext.GetDisplayFields();
              }
              catch (UnauthorizedException)
              {
                  throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.Unauthorized));
              }
              catch
              {
                  throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError));
              }
          }
  
          /// <summary>
          ///     Adds your instance of Account class.
          /// </summary>
          /// <param name="lateFee">Your instance of late fees class to add.</param>
          [AcceptVerbs("POST")]
          [Route("add/{lateFee}")]
          [Route("~/api/transactions/late-fee/add/{lateFee}")]
          public void Add(MixERP.Net.Entities.Transactions.LateFee lateFee)
          {
              if (lateFee == null)
              {
                  throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.MethodNotAllowed));
              }
  
              try
              {
                  this.LateFeeContext.Add(lateFee);
              }
              catch (UnauthorizedException)
              {
                  throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.Unauthorized));
              }
              catch
              {
                  throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError));
              }
          }
  
          /// <summary>
          ///     Edits existing record with your instance of Account class.
          /// </summary>
          /// <param name="lateFee">Your instance of Account class to edit.</param>
          /// <param name="transactionMasterId">Enter the value for TransactionMasterId in order to find and edit the existing record.</param>
          [AcceptVerbs("PUT")]
          [Route("edit/{transactionMasterId}/{lateFee}")]
          [Route("~/api/transactions/late-fee/edit/{transactionMasterId}/{lateFee}")]
          public void Edit(long transactionMasterId, MixERP.Net.Entities.Transactions.LateFee lateFee)
          {
  
gt:             if (lateFee == null)