Exemplo n.º 1
0
        private IHttpActionResult TryCreateJoke(JokeCreateModel model)
        {
            model.CreatedById = this.UserId;
            var category       = this.categories.Find(model.Category);
            var joke           = this.jokes.Create(model, category);
            var locationHeader = new Uri(this.Url.Link("JokesApi", new { id = joke.Id, controller = "Jokes" }));

            return(this.Created(locationHeader, this.Mapper.Map <JokeViewModel>(joke)));
        }
Exemplo n.º 2
0
        public IHttpActionResult Create(JokeCreateModel model)
        {
            if (this.ModelState.IsValid == false)
            {
                return(this.BadRequest(this.ModelState));
            }

            return(this.TryCreateJoke(model));
        }
Exemplo n.º 3
0
        public Joke Create(JokeCreateModel model, JokeCategory category)
        {
            var joke = new Joke
            {
                Category    = category,
                CreatedById = model.CreatedById,
                Content     = model.Content,
            };

            this.jokes.Add(joke);
            this.jokes.Save();

            return(joke);
        }