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