public UserSession Login(User user) { if (user == null) { throw new BusinessException("User cannot be null."); } if (string.IsNullOrEmpty(user.Email)) { throw new BusinessException("User Email cannot be null."); } _UserService.Filter(entity => entity.Email == user.Email); User dbUser = this._UserService.Filter(dbUser => dbUser.Email.Trim().ToLower() == user.Email.Trim().ToLower()).SingleOrDefault(); if (dbUser == null) { throw new BusinessException("User with email " + user.Email + " does not exist."); } if (dbUser.Password != _EncryptionService.EncryptPassword(user.Password)) { throw new BusinessException("Email/Password don't match."); } return(new UserSession() { UserId = dbUser.Id, SessionKey = _JWTService.GenerateUserSession(user) }); }