public bool Logout(LoginDataContract logoutData)
 {
     bool flag = false;
     using (LoginRepository loginRepo = new LoginRepository(new ChatDBDataContext()))
     {
         tbl_ChatUserLogin login = loginRepo.Get(logoutData.Username);
         if (login != null)
         {
             flag = ChangeUserStatus(ChatState.OFFLINE, login.Id);
         }
     }
     return flag;
 }
        public int RegisterLogin(LoginDataContract loginData, int profileId)
        {
            int loginId = 0;
            using (LoginRepository loginRepo = new LoginRepository(new ChatDBDataContext()))
            {
                loginRepo.Create(new tbl_ChatUserLogin()
                {
                    Username = loginData.Username, Password = loginData.Password, ProfileId = profileId
                });
                loginRepo.Save();

                loginId = loginRepo.Get(loginData.Username).Id;
            }
            return loginId;
        }
        public bool Logout(LoginDataContract data)
        {
            bool response = false;
            if (callBackCollections.Exists(data.Username))
            {
                callBackCollections.Remove(data.Username);
            }

            IUser user = new UserService();
            response = user.Logout(data);
            /// notify other online users
            Action<string, ChatState> Notify = new Action<string, ChatState>(ServiceUtils.CallBackNotify);
            Notify.Invoke(data.Username, ChatState.OFFLINE);

            return response;
        }
        public bool Login(LoginDataContract data)
        {
            bool response = false;
            if (!callBackCollections.Exists(data.Username))
            {
                callBackCollections.Add(data.Username, OperationContext.Current.GetCallbackChannel<IServiceCallBack>());
            }

            IUser user = new UserService();
            response = user.Login(data);
            /// notify other online users
            Action<string, ChatState> Notify = new Action<string, ChatState>(ServiceUtils.CallBackNotify);
            Notify.Invoke(data.Username, ChatState.ONLINE);

            return response;
        }
        public void Register(RegisterDataContract data)
        {
            if (data == null)
                throw new ArgumentNullException("data", "data cannot be null");

            IUser user = new UserService();
            int profileId = 0;
            int loginId = 0;
            try
            {
                profileId = user.RegisterProfile(data);
            }
            catch (Exception Ex)
            {
                ServiceFaultException SFEx = new ServiceFaultException(Ex.Message, "Register");
                throw new FaultException<ServiceFaultException>(SFEx, new FaultReason(SFEx.Description), new FaultCode("Register"));
            }
            finally
            {
                LoginDataContract loginDetail = new LoginDataContract(data.Username, data.Password);
                loginId = user.RegisterLogin(loginDetail, profileId);

                user.RegisterStatus(ChatState.INITIAL, loginId);

                OperationContext.Current.GetCallbackChannel<IServiceCallBack>().DoLoginCallBack(loginDetail);
            }
        }