public IHttpActionResult CreateNewMessage(UserCreateMessageBindingModel model)
        {
            // Validate the input parameters
            if (!ModelState.IsValid)
            {
                return(this.BadRequest(this.ModelState));
            }

            // Validate that the current user exists in the database
            var currentUserId = this.idProvider.GetId();
            var currentUser   = this.Data.Users.GetAll().FirstOrDefault(x => x.Id == currentUserId);

            if (currentUser == null)
            {
                return(this.BadRequest("Invalid user token! Please login again!"));
            }

            var currentRoom = currentUser.Room;

            if (currentRoom == null)
            {
                return(this.BadRequest("User currently isn't in any room!"));
            }


            var message = new Message()
            {
                Text     = model.Text,
                PosterId = currentUserId,
                SentDate = DateTime.Now,
                Room     = currentRoom
            };

            this.Data.Messages.Add(message);

            this.Data.SaveChanges();

            return(this.Ok(
                       new
            {
                message = string.Format("Message from user with id {0} created successfully.", currentUserId),
                messageId = message.Id
            }
                       ));
        }
        public IHttpActionResult CreateNewMessage(UserCreateMessageBindingModel model)
        {
            // Validate the input parameters
            if (!ModelState.IsValid)
            {
                return this.BadRequest(this.ModelState);
            }

            // Validate that the current user exists in the database
            var currentUserId = this.idProvider.GetId();
            var currentUser = this.Data.Users.GetAll().FirstOrDefault(x => x.Id == currentUserId);

            if (currentUser == null)
            {
                return this.BadRequest("Invalid user token! Please login again!");
            }

            var currentRoom = currentUser.Room;

            if (currentRoom == null)
            {
                return this.BadRequest("User currently isn't in any room!");
            }


            var message = new Message()
            {
                Text = model.Text,
                PosterId = currentUserId,
                SentDate = DateTime.Now,
                Room = currentRoom
            };

            this.Data.Messages.Add(message);

            this.Data.SaveChanges();

            return this.Ok(
                new
                {
                    message = string.Format("Message from user with id {0} created successfully.", currentUserId),
                    messageId = message.Id
                }
            );
        }