public IHttpActionResult PostChannelMessages(string channel, ChannelMessageBindingModel model)
        {
            if (model == null)
            {
                return BadRequest("Missing message data.");
            }

            if (!ModelState.IsValid)
            {
                return this.BadRequest(this.ModelState);
            }

            Channel channelDB = db.Channels.FirstOrDefault(c => c.Name == channel);

            if (channelDB == null)
            {
                return NotFound();
            }


            var currentUserId = User.Identity.GetUserId();
            var currentUser = this.db.Users.Find(currentUserId);

            var message = new ChannelMessage()
            {
                Text = model.Text,
                Channel = channelDB,
                DateSent = DateTime.Now,
                Sender = currentUser
            };

            db.ChannelMessages.Add(message);
            db.SaveChanges();


            if (message.Sender == null)
            {
                return this.Ok(new
                {
                    Id = message.Id,
                    Message = "Anonymous message sent to channel " + channel
                }
            );
            }

            return this.Ok(new
                {
                    Id = message.Id,
                    Sender = message.Sender.UserName,
                    Message = "Message sent to channel " + channel
                }
            );
        }
        public IHttpActionResult SendChannelMessage(
            string channelName, ChannelMessageBindingModel channelMessageData)
        {
            if (channelMessageData == null)
            {
                return BadRequest("Missing message data.");
            }

            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            var channel = db.Channels.All().FirstOrDefault(c => c.Name == channelName);
            if (channel == null)
            {
                return this.NotFound();
            }

            var currentUserId = User.Identity.GetUserId();
            var currentUser = this.db.Users.Find(currentUserId);

            var message = new ChannelMessage()
            {
                Text = channelMessageData.Text,
                Channel = channel,
                DateSent = DateTime.Now,
                SenderUser = currentUser
            };
            db.ChannelMessages.Add(message);
            db.SaveChanges();

            if (message.SenderUser == null)
            {
                return this.Ok(
                    new
                    {
                        message.Id,
                        Message = "Anonymous message sent successfully to channel " + channelName + "."
                    }
                );
            }

            return this.Ok(
                new
                {
                    message.Id,
                    Sender = message.SenderUser.UserName,
                    Message = "Message sent successfully to channel " + channelName + "."
                }
            );
        }