// POST http://localhost:50481/odata/Quotes // User-Agent: Fiddler // Host: localhost:14270 // Content-type: application/json // Accept: application/json // Content-Length: 26 // { id:"go-pro-7-steps", title:"Go Pro: 7 Steps to Becoming a Network Marketing Professional", description:"Over twenty years ago at a company convention, Eric Worre had an aha moment that changed his life forever. At that event he made the decision to Go Pro and become a Network Marketing expert." } //[Authorize(Roles = "Admin")] public async Task<IHttpActionResult> Post(TranslatedQuote translatedQuote, [ValueProvider(typeof(CultureValueProviderFactory))] string culture = "en-US") { if (translatedQuote == null) return BadRequest(); translatedQuote.Culture = culture; if (!ModelState.IsValid) { return BadRequest(ModelState); } try { var quote = new Quote(translatedQuote, _cultureManager.SupportedCultures); var newQuote = _quotesManager.Post(quote); await _quotesManager.SaveChanges(); translatedQuote.Id = newQuote.Id; return Created(translatedQuote); } catch (Exception ex) { return InternalServerError(ex); } }
// PUT http://localhost:50481/odata/Quotes('go-pro-7-steps') // User-Agent: Fiddler // Host: localhost:14270 // Content-type: application/json // Accept: application/json // Content-Length: 34 // { id:"go-pro-7-steps", title:"Go Pro: 7 Steps to Becoming a Network Marketing Professional [PUT]", description:"Over twenty years ago at a company convention, Eric Worre had an aha moment that changed his life forever. At that event he made the decision to Go Pro and become a Network Marketing expert." } //[Authorize(Roles = "Admin")] public async Task<IHttpActionResult> Put([FromODataUri] string key, TranslatedQuote updateQuote, [ValueProvider(typeof(CultureValueProviderFactory))] string culture = "en-US") { updateQuote.Culture = culture; if (!ModelState.IsValid) { return BadRequest(ModelState); } if (key != updateQuote.Id) { return BadRequest(); } var quote = new Quote(updateQuote, new[] { culture }); var modelQuote = _quotesManager.Put(key, quote); try { await _quotesManager.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!_quotesManager.Exists(modelQuote.Id)) { return NotFound(); } else { throw; } } return Updated(modelQuote); }