public async Task <IActionResult> Post([FromBody] QuoteCreate quote) { try { var id = Guid.NewGuid(); var viewModel = quote; return(CreatedAtAction("Get", new { id = id }, viewModel)); } catch (Exception) { return(StatusCode(StatusCodes.Status500InternalServerError)); } }
public bool CreateQuote(QuoteCreate model) { var entity = new Quote { Content = model.Content, AuthorId = model.AuthorId, CategoryId = model.CategoryId, DateSpoken = model.DateSpoken }; using (var ctx = new ApplicationDbContext()) { ctx.Quotes.Add(entity); return(ctx.SaveChanges() == 1); } }
public IHttpActionResult Post(QuoteCreate quote) { if (quote == null) { return(BadRequest("Received model was null.")); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var service = CreateQuoteService(); if (!service.CreateQuote(quote)) { return(InternalServerError()); } return(Ok()); }