//---------------------------------------------------------------------------------------------
// This file was AUTO-GENERATED by "Web API Controllers" Xomega.Net generator.
//
// Manual CHANGES to this file WILL BE LOST when the code is regenerated.
//---------------------------------------------------------------------------------------------

using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Xomega.Framework;
using Xomega.Framework.Services;

namespace AdventureWorks.Services.Rest
{
    ///<summary>
    /// Sales territory lookup table.
    ///</summary>
    public partial class SalesTerritoryController : BaseController
    {
        private readonly ISalesTerritoryService svc;

        public SalesTerritoryController(ErrorList errorList, ErrorParser errorParser, ISalesTerritoryService service)
            : base(errorList, errorParser)
        {
            svc = service;
        }

        ///<summary>
        /// Reads a list of Sales Territory objects based on the specified criteria.
        ///</summary>
        [Route("sales-territory")]
        [HttpGet]
        public async Task<ActionResult> ReadListAsync()
        {
            ActionResult response;
            try
            {
                if (ModelState.IsValid)
                {
                    Output<ICollection<SalesTerritory_ReadListOutput>> output = await svc.ReadListAsync();
                    response = StatusCode((int)output.HttpStatus, output);
                    return response;
                }
                else
                {
                    currentErrors.AddModelErrors(ModelState);
                }
            }
            catch (Exception ex)
            {
                currentErrors.MergeWith(errorsParser.FromException(ex));
            }
            response = StatusCode((int)currentErrors.HttpStatus, new Output(currentErrors));
            return response;
        }
    }
}