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;
  
  namespace MixERP.Net.Api.HRM
  {
      /// <summary>
      ///     Provides a direct HTTP access to perform various tasks such as adding, editing, and removing Salary Frequencies.
      /// </summary>
      [RoutePrefix("api/v1.5/hrm/salary-frequency")]
      public class SalaryFrequencyController : ApiController
      {
          /// <summary>
          ///     The SalaryFrequency data context.
          /// </summary>
          private readonly MixERP.Net.Core.Modules.HRM.Data.SalaryFrequency SalaryFrequencyContext;
  
          public SalaryFrequencyController()
          {
              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.SalaryFrequencyContext = new MixERP.Net.Core.Modules.HRM.Data.SalaryFrequency
              {
                  _Catalog = this._Catalog,
                  _LoginId = this._LoginId,
                  _UserId = this._UserId
              };
          }
  
          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 "salary frequency" entity.
          /// </summary>
          /// <returns>Returns the "salary frequency" meta information to perform CRUD operation.</returns>
          [AcceptVerbs("GET", "HEAD")]
          [Route("meta")]
          [Route("~/api/hrm/salary-frequency/meta")]
          public EntityView GetEntityView()
          {
              return new EntityView
              {
                  PrimaryKey = "salary_frequency_id",
                  Columns = new List<EntityColumn>()
                                  {
                                          new EntityColumn { ColumnName = "salary_frequency_id",  PropertyName = "SalaryFrequencyId",  DataType = "int",  DbDataType = "int4",  IsNullable = false,  IsPrimaryKey = true,  IsSerial = false,  Value = "",  MaxLength = 0 },
                                          new EntityColumn { ColumnName = "salary_frequency_name",  PropertyName = "SalaryFrequencyName",  DataType = "string",  DbDataType = "varchar",  IsNullable = false,  IsPrimaryKey = false,  IsSerial = false,  Value = "",  MaxLength = 128 },
                                          new EntityColumn { ColumnName = "frequency_id",  PropertyName = "FrequencyId",  DataType = "int",  DbDataType = "int4",  IsNullable = true,  IsPrimaryKey = false,  IsSerial = false,  Value = "",  MaxLength = 0 }
                                  }
              };
          }
  
          /// <summary>
          ///     Counts the number of salary frequencies.
          /// </summary>
          /// <returns>Returns the count of the salary frequencies.</returns>
          [AcceptVerbs("GET", "HEAD")]
          [Route("count")]
          [Route("~/api/hrm/salary-frequency/count")]
          public long Count()
          {
              try
              {
                  return this.SalaryFrequencyContext.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 salary frequency for export.
          /// </summary>
          /// <returns></returns>
          [AcceptVerbs("GET", "HEAD")]
          [Route("export")]
          [Route("all")]
          [Route("~/api/hrm/salary-frequency/export")]
          [Route("~/api/hrm/salary-frequency/all")]
          public IEnumerable<MixERP.Net.Entities.HRM.SalaryFrequency> Get()
          {
              try
              {
                  return this.SalaryFrequencyContext.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>
          ///     Returns an instance of salary frequency.
          /// </summary>
          /// <param name="salaryFrequencyId">Enter SalaryFrequencyId to search for.</param>
          /// <returns></returns>
          [AcceptVerbs("GET", "HEAD")]
          [Route("{salaryFrequencyId}")]
          [Route("~/api/hrm/salary-frequency/{salaryFrequencyId}")]
          public MixERP.Net.Entities.HRM.SalaryFrequency Get(int salaryFrequencyId)
          {
              try
              {
                  return this.SalaryFrequencyContext.Get(salaryFrequencyId);
              }
              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/hrm/salary-frequency/get")]
          public IEnumerable<MixERP.Net.Entities.HRM.SalaryFrequency> Get([FromUri] int[] salaryFrequencyIds)
          {
              try
              {
                  return this.SalaryFrequencyContext.Get(salaryFrequencyIds);
              }
              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 salary frequencies on each page, sorted by the property SalaryFrequencyId.
          /// </summary>
          /// <returns>Returns the first page from the collection.</returns>
          [AcceptVerbs("GET", "HEAD")]
          [Route("")]
          [Route("~/api/hrm/salary-frequency")]
          public IEnumerable<MixERP.Net.Entities.HRM.SalaryFrequency> GetPaginatedResult()
          {
              try
              {
                  return this.SalaryFrequencyContext.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 salary frequencies on each page, sorted by the property SalaryFrequencyId.
          /// </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/hrm/salary-frequency/page/{pageNumber}")]
          public IEnumerable<MixERP.Net.Entities.HRM.SalaryFrequency> GetPaginatedResult(long pageNumber)
          {
              try
              {
                  return this.SalaryFrequencyContext.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>
          ///     Counts the number of salary frequencies using the supplied filter(s).
          /// </summary>
          /// <param name="filters">The list of filter conditions.</param>
          /// <returns>Returns the count of filtered salary frequencies.</returns>
          [AcceptVerbs("POST")]
          [Route("count-where")]
          [Route("~/api/hrm/salary-frequency/count-where")]
          public long CountWhere([FromBody]JArray filters)
          {
              try
              {
                  List<EntityParser.Filter> f = filters.ToObject<List<EntityParser.Filter>>(JsonHelper.GetJsonSerializer());
                  return this.SalaryFrequencyContext.CountWhere(f);
              }
              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 filtered and paginated collection containing 10 salary frequencies on each page, sorted by the property SalaryFrequencyId.
          /// </summary>
          /// <param name="pageNumber">Enter the page number to produce the resultset. If you provide a negative number, the result will not be paginated.</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/hrm/salary-frequency/get-where/{pageNumber}")]
          public IEnumerable<MixERP.Net.Entities.HRM.SalaryFrequency> GetWhere(long pageNumber, [FromBody]JArray filters)
          {
              try
              {
                  List<EntityParser.Filter> f = filters.ToObject<List<EntityParser.Filter>>(JsonHelper.GetJsonSerializer());
                  return this.SalaryFrequencyContext.GetWhere(pageNumber, f);
              }
              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>
          ///     Counts the number of salary frequencies using the supplied filter name.
          /// </summary>
          /// <param name="filterName">The named filter.</param>
          /// <returns>Returns the count of filtered salary frequencies.</returns>
          [AcceptVerbs("GET", "HEAD")]
          [Route("count-filtered/{filterName}")]
          [Route("~/api/hrm/salary-frequency/count-filtered/{filterName}")]
          public long CountFiltered(string filterName)
          {
              try
              {
                  return this.SalaryFrequencyContext.CountFiltered(filterName);
              }
              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 filtered and paginated collection containing 10 salary frequencies on each page, sorted by the property SalaryFrequencyId.
          /// </summary>
          /// <param name="pageNumber">Enter the page number to produce the resultset. If you provide a negative number, the result will not be paginated.</param>
          /// <param name="filterName">The named filter.</param>
          /// <returns>Returns the requested page from the collection using the supplied filters.</returns>
          [AcceptVerbs("GET", "HEAD")]
          [Route("get-filtered/{pageNumber}/{filterName}")]
          [Route("~/api/hrm/salary-frequency/get-filtered/{pageNumber}/{filterName}")]
          public IEnumerable<MixERP.Net.Entities.HRM.SalaryFrequency> GetFiltered(long pageNumber, string filterName)
          {
              try
              {
                  return this.SalaryFrequencyContext.GetFiltered(pageNumber, filterName);
              }
              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 salary frequencies.
          /// </summary>
          /// <returns>Returns an enumerable key/value collection of salary frequencies.</returns>
          [AcceptVerbs("GET", "HEAD")]
          [Route("display-fields")]
          [Route("~/api/hrm/salary-frequency/display-fields")]
          public IEnumerable<DisplayField> GetDisplayFields()
          {
              try
              {
                  return this.SalaryFrequencyContext.GetDisplayFields();
              }
              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>
          ///     A custom field is a user defined field for salary frequencies.
          /// </summary>
          /// <returns>Returns an enumerable custom field collection of salary frequencies.</returns>
          [AcceptVerbs("GET", "HEAD")]
          [Route("custom-fields")]
          [Route("~/api/hrm/salary-frequency/custom-fields")]
          public IEnumerable<PetaPoco.CustomField> GetCustomFields()
          {
              try
              {
                  return this.SalaryFrequencyContext.GetCustomFields(null);
              }
              catch (UnauthorizedException)
              {
                  throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.Forbidden));
              }
              catch (MixERPException ex)
              {
                  throw new HttpResponseException(new HttpResponseMessage
                  {
  
gt:                     Content = new StringContent(ex.Message),