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 Employment Status Codes.
      /// </summary>
      [RoutePrefix("api/v1.5/hrm/employment-status-code")]
      public class EmploymentStatusCodeController : ApiController
      {
          /// <summary>
          ///     The EmploymentStatusCode data context.
          /// </summary>
          private readonly MixERP.Net.Core.Modules.HRM.Data.EmploymentStatusCode EmploymentStatusCodeContext;
  
          public EmploymentStatusCodeController()
          {
              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.EmploymentStatusCodeContext = new MixERP.Net.Core.Modules.HRM.Data.EmploymentStatusCode
              {
                  _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 "employment status code" entity.
          /// </summary>
          /// <returns>Returns the "employment status code" meta information to perform CRUD operation.</returns>
          [AcceptVerbs("GET", "HEAD")]
          [Route("meta")]
          [Route("~/api/hrm/employment-status-code/meta")]
          public EntityView GetEntityView()
          {
              return new EntityView
              {
                  PrimaryKey = "employment_status_code_id",
                  Columns = new List<EntityColumn>()
                                  {
                                          new EntityColumn { ColumnName = "employment_status_code_id",  PropertyName = "EmploymentStatusCodeId",  DataType = "int",  DbDataType = "int4",  IsNullable = false,  IsPrimaryKey = true,  IsSerial = false,  Value = "",  MaxLength = 0 },
                                          new EntityColumn { ColumnName = "status_code",  PropertyName = "StatusCode",  DataType = "string",  DbDataType = "varchar",  IsNullable = false,  IsPrimaryKey = false,  IsSerial = false,  Value = "",  MaxLength = 12 },
                                          new EntityColumn { ColumnName = "status_code_name",  PropertyName = "StatusCodeName",  DataType = "string",  DbDataType = "varchar",  IsNullable = false,  IsPrimaryKey = false,  IsSerial = false,  Value = "",  MaxLength = 100 },
                                          new EntityColumn { ColumnName = "audit_user_id",  PropertyName = "AuditUserId",  DataType = "int",  DbDataType = "int4",  IsNullable = true,  IsPrimaryKey = false,  IsSerial = false,  Value = "",  MaxLength = 0 },
                                          new EntityColumn { ColumnName = "audit_ts",  PropertyName = "AuditTs",  DataType = "DateTime",  DbDataType = "timestamptz",  IsNullable = true,  IsPrimaryKey = false,  IsSerial = false,  Value = "",  MaxLength = 0 }
                                  }
              };
          }
  
          /// <summary>
          ///     Counts the number of employment status codes.
          /// </summary>
          /// <returns>Returns the count of the employment status codes.</returns>
          [AcceptVerbs("GET", "HEAD")]
          [Route("count")]
          [Route("~/api/hrm/employment-status-code/count")]
          public long Count()
          {
              try
              {
                  return this.EmploymentStatusCodeContext.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 employment status code for export.
          /// </summary>
          /// <returns></returns>
          [AcceptVerbs("GET", "HEAD")]
          [Route("export")]
          [Route("~/api/hrm/employment-status-code/export")]
          public IEnumerable<MixERP.Net.Entities.HRM.EmploymentStatusCode> Get()
          {
              try
              {
                  return this.EmploymentStatusCodeContext.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 employment status code.
          /// </summary>
          /// <param name="employmentStatusCodeId">Enter EmploymentStatusCodeId to search for.</param>
          /// <returns></returns>
          [AcceptVerbs("GET", "HEAD")]
          [Route("{employmentStatusCodeId}")]
          [Route("~/api/hrm/employment-status-code/{employmentStatusCodeId}")]
          public MixERP.Net.Entities.HRM.EmploymentStatusCode Get(int employmentStatusCodeId)
          {
              try
              {
                  return this.EmploymentStatusCodeContext.Get(employmentStatusCodeId);
              }
              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/employment-status-code/get")]
          public IEnumerable<MixERP.Net.Entities.HRM.EmploymentStatusCode> Get([FromUri] int[] employmentStatusCodeIds)
          {
              try
              {
                  return this.EmploymentStatusCodeContext.Get(employmentStatusCodeIds);
              }
              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 employment status codes on each page, sorted by the property EmploymentStatusCodeId.
          /// </summary>
          /// <returns>Returns the first page from the collection.</returns>
          [AcceptVerbs("GET", "HEAD")]
          [Route("")]
          [Route("~/api/hrm/employment-status-code")]
          public IEnumerable<MixERP.Net.Entities.HRM.EmploymentStatusCode> GetPagedResult()
          {
              try
              {
                  return this.EmploymentStatusCodeContext.GetPagedResult();
              }
              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 employment status codes on each page, sorted by the property EmploymentStatusCodeId.
          /// </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/employment-status-code/page/{pageNumber}")]
          public IEnumerable<MixERP.Net.Entities.HRM.EmploymentStatusCode> GetPagedResult(long pageNumber)
          {
              try
              {
                  return this.EmploymentStatusCodeContext.GetPagedResult(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 employment status codes using the supplied filter(s).
          /// </summary>
          /// <param name="filters">The list of filter conditions.</param>
          /// <returns>Returns the count of filtered employment status codes.</returns>
          [AcceptVerbs("POST")]
          [Route("count-where")]
          [Route("~/api/hrm/employment-status-code/count-where")]
          public long CountWhere([FromBody]JArray filters)
          {
              try
              {
                  List<EntityParser.Filter> f = filters.ToObject<List<EntityParser.Filter>>(JsonHelper.GetJsonSerializer());
                  return this.EmploymentStatusCodeContext.CountWhere(f);
              }
              catch (UnauthorizedException)
              {
                  throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.Forbidden));
              }
              catch (MixERPException ex)
              {
                  throw new HttpResponseException(new HttpResponseMessage
                  {
  
gt:                     Content = new StringContent(ex.Message),