public ResponseBase Any(CloseSession request)
        {
            _logger.Log(EErrorType.Info, " ****** Call start: CloseSession");
            CloseSessionResponse response = new CloseSessionResponse();

            try
            {
                _logger.Log(EErrorType.Info, string.Format("Closing Session: {0}", request.SessionToken));
                Interfaces.DAL.SessionInfo sinfo = new Interfaces.DAL.SessionInfo();
                sinfo.SessionEnd = DateTime.UtcNow;
                sinfo.SessionId  = request.SessionToken;

                _dal.CloseSession(sinfo);

                response.Success = true;
            }
            catch (Exception ex)
            {
                _logger.Log(ex);
                response.Success = false;
                response.Errors.Add(new Error()
                {
                    Code = EErrorCodes.GeneralError, Type = EErrorType.Error, Message = string.Format("Unexpected error: {0}", ex.Message)
                });
            }

            _logger.Log(EErrorType.Info, " ****** Call end: CloseSession");

            return(response);
        }
        public ResponseBase Any(InitSession request)
        {
            _logger.Log(EErrorType.Info, " ****** Call start: InitSession");
            InitSessionResponse response = new InitSessionResponse();

            try
            {
                // checking account key validity
                GetUserAccountInfoParams accParams = new GetUserAccountInfoParams();
                accParams.AccountKey = request.AccountKey;
                GetUserAccountInfoResult accResult = _dal.GetUserAccountInfo(accParams);
                if (accResult != null)
                {
                    string sessionId = Guid.NewGuid().ToString();

                    Interfaces.DAL.SessionInfo sinfo = new Interfaces.DAL.SessionInfo();
                    sinfo.AccountKey     = request.AccountKey;
                    sinfo.SessionStart   = DateTime.UtcNow;
                    sinfo.SessionExpires = DateTime.UtcNow
                                           + TimeSpan.FromMinutes(ConfigurationManager.AppSettings["SessionExpiresMins"] != null ? Int32.Parse(ConfigurationManager.AppSettings["SessionExpiresMins"]) : 60);
                    sinfo.SessionId = sessionId;

                    // if current session exists - we are just using current session token
                    Interfaces.DAL.SessionInfo existSession = _dal.GetSessionInfo(sinfo, true);
                    if (existSession == null)
                    {
                        _dal.InitSession(sinfo);

                        response.SessionToken = sessionId;
                    }
                    response.Success = true;
                }
                else
                {
                    response.Success = false;
                    response.Errors.Add(new Error()
                    {
                        Code = EErrorCodes.UserAccountNotFound, Type = EErrorType.Error, Message = "Invalid account key provided"
                    });
                }
            }
            catch (Exception ex)
            {
                _logger.Log(ex);
                response.Success = false;
                response.Errors.Add(new Error()
                {
                    Code = EErrorCodes.GeneralError, Type = EErrorType.Error, Message = string.Format("Unexpected error: {0}", ex.Message)
                });
            }

            _logger.Log(EErrorType.Info, " ****** Call end: InitSession");

            return(response);
        }
        public ResponseBase Any(GetSessionInfo request)
        {
            _logger.Log(EErrorType.Info, " ****** Call start: GetSessionInfo");
            GetSessionInfoResponse response = new GetSessionInfoResponse();

            try
            {
                Interfaces.DAL.SessionInfo sinfo = new Interfaces.DAL.SessionInfo();

                sinfo.SessionId = !string.IsNullOrEmpty(request.SessionToken) ? request.SessionToken : string.Empty;

                _logger.Log(EErrorType.Info, string.Format("_dal.GetSessionInfo({0}, {1})", sinfo.SessionId, request.CheckActive));

                sinfo = _dal.GetSessionInfo(sinfo, request.CheckActive);
                if (sinfo != null)
                {
                    response.Payload.SessionStart = sinfo.SessionStart;
                    response.Payload.SessionEnd   = sinfo.SessionEnd;
                    if (!request.CheckActive)
                    {
                        // checking all sessions - just returning the warning that this session was closed
                        if (response.Payload.SessionEnd > DateTime.MinValue)
                        {
                            response.Errors.Add(new Error()
                            {
                                Code = EErrorCodes.SessionClosed, Message = "Session with given token was closed", Type = EErrorType.Warning
                            });
                        }
                        response.Success = true;
                    }
                    else
                    {
                        // checking for active session!
                        // if expiration date >= now - closing the session and returning error; in other case returning true
                        _logger.Log(EErrorType.Info, string.Format("Expires: {0}, Now: {1}", sinfo.SessionExpires, DateTime.UtcNow));
                        if (sinfo.SessionExpires <= DateTime.UtcNow)
                        {
                            _logger.Log(EErrorType.Info, string.Format("Closing session {0}", sinfo.SessionId));
                            sinfo.SessionEnd = DateTime.UtcNow;
                            _dal.CloseSession(sinfo);

                            response.Errors.Add(new Error()
                            {
                                Code = EErrorCodes.SessionClosed, Message = "Session with given token expired and was closed", Type = EErrorType.Error
                            });
                            response.Success = false;
                        }
                        else
                        {
                            response.Success = true;
                        }
                    }
                }
                else
                {
                    response.Errors.Add(new Error()
                    {
                        Code = EErrorCodes.InvalidSession, Message = "Invalid session token", Type = EErrorType.Error
                    });
                }
            }
            catch (Exception ex)
            {
                _logger.Log(ex);
                response.Success = false;
                response.Errors.Add(new Error()
                {
                    Code = EErrorCodes.GeneralError, Type = EErrorType.Error, Message = string.Format("Unexpected error: {0}", ex.Message)
                });
            }

            _logger.Log(EErrorType.Info, " ****** Call end: GetSessionInfo");

            return(response);
        }
        public ResponseBase Any(Login request)
        {
            LoginResponse response = new LoginResponse();

            _logger.Log(EErrorType.Info, " ****** Call start: Login");

            try
            {
                GetUserAccountInfoParams accParams = new GetUserAccountInfoParams();
                accParams.AccountKey = null;
                accParams.Email      = request.Email;
                GetUserAccountInfoResult accResult = _dal.GetUserAccountInfo(accParams);
                if (accResult != null)
                {
                    string pwdHash = EncodeUtils.GetPasswordHash(request.Pwd);
                    if (accResult.PwdHash == pwdHash)
                    {
                        string sessionId = Guid.NewGuid().ToString();

                        Interfaces.DAL.SessionInfo sinfo = new Interfaces.DAL.SessionInfo();
                        sinfo.AccountKey     = accResult.AccountKey;
                        sinfo.SessionStart   = DateTime.UtcNow;
                        sinfo.SessionExpires = DateTime.UtcNow
                                               + TimeSpan.FromMinutes(ConfigurationManager.AppSettings["SessionExpiresMins"] != null ? Int32.Parse(ConfigurationManager.AppSettings["SessionExpiresMins"]) : 60);
                        sinfo.SessionId = sessionId;

                        _dal.InitSession(sinfo);

                        response.SessionToken = sessionId;

                        response.Success = true;
                    }
                    else
                    {
                        response.Success = false;
                        response.Errors.Add(new Error()
                        {
                            Code = EErrorCodes.UserAccountNotFound, Type = EErrorType.Error, Message = "Email / password combination not found"
                        });
                    }
                }
                else
                {
                    response.Success = false;
                    response.Errors.Add(new Error()
                    {
                        Code = EErrorCodes.UserAccountNotFound, Type = EErrorType.Error, Message = "Account not found"
                    });
                }
            }
            catch (Exception ex)
            {
                _logger.Log(ex);
                response.Success = false;
                response.Errors.Add(new Error()
                {
                    Code = EErrorCodes.GeneralError, Type = EErrorType.Error, Message = string.Format("Unexpected error: {0}", ex.Message)
                });
            }

            return(response);
        }