public IHttpActionResult Post(TopicRequestModel requestTopic)
        {
            if (this.sections.GetById(requestTopic.SectionId) == null)
            {
                return this.BadRequest("The section id doesn't exist");
            }

            var topic = Mapper.Map<TopicRequestModel, Topic>(requestTopic);

            var newContributor = this.users.GetUserById(this.User.Identity.GetUserId()).FirstOrDefault();

            this.topics.Add(topic, newContributor);

            return this.Ok(topic.Id);
        }
        public IHttpActionResult Put(int id, TopicRequestModel requestTopic)
        {
            if (!this.ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            var topic = this.topics.GetById(id).FirstOrDefault();

            if (topic == null)
            {
                return this.BadRequest();
            }

            Func<ExampleRequestModel, Example> mapToExample = c =>
            {
                var example = this.examples.GetById(c.Id).FirstOrDefault();

                if (example == null)
                {
                    example = new Example { Id = c.Id };
                }

                example.Description = c.Description;
                example.Content = c.Content;

                this.examples.Update(example);
                return example;
            };

            topic.Title = requestTopic.Title;
            topic.Content = requestTopic.Content;
            topic.VideoId = requestTopic.VideoId;
            topic.Examples = requestTopic.Examples.Select(mapToExample).ToList();

            if (!topic.Contributors.Any(c => c.Id == this.User.Identity.GetUserId()))
            {
                topic.Contributors.Add(this.users.GetUserById(this.User.Identity.GetUserId()).FirstOrDefault());
            }

            this.topics.Update(topic);

            return this.Ok();
        }