public IHttpActionResult PostMessagesToChannel(string channelName, ChannelMessagesBindingModel m)
        {
            if (!ModelState.IsValid)
                return BadRequest(ModelState);

            if (string.IsNullOrEmpty(channelName))
                return BadRequest();

            if (!Data.Channels.Any(c => c.Name == channelName))
                return NotFound();

            var channelId = Data.Channels.First(c => c.Name == channelName).Id;

            var message = new ChannelMessage
            {
                Text = m.Text,
                DateSent = DateTime.Now,
                ChannelId = channelId
            };

            Data.ChannelMessages.Add(message);

            Data.SaveChanges();

            return Ok(new
            {
                message.Id,
                Message = "Anonymous message sent to channel " + channelName + "."
            });
        }
        public IHttpActionResult PostChannelMessages(string channelName, ChannelMessagesBindingModel model)
        {
            if (model == null)
            {
                return this.BadRequest("Name is required!Cannot be empty.");
            }

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

            var channel = this.Data.Channels
                .FirstOrDefault(ch => ch.Name == channelName);

            if (channel == null)
            {
                return this.NotFound();
            }

            var message = new ChannelMessage
            {
                Text = model.Text,
                DateSent = DateTime.Now,
                ChannelId = channel.Id
            };

            if (this.User.Identity.IsAuthenticated)
            {
                message.SenderId = this.User.Identity.GetUserId();

            }

            this.Data.ChannelMessages.Add(message);
            this.Data.SaveChanges();
            
            if (this.User.Identity.IsAuthenticated)
            {
                return this.Ok(new
                {
                    Id = message.Id,
                    Sender = this.User.Identity.GetUserName(),
                    Message = "Message sent to channel " + channel.Name
                });

            }

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