public HttpResponseMessage RegisterUser(UserRegisterModel userToRegister)
        {
            UserValidator.ValidateAuthCode(userToRegister.AuthCode);
            UserValidator.ValidateNickname(userToRegister.Nickname);
            UserValidator.ValidateUsername(userToRegister.Username);

            User newUser = null;
            try
            {
                newUser = UsersMapper.ToUserEntity(userToRegister);
            }
            catch (Exception)
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Invalid user register model provided!");
            }

            usersRepository.Add(newUser);

            User inDbUser = this.usersRepository.GetByUsernameAndAuthCode(newUser.Username, newUser.AuthCode);
            inDbUser.SessionKey = UserValidator.GenerateSessionKey(inDbUser.ID);
            this.usersRepository.Update(inDbUser.ID, inDbUser);
            UserLoggedModel loggedUser = new UserLoggedModel()
                {
                    Nickname = inDbUser.Nickname,
                    SessionKey = inDbUser.SessionKey
                };

            HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, loggedUser);
            response.Headers.Location = new Uri(Url.Link("NewsApi", new { sessionKey = loggedUser.SessionKey }));
            return response;
        }
        public HttpResponseMessage LoginUser(UserLoginModel userToLogin)
        {
            UserValidator.ValidateAuthCode(userToLogin.AuthCode);
            UserValidator.ValidateUsername(userToLogin.Username);

            User user = null;
            try
            {
                user = this.usersRepository.GetByUsernameAndAuthCode(userToLogin.Username, userToLogin.AuthCode);
            }
            catch (Exception)
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Invalid username or password!");
            }

            user.SessionKey = UserValidator.GenerateSessionKey(user.ID);
            this.usersRepository.Update(user.ID, user);

            UserLoggedModel loggedUser = new UserLoggedModel()
                {
                    Nickname = user.Nickname,
                    SessionKey = user.SessionKey
                };

            HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK, loggedUser);
            return response;
        }