
namespace MasterDetailsWithRIAServices.Web.Services
{
	using System;
	using System.Collections.Generic;
	using System.ComponentModel;
	using System.ComponentModel.DataAnnotations;
	using System.Data;
	using System.Linq;
	using System.Web.DomainServices;
	using System.Web.DomainServices.Providers;
	using System.Web.Ria;
	using System.Web.Ria.Services;
	using MasterDetailsWithRIAServices.Web.Models;


	// Implements application logic using the ChinookEntities context.
	// TODO: Add your application logic to these methods or in additional methods.
	// TODO: Wire up authentication (Windows/ASP.NET Forms) and uncomment the following to disable anonymous access
	// Also consider adding roles to restrict access as appropriate.
	// [RequiresAuthentication]
	[EnableClientAccess()]
	public class ChinookService : LinqToEntitiesDomainService<ChinookEntities>
	{

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

		// TODO: Consider
		// 1. Adding parameters to this method and constraining returned results, and/or
		// 2. Adding query methods taking different parameters.
		public IQueryable<Artist> GetArtists()
		{
			// "Slow Hotel Internet Connection", Copyright of Brad Abrams :)
			System.Threading.Thread.Sleep(2000);
			
			return this.ObjectContext.Artist
				.Where(artist => artist.Album.Count > 5)
				.OrderByDescending(artist => artist.Album.Count)
				;
		}

		public IQueryable<Album> GetAlbumsForArtistId(int artistId)
		{
			return this.ObjectContext.Album
				.Where(album => album.Artist.ArtistId == artistId)
				.OrderBy(album => album.AlbumId); // OrderBy to workaround an issue with EntityFramework.
		}
	}
}


