//---------------------------------------------------------------------------------------------
// 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>
    /// Current customer information. Also see the Person and Store tables.
    ///</summary>
    public partial class CustomerController : BaseController
    {
        private readonly ICustomerService svc;

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

        ///<summary>
        /// Reads a list of Customer objects based on the specified criteria.
        ///</summary>
        [Route("customer")]
        [HttpGet]
        public async Task<ActionResult> ReadListAsync([FromQuery] Customer_ReadListInput_Criteria _criteria)
        {
            ActionResult response;
            try
            {
                if (ModelState.IsValid)
                {
                    Output<ICollection<Customer_ReadListOutput>> output = await svc.ReadListAsync(_criteria);
                    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;
        }
    }
}