
namespace VideoDistanc.Web
{
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.ComponentModel.DataAnnotations;
    using System.Data;
    using System.Linq;
    using System.ServiceModel.DomainServices.EntityFramework;
    using System.ServiceModel.DomainServices.Hosting;
    using System.ServiceModel.DomainServices.Server;


    // Implements application logic using the ChatDatabaseEntities 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 ChatService : LinqToEntitiesDomainService<ChatDatabaseEntities>
    {

        // TODO:
        // Consider constraining the results of your query method.  If you need additional input you can
        // add parameters to this method or create additional query methods with different names.
        // To support paging you will need to add ordering to the 'ChatLists' query.
        public IQueryable<ChatList> GetChatLists()
        {
            return this.ObjectContext.ChatLists.OrderBy(e => e.id);
        }

        public void InsertChatList(ChatList chatList)
        {
            TimeSpan timeNow = DateTime.Now.TimeOfDay;
            TimeSpan trimmedTimeNow = new TimeSpan(timeNow.Hours, timeNow.Minutes, timeNow.Seconds);
            chatList.Time = trimmedTimeNow;
            if ((chatList.EntityState != EntityState.Detached))
            {
                this.ObjectContext.ObjectStateManager.ChangeObjectState(chatList, EntityState.Added);
            }
            else
            {
                this.ObjectContext.ChatLists.AddObject(chatList);
            }
        }

        public void UpdateChatList(ChatList currentChatList)
        {
            this.ObjectContext.ChatLists.AttachAsModified(currentChatList, this.ChangeSet.GetOriginal(currentChatList));
        }

        public void DeleteChatList(ChatList chatList)
        {
            if ((chatList.EntityState == EntityState.Detached))
            {
                this.ObjectContext.ChatLists.Attach(chatList);
            }
            this.ObjectContext.ChatLists.DeleteObject(chatList);
        }
    }
}


