public HttpResponseMessage RegisterUser([FromBody]UserRegisterDTO user)
        {
            HttpResponseMessage responseMessage = this.PerformOperation(() =>
            {
                UserValidator.ValidateAuthenticationCode(user.AuthCode);
                UserValidator.ValidateNickname(user.Nickname);
                UserValidator.ValidateUsername(user.Username);

                var exstingUserEntity = this.data.Users.All().FirstOrDefault(
                    u => u.Username == user.Username.ToLower() || u.Nickname.ToLower() == user.Nickname.ToLower());
                if (exstingUserEntity != null)
                {
                    throw new InvalidOperationException("User already exists!");
                }

                var newUserEntity = new User()
                {
                    AuthCode = user.AuthCode,
                    Nickname = user.Nickname,
                    Username = user.Username
                };

                this.data.Users.Add(newUserEntity);
                this.data.SaveChanges();

                newUserEntity.SessionKey = UserValidator.GenerateSessionKey(newUserEntity.ID);
                this.data.SaveChanges();

                var loggedUser = new LoggedUserDTO()
                {
                    Nickname = newUserEntity.Nickname,
                    SessionKey = newUserEntity.SessionKey
                };

                return this.Request.CreateResponse(HttpStatusCode.Created, loggedUser);
            });

            return responseMessage;
        }
        public HttpResponseMessage LoginUser([FromBody]UserLoginDTO user)
        {
            HttpResponseMessage responseMessage = this.PerformOperation(() =>
            {
                UserValidator.ValidateAuthenticationCode(user.AuthCode);
                UserValidator.ValidateUsername(user.Username);

                var userEntity = this.data.Users.All().FirstOrDefault(
                    u => u.AuthCode == user.AuthCode && u.Username == user.Username.ToLower());
                if (userEntity == null)
                {
                    throw new InvalidOperationException("User not registered!");
                }

                userEntity.SessionKey = UserValidator.GenerateSessionKey(userEntity.ID);
                this.data.SaveChanges();

                var loggedUser = new LoggedUserDTO()
                {
                    Nickname = userEntity.Nickname,
                    SessionKey = userEntity.SessionKey
                };

                return this.Request.CreateResponse(HttpStatusCode.Created, loggedUser);
            });

            return responseMessage;
        }