public TranslatedAd Patch(string id, Ad patch) { var ad = _db.Ads.Include(c => c.Translations).SingleOrDefault(c => c.Id == id); ad.Patch(patch); return new TranslatedAd(ad); }
public void Patch(Ad patch) { foreach (var translationPatch in patch.Translations) { var translation = Translations.FirstOrDefault(t => t.Culture == translationPatch.Culture); if (translation == null) { continue; } if (translationPatch.Title != null) translation.Title = translationPatch.Title; if (translationPatch.Description != null) translation.Description = translationPatch.Description; } }
public TranslatedAd(Ad ad) { Id = ad.Id; if (ad.Translations != null && ad.Translations.Any()) { var translation = ad.Translations.First(); Culture = translation.Culture; Title = translation.Title; Description = translation.Description; } }
// POST http://localhost:48946/odata/Ads // User-Agent: Fiddler // Host: localhost:14270 // Content-type: application/json // Accept: application/json // Content-Length: 26 // { id:"jeunesse-global-secret", title:"Jeunesse Global Secret", description:"Jeunesse Global Secret Are you looking to get involved in the Jeunesse Global home based business opportunity? Do you have an interest anti-aging? Would you like to make a 6 figure income helping others look and feel younger?", votesUp:666, votesDown:34 } //[Authorize(Roles = "Admin")] public async Task<IHttpActionResult> Post(TranslatedAd translatedAd, [ValueProvider(typeof(CultureValueProviderFactory))] string culture = "en-US") { translatedAd.Culture = culture; if (!ModelState.IsValid) { return BadRequest(ModelState); } try { var ad = new Ad(translatedAd, _cultureManager.SupportedCultures); var newAd = _adsManager.Post(ad); await _adsManager.SaveChanges(); translatedAd.Id = newAd.Id; return Created(translatedAd); } catch (Exception ex) { throw; } }
public Ad Post(Ad ad) { _db.Ads.Add(ad); return ad; }
public TranslatedAd Put(string id, Ad updateAd) { _db.Entry(updateAd).State = EntityState.Modified; _db.Entry(updateAd.Translations.First()).State = EntityState.Modified; return new TranslatedAd(updateAd); }
public Ad Post(Ad ad) { return _repository.Post(ad); }
public TranslatedAd Put(string id, Ad updateAd) { return _repository.Put(id, updateAd); }
public TranslatedAd Patch(string id, Ad patch) { return _repository.Patch(id, patch); }
// PUT http://localhost:48946/odata/Ads('jeunesse-global-secret') // User-Agent: Fiddler // Host: localhost:14270 // Content-type: application/json // Accept: application/json // Content-Length: 34 // { id:"jeunesse-global-secret", title:"Jeunesse Global Secret [PUT]", description:"Jeunesse Global Secret Are you looking to get involved in the Jeunesse Global home based business opportunity? Do you have an interest anti-aging? Would you like to make a 6 figure income helping others look and feel younger?" } //[Authorize(Roles = "Admin")] public async Task<IHttpActionResult> Put([FromODataUri] string key, TranslatedAd updateAd, [ValueProvider(typeof(CultureValueProviderFactory))] string culture = "en-US") { updateAd.Culture = culture; if (!ModelState.IsValid) { return BadRequest(ModelState); } if (key != updateAd.Id) { return BadRequest(); } var ad = new Ad(updateAd, new[] { culture }); var modelAd = _adsManager.Put(key, ad); try { await _adsManager.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!_adsManager.Exists(modelAd.Id)) { return NotFound(); } else { throw; } } return Updated(modelAd); }
public async Task<IHttpActionResult> Patch([FromODataUri] string key, Delta<TranslatedAd> delta, [ValueProvider(typeof(CultureValueProviderFactory))] string culture = "en-US") { var ad = new Ad(delta.GetEntity(), culture); var tochange = _adsManager.Patch(key, ad); try { await _adsManager.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!_adsManager.Exists(tochange.Id)) { return NotFound(); } else { throw; } } return Updated(tochange); }