using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Drawing.Design;
using System.ComponentModel;
using System.Web.Script.Services;
using Telerik.RadTips.Data;
using Telerik.RadTips.Entities;
using System.Collections;

namespace Telerik.RadTips
{
	[WebService]
	[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
	[ToolboxItem(false)]
	[ScriptService]
	public class NorthwindService : WebService
	{
		[WebMethod]
		public Dictionary<string, object> GetCustomers(int startIndex, int rowCount)
		{
			var northwind = new NorthwindDataContext();
			var customers = from c in northwind.Customers
							select c;
			return new Dictionary<string, object> { 
				{ "Customers", customers.Skip(startIndex).Take(rowCount) }, 
				{ "CustomerCount", customers.Count() } 
			};
		}

		[WebMethod]
		public Dictionary<string, object> GetOrders(string[] customerIDs)
		{
			var northwind = new NorthwindDataContext();
			var orders = from o in northwind.Orders
						 where customerIDs.Contains(o.CustomerID)
						 select new
						 {
							 OrderDate = o.OrderDate.Value.ToShortDateString(),
							 Quantity = o.OrderDetails.Sum(od => od.Quantity),
							 Price = o.OrderDetails.Sum(od => (decimal)(1 - od.Discount) * od.Quantity * od.UnitPrice),
							 Destination = o.ShipCountry
						 };
			return new Dictionary<string, object> {
				{ "Orders", orders },
				{ "OrderCount", orders.Count() }
			};
		}
	}
}
