public TranslatedMessage Patch(string id, Message patch) { var message = _db.Messages.Include(c => c.Translations).SingleOrDefault(c => c.Id == id); message.Patch(patch); return new TranslatedMessage(message); }
public void Patch(Message 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 TranslatedMessage(Message message) { Id = message.Id; if (message.Translations != null && message.Translations.Any()) { var translation = message.Translations.First(); Culture = translation.Culture; Title = translation.Title; Description = translation.Description; } }
// POST http://localhost:48946/odata/Messages // 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(TranslatedMessage translatedMessage, [ValueProvider(typeof(CultureValueProviderFactory))] string culture = "en-US") { translatedMessage.Culture = culture; if (!ModelState.IsValid) { return BadRequest(ModelState); } try { var message = new Message(translatedMessage, _cultureManager.SupportedCultures); var newMessage = _messagesManager.Post(message); await _messagesManager.SaveChanges(); translatedMessage.Id = newMessage.Id; return Created(translatedMessage); } catch (Exception ex) { throw; } }
public Message Post(Message message) { _db.Messages.Add(message); return message; }
public TranslatedMessage Put(string id, Message updateMessage) { _db.Entry(updateMessage).State = EntityState.Modified; _db.Entry(updateMessage.Translations.First()).State = EntityState.Modified; return new TranslatedMessage(updateMessage); }
// PUT http://localhost:48946/odata/Messages('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, TranslatedMessage updateMessage, [ValueProvider(typeof(CultureValueProviderFactory))] string culture = "en-US") { updateMessage.Culture = culture; if (!ModelState.IsValid) { return BadRequest(ModelState); } if (key != updateMessage.Id) { return BadRequest(); } var message = new Message(updateMessage, new[] { culture }); var modelAd = _messagesManager.Put(key, message); try { await _messagesManager.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!_messagesManager.Exists(modelAd.Id)) { return NotFound(); } else { throw; } } return Updated(modelAd); }
public async Task<IHttpActionResult> Patch([FromODataUri] string key, Delta<TranslatedMessage> delta, [ValueProvider(typeof(CultureValueProviderFactory))] string culture = "en-US") { var message = new Message(delta.GetEntity(), culture); var tochange = _messagesManager.Patch(key, message); try { await _messagesManager.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!_messagesManager.Exists(tochange.Id)) { return NotFound(); } else { throw; } } return Updated(tochange); }
public Message Post(Message message) { return _repository.Post(message); }
public TranslatedMessage Put(string id, Message updateMessage) { return _repository.Put(id, updateMessage); }
public TranslatedMessage Patch(string id, Message patch) { return _repository.Patch(id, patch); }