using System;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.Collections.Generic;
using System.Text;
using System.Collections.ObjectModel;
namespace TrailerPlayer.Web
{
    [ServiceContract(Namespace = "")]
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    public class MovieSearchService
    {
       

        [OperationContract]
        public ObservableCollection<Movie> Search(string key)
        {
            IQueryable<Movie> q;
            using (MovieDataContext dc = new MovieDataContext())
            {
                if (key == null)
                {
                    q = from m in dc.Movies
                        select m;
                }
                else
                {
                    q = from m in dc.Movies
                        where m.Title.Contains(key) || m.Cast.Contains(key) || m.Director.Contains(key) || m.Type.Contains(key)
                        select m;
                }
                
                return new ObservableCollection<Movie>(q.ToList<Movie>());
            }
            
        }

        // Add more operations here and mark them with [OperationContract]
    }
}
