
namespace RadGridAndDomainDataSource
{
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.ComponentModel.DataAnnotations;
    using System.Linq;
    using System.Web.Ria;
    using System.Web.Ria.Data;
    using System.Web.DomainServices;
    using System.Data.Linq;
    using System.Web.DomainServices.LinqToSql;


    // Implements application logic using the NorthwindDataContext context.
    // TODO: Add your application logic to these methods or in additional methods.
    [EnableClientAccess()]
    public class NorthwindDomainService : LinqToSqlDomainService<NorthwindDataContext>
    {

        // TODO: Consider
        // 1. Adding parameters to this method and constraining returned results, and/or
        // 2. Adding query methods taking different parameters.
        public IQueryable<Customer> GetCustomers()
        {
            return this.Context.Customers;
        }

        public void InsertCustomer(Customer customer)
        {
            this.Context.Customers.InsertOnSubmit(customer);
        }

        public void UpdateCustomer(Customer currentCustomer)
        {
            this.Context.Customers.Attach(currentCustomer, this.ChangeSet.GetOriginal(currentCustomer));
        }

        public void DeleteCustomer(Customer customer)
        {
            this.Context.Customers.Attach(customer);
            this.Context.Customers.DeleteOnSubmit(customer);
        }

        // TODO: Consider
        // 1. Adding parameters to this method and constraining returned results, and/or
        // 2. Adding query methods taking different parameters.
        public IQueryable<Order> GetOrders()
        {
            return this.Context.Orders;
        }

        public void InsertOrder(Order order)
        {
            this.Context.Orders.InsertOnSubmit(order);
        }

        public void UpdateOrder(Order currentOrder)
        {
            this.Context.Orders.Attach(currentOrder, this.ChangeSet.GetOriginal(currentOrder));
        }

        public void DeleteOrder(Order order)
        {
            this.Context.Orders.Attach(order);
            this.Context.Orders.DeleteOnSubmit(order);
        }
    }
}


