Пример #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);
        }