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

            try
            {
                GetUserAccountInfoParams accParams = new GetUserAccountInfoParams();
                accParams.Email = request.Email;

                GetUserAccountInfoResult accResult = _dal.GetUserAccountInfo(accParams);
                if (accResult == null)
                {
                    // creating account
                    CreateUpdateUserAccountParams createParams = new CreateUpdateUserAccountParams();
                    createParams.Name           = request.Name;
                    createParams.Email          = request.Email;
                    createParams.AccountKey     = EncodeUtils.CreateAccountKey();
                    createParams.PwdHash        = EncodeUtils.GetPasswordHash(request.Pwd);
                    createParams.ActivationCode = EncodeUtils.CreateActivationCode();
                    createParams.State          = "Pending"; // TODO; change to consts

                    _dal.CreateUserAccount(createParams);

                    SendMailResponse mailerResponse = SendAccountConfirmEmail(createParams.Email, createParams.AccountKey, createParams.Name);

                    response.Payload.AccountKey = createParams.AccountKey;
                    response.Success            = true;
                }
                else
                {
                    response.Success = false;
                    response.Errors.Add(new Error()
                    {
                        Code = EErrorCodes.UserAccountExists, Type = EErrorType.Error, Message = "User with specified data already exists"
                    });
                }
            }
            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: CreateAccount");

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

            try
            {
                SessionInfo sessionParams = new SessionInfo();
                sessionParams.SessionId = request.SessionToken;

                SessionInfo sessionInfo = _dal.GetSessionInfo(sessionParams, true);
                if (sessionInfo != null)
                {
                    CreateUpdateUserAccountParams updateParams = new CreateUpdateUserAccountParams();
                    updateParams.AccountKey = sessionInfo.AccountKey;
                    updateParams.Email      = request.Email ?? null;
                    updateParams.Name       = request.Name ?? null;
                    updateParams.PwdHash    = !string.IsNullOrEmpty(request.Pwd) ? EncodeUtils.GetPasswordHash(request.Pwd) : null;
                    updateParams.State      = request.State ?? null;

                    _dal.UpdateUserAccount(updateParams);

                    response.Success = true;
                }
                else
                {
                    response.Success = false;
                    response.Errors.Add(new Error()
                    {
                        Code = EErrorCodes.InvalidSession, Type = EErrorType.Error, Message = "Invalid session"
                    });
                }
            }
            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: UpdateAccount");

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

            try
            {
                // getting account details
                GetUserAccountInfoParams accInfoParams = new GetUserAccountInfoParams();
                accInfoParams.Email = request.Email;

                GetUserAccountInfoResult accResult = _dal.GetUserAccountInfo(accInfoParams);
                if (accResult != null && accResult.Success)
                {
                    string newPassword = EncodeUtils.GenerateRandomPassword();
                    // getting account details
                    CreateUpdateUserAccountParams updateParams = new CreateUpdateUserAccountParams();
                    updateParams.AccountKey = accResult.AccountKey;
                    updateParams.Email      = request.Email;
                    updateParams.PwdHash    = EncodeUtils.GetPasswordHash(newPassword);

                    _dal.UpdateUserAccount(updateParams);

                    SendMailResponse mailerResponse = SendPasswordResetNotificationEmail(updateParams.Email, accResult.Name, newPassword);
                    if (!mailerResponse.Success)
                    {
                        response.Errors.Add(new Error()
                        {
                            Code    = EErrorCodes.MailSendFailed,
                            Message = "Mail services returned errors. Check other errors",
                            Type    = EErrorType.Warning
                        });
                        response.Errors.AddRange(mailerResponse.Errors);
                    }

                    response.Success = true;
                }
                else
                {
                    response.Success = false;
                    response.Errors.Add(new Error()
                    {
                        Code = EErrorCodes.UserAccountNotFound, Type = EErrorType.Error, Message = "No account found for the given email"
                    });
                }
            }
            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: ChangePassword");

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

            try
            {
                SessionInfo sessionParams = new SessionInfo();
                sessionParams.SessionId = request.SessionToken;

                SessionInfo sessionInfo = _dal.GetSessionInfo(sessionParams, true);
                if (sessionInfo != null)
                {
                    // updating account details
                    CreateUpdateUserAccountParams updateParams = new CreateUpdateUserAccountParams();
                    updateParams.AccountKey = sessionInfo.AccountKey;
                    updateParams.Email      = request.Email;
                    updateParams.PwdHash    = EncodeUtils.GetPasswordHash(request.Pwd);

                    _dal.UpdateUserAccount(updateParams);

                    // getting account details
                    GetUserAccountInfoParams accInfoParams = new GetUserAccountInfoParams();
                    accInfoParams.AccountKey = sessionInfo.AccountKey;

                    GetUserAccountInfoResult accResult = _dal.GetUserAccountInfo(accInfoParams);
                    if (accResult != null)
                    {
                        SendMailResponse mailerResponse = SendPasswordChangedNotificationEmail(updateParams.Email, accResult.Name);
                        if (!mailerResponse.Success)
                        {
                            response.Errors.Add(new Error()
                            {
                                Code    = EErrorCodes.MailSendFailed,
                                Message = "Mail services returned errors. Check other errors",
                                Type    = EErrorType.Warning
                            });
                            response.Errors.AddRange(mailerResponse.Errors);
                        }
                    }

                    response.Success = true;
                }
                else
                {
                    response.Success = false;
                    response.Errors.Add(new Error()
                    {
                        Code = EErrorCodes.InvalidSession, Type = EErrorType.Error, Message = "Invalid session"
                    });
                }
            }
            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: ChangePassword");

            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);
        }