using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Web;
using System.Web.Services;
using System.Collections.Specialized;
using Microsoft.ApplicationBlocks.ExceptionManagement;
using System.Web.Services.Protocols;

namespace Northwind
{
	/// <summary>
	/// Summary description for NorthwindBusinessLogicLayer.
	/// </summary>
	public class NorthwindBusinessLogicLayer : System.Web.Services.WebService
	{
		public NorthwindBusinessLogicLayer()
		{
			//CODEGEN: This call is required by the ASP.NET Web Services Designer
			InitializeComponent();
		}

		#region Component Designer generated code
		
		//Required by the Web Services Designer 
		private IContainer components = null;
				
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if(disposing && components != null)
			{
				components.Dispose();
			}
			base.Dispose(disposing);		
		}
		
		#endregion


		private NorthwindDataAccess GetDataAccess()
		{
			return new NorthwindDataAccess();
		}

		[WebMethod]
		public Northwind.dsCustomers RetrieveCustomer(string ID)
		{
			try
			{
				using(NorthwindDataAccess nwda = GetDataAccess())
				{
					return nwda.RetrieveCustomer(ID);
				}
			}
			catch(Exception e)
			{
				ExceptionManager.Publish(e);
				throw new SoapException(
					"Web Service Exception"
					,SoapException.ServerFaultCode
					,e);
			}
		}
		
		[WebMethod]
		public int RetrieveCustomerCount()
		{
			try
			{
				using(NorthwindDataAccess nwda = GetDataAccess())
				{
					return nwda.RetrieveCustomerCount();
				}
			}
			catch(Exception e)
			{
				ExceptionManager.Publish(e);
				throw new SoapException(
					"Web Service Exception"
					,SoapException.ServerFaultCode
					,e);
			}
		}
		
		[WebMethod]
		public StringCollection RetrieveCustomerCountryList()
		{
			try
			{
				using(NorthwindDataAccess nwda = GetDataAccess())
				{
					return nwda.RetrieveCustomerCountryList();
				}
			}
			catch(Exception e)
			{
				ExceptionManager.Publish(e);
				throw new SoapException(
					"Web Service Exception"
					,SoapException.ServerFaultCode
					,e);
			}
		}
		
		[WebMethod]
		public DataSet RetrieveCustomerList()
		{
			try
			{
				using(NorthwindDataAccess nwda = GetDataAccess())
				{
					return nwda.RetrieveCustomerList();
				}
			}
			catch(Exception e)
			{
				ExceptionManager.Publish(e);
				throw new SoapException(
					"Web Service Exception"
					,SoapException.ServerFaultCode
					,e);
			}
		}

		[WebMethod]
		public StringCollection RetrieveCustomerRegionList()
		{
			try
			{
				using(NorthwindDataAccess nwda = GetDataAccess())
				{
					return nwda.RetrieveCustomerRegionList();
				}
			}
			catch(Exception e)
			{
				ExceptionManager.Publish(e);
				throw new SoapException(
					"Web Service Exception"
					,SoapException.ServerFaultCode
					,e);
			}
		}

		[WebMethod]		
		public dsCustomers RetrieveCustomers()
		{
			try
			{
				using(NorthwindDataAccess nwda = GetDataAccess())
				{
					return nwda.RetrieveCustomers();
				}
			}
			catch(Exception e)
			{
				ExceptionManager.Publish(e);
				throw new SoapException(
					"Web Service Exception"
					,SoapException.ServerFaultCode
					,e);
			}
		}

		[WebMethod]
		public Northwind.dsEmployees RetrieveEmployees()
		{
			try
			{
				using(NorthwindDataAccess nwda = GetDataAccess())
				{
					return nwda.RetrieveEmployees();
				}
			}
			catch(Exception e)
			{
				ExceptionManager.Publish(e);
				throw new SoapException(
					"Web Service Exception"
					,SoapException.ServerFaultCode
					,e);
			}
		}

		[WebMethod]
		public int RetrieveOrderCount()
		{
			try
			{
				using(NorthwindDataAccess nwda = GetDataAccess())
				{
					return nwda.RetrieveOrderCount();
				}
			}
			catch(Exception e)
			{
				ExceptionManager.Publish(e);
				throw new SoapException(
					"Web Service Exception"
					,SoapException.ServerFaultCode
					,e);
			}
		}

		[WebMethod]
		public Northwind.dsOrders RetrieveOrders(int EmployeeID
			, string CustomerID)
		{
			try
			{
				using(NorthwindDataAccess nwda = GetDataAccess())
				{
					return nwda.RetrieveOrders(EmployeeID
						, CustomerID);
				}
			}
			catch(Exception e)
			{
				ExceptionManager.Publish(e);
				throw new SoapException(
					"Web Service Exception"
					,SoapException.ServerFaultCode
					,e);
			}
		}

		[WebMethod]
		public Northwind.dsOrdersOrderDetails RetrieveOrdersOrderDetails()
		{
			try
			{
				using(NorthwindDataAccess nwda = GetDataAccess())
				{
					return nwda.RetrieveOrdersOrderDetails();
				}
			}
			catch(Exception e)
			{
				ExceptionManager.Publish(e);
				throw new SoapException(
					"Web Service Exception"
					,SoapException.ServerFaultCode
					,e);
			}
		}

		[WebMethod]
		public Northwind.dsProducts RetrieveProducts()
		{
			try
			{
				using(NorthwindDataAccess nwda = GetDataAccess())
				{
					return nwda.RetrieveProducts();
				}
			}
			catch(Exception e)
			{
				ExceptionManager.Publish(e);
				throw new SoapException(
					"Web Service Exception"
					,SoapException.ServerFaultCode
					,e);
			}
		}

		[WebMethod]
		public Northwind.dsRegionTerritoryEmployeeCustomer
			RetrieveRegionTerritoryEmployeeCustomer()
		{
			try
			{
				using(NorthwindDataAccess nwda = GetDataAccess())
				{
					return nwda.
						RetrieveRegionTerritoryEmployeeCustomer();
				}
			}
			catch(Exception e)
			{
				ExceptionManager.Publish(e);
				throw new SoapException(
					"Web Service Exception"
					,SoapException.ServerFaultCode
					,e);
			}
		}

		[WebMethod]
		public void UpdateCustomers(Northwind.dsCustomers custs)
		{
			try
			{
				using(NorthwindDataAccess nwda = GetDataAccess())
				{
					nwda.UpdateCustomers(custs);
				}
			}
			catch(Exception e)
			{
				ExceptionManager.Publish(e);
				throw new SoapException(
					"Web Service Exception"
					,SoapException.ServerFaultCode
					,e);
			}
		}

		[WebMethod]
		public void UpdateEmployees(Northwind.dsEmployees emps)
		{
			try
			{
				using(NorthwindDataAccess nwda = GetDataAccess())
				{
					nwda.UpdateEmployees(emps);
				}
			}
			catch(Exception e)
			{
				ExceptionManager.Publish(e);
				throw new SoapException(
					"Web Service Exception"
					,SoapException.ServerFaultCode
					,e);
			}
		}

		[WebMethod]
		public void UpdateProducts(Northwind.dsProducts
			Products)
		{
			try
			{
				using(NorthwindDataAccess nwda = GetDataAccess())
				{
					nwda.UpdateProducts(Products);
				}
			}
			catch(Exception e)
			{
				ExceptionManager.Publish(e);
				throw new SoapException(
					"Web Service Exception"
					,SoapException.ServerFaultCode
					,e);
			}
		}

		[WebMethod]
		public void UpdateOrdersOrderDetails(
			Northwind.dsOrdersOrderDetails orders)
		{
			try
			{
				using(NorthwindDataAccess nwda = GetDataAccess())
				{
					nwda.UpdateOrdersOrderDetails(
						orders);
				}
			}
			catch(Exception e)
			{
				ExceptionManager.Publish(e);
				throw new SoapException(
					"Web Service Exception"
					,SoapException.ServerFaultCode
					,e);
			}
		}
	}
}
