﻿//====================================================================================================
// Base code generated with LeatherGoods - ASF.Services.Http
// Architecture Solutions Foundation
//
// Generated by academic at LeatherGoods V 1.0 
//====================================================================================================

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using ASF.Business;
using ASF.Entities;
using ASF.Services.Contracts;
using ASF.Services.Contracts.Responses;

namespace ASF.Services.Http
{

    /// <summary>
    /// OrderDetail HTTP service controller.
    /// </summary>
    [RoutePrefix("rest/OrderDetail")]
    public class OrderDetailService : ApiController
    {

        [HttpPost]
        [Route("Add")]
        public OrderDetail Add(OrderDetail orderDetail)
        {
            try
            {
                var bo = new OrderDetailBusiness();
                return bo.Add(orderDetail);
            }
            catch (Exception ex)
            {
                var httpError = new HttpResponseMessage()
                {
                    StatusCode = (HttpStatusCode)422,
                    ReasonPhrase = ex.Message
                };

                throw new HttpResponseException(httpError);
            }
        }

        [HttpGet]
        [Route("All")]
        public AllOrderDetailResponse All()
        {
            try
            {
                var response = new AllOrderDetailResponse();
                var bo = new OrderDetailBusiness();
                response.Result = bo.All();
                return response;
            }
            catch (Exception ex)
            {
                var httpError = new HttpResponseMessage()
                {
                    StatusCode = (HttpStatusCode)422,
                    ReasonPhrase = ex.Message
                };

                throw new HttpResponseException(httpError);
            }
        }

        [HttpPost]
        [Route("Edit")]
        public void Edit(OrderDetail orderDetail)
        {
            try
            {
                var bo = new OrderDetailBusiness();
                orderDetail.ChangedOn = System.DateTime.Now;
                bo.Edit(orderDetail);
            }
            catch (Exception ex)
            {
                var httpError = new HttpResponseMessage()
                {
                    StatusCode = (HttpStatusCode)422,
                    ReasonPhrase = ex.Message
                };

                throw new HttpResponseException(httpError);
            }
        }

        [HttpGet]
        [Route("Find")]
        public FindOrderDetailResponse Find(int id)
        {
            try
            {
                var response = new FindOrderDetailResponse();
                var bo = new OrderDetailBusiness();
                response.Result = bo.Find(id);
                return response;
            }
            catch (Exception ex)
            {
                var httpError = new HttpResponseMessage()
                {
                    StatusCode = (HttpStatusCode)422,
                    ReasonPhrase = ex.Message
                };

                throw new HttpResponseException(httpError);
            }
        }

        [HttpGet]
        [Route("FindByOrderId")]
        public AllOrderDetailResponse FindByOrderId(int on)
        {
            try
            {
                var response = new AllOrderDetailResponse();
                var odb = new OrderDetailBusiness();
                response.Result = odb.FindByOrderId(on);
                return response;
            }
            catch (Exception ex)
            {
                var httpError = new HttpResponseMessage()
                {
                    StatusCode = (HttpStatusCode)422,
                    ReasonPhrase = ex.Message
                };

                throw new HttpResponseException(httpError);
            }
        }

        [HttpGet]
        [Route("Remove")]
        public void Remove(int id)
        {
            try
            {
                var bo = new OrderDetailBusiness();
                bo.Remove(id);
            }
            catch (Exception ex)
            {
                var httpError = new HttpResponseMessage()
                {
                    StatusCode = (HttpStatusCode)422,
                    ReasonPhrase = ex.Message
                };

                throw new HttpResponseException(httpError);
            }
        }


    }
}
