//---------------------------------------------------------------------------------------------
// 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>
    /// Cross-reference table mapping people to their credit card information in the CreditCard table. 
    ///</summary>
    public partial class PersonCreditCardController : BaseController
    {
        private readonly IPersonCreditCardService svc;

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

        ///<summary>
        /// Reads a list of Person Credit Card objects based on the specified criteria.
        ///</summary>
        [Route("person/{_businessEntityId}/credit-card")]
        [HttpGet]
        public async Task<ActionResult> ReadListAsync([FromRoute] int _businessEntityId)
        {
            ActionResult response;
            try
            {
                if (ModelState.IsValid)
                {
                    Output<ICollection<PersonCreditCard_ReadListOutput>> output = await svc.ReadListAsync(_businessEntityId);
                    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;
        }
    }
}