public SessionDTO Map(Session session)
 {
     return new SessionDTO
         {
             SessionToken = session.SessionToken,
             User = _userToUserDtoMapper.Map(session.User)
         };
 }
        public SessionDTO Authenticate(BlogContext context, string userName, string password)
        {
            var user = context.Users.SingleOrDefault(u => u.UserName == userName);
            if (user == null)
            {
                throw new NoSuchUserException();
            }

            if (user.Password != password)
            {
                throw new InvalidPasswordException();
            }

            var session = new Session
                {
                    SessionToken = Guid.NewGuid().ToString(),
                    User = user
                };

            session = context.Sessions.Add(session);
            context.SaveChanges();

            return _sessionToSessionDtoMapper.Map(session);
        }