public UserSession LogIn(string email, string password) { User user = null; try { user = userRepository.GetUserByEmailAndPassword(email, password); } catch (ClientException e) { throw new ClientBusinessLogicException(e.Message); } catch (ServerException e) { throw new ServerBusinessLogicException(e.Message); } UserSession userSession = sessionRepository.GetUserSessionByUserId(user.Id); if (userSession == null) { Guid token = Guid.NewGuid(); userSession = new UserSession() { User = user, Token = token.ToString() }; sessionRepository.Add(userSession); } return(userSession); }