예제 #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)));
        }
예제 #2
0
        public IHttpActionResult Create(JokeCreateModel model)
        {
            if (this.ModelState.IsValid == false)
            {
                return(this.BadRequest(this.ModelState));
            }

            return(this.TryCreateJoke(model));
        }
예제 #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);
        }