public TranslatedPost Patch(string id, Post patch) { var post = _db.Posts.Include(c => c.Translations).SingleOrDefault(c => c.Id == id); post.Patch(patch); return new TranslatedPost(post); }
public void Patch(Post patch) { if (patch.Author?.Name != null) Author.Name = patch.Author.Name; if (patch.Author?.Url != null) Author.Name = patch.Author.Url; if (patch.Author?.Photo != null) Author.Name = patch.Author.Photo; 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.Summary != null) translation.Summary = translationPatch.Summary; if (translationPatch.Content != null) translation.Content = translationPatch.Content; if (translationPatch.Tags != null) translation.Tags = translationPatch.Tags; // ??? } }
public TranslatedPost(Post post) { Id = post.Id; if (post.Translations != null && post.Translations.Any()) { var translation = post.Translations.First(); Culture = translation.Culture; Title = translation.Title; Summary = translation.Summary; SummaryImage = translation.SummaryImage; Content = translation.Content; ContentImage = translation.ContentImage; Tags = translation.Tags; } }
// POST http://localhost:51102/odata/Posts // User-Agent: Fiddler // Host: localhost:14270 // Content-type: application/json // Accept: application/json // Content-Length: 26 // { id:"workmarketinnet-launched", title:"WorkMarketinNet launched", description:"Finally. After months of development WorkMarketingNet is alive." } //[Authorize(Roles = "Admin")] public async Task<IHttpActionResult> Post(TranslatedPost translatedPost, [ValueProvider(typeof(CultureValueProviderFactory))] string culture = "en-US") { translatedPost.Culture = culture; if (!ModelState.IsValid) { return BadRequest(ModelState); } try { var post = new Post(translatedPost, _cultureManager.SupportedCultures); var newPost = _postsManager.Post(post); await _postsManager.SaveChanges(); translatedPost.Id = newPost.Id; return Created(translatedPost); } catch (Exception ex) { throw; } }
// PUT http://localhost:51102/odata/Posts('workmarketinnet-launched') // User-Agent: Fiddler // Host: localhost:14270 // Content-type: application/json // Accept: application/json // Content-Length: 34 // { id:"workmarketinnet-launched", title:"WorkMarketinNet launched [PUT]", description:"Finally. After months of development WorkMarketingNet is alive." } //[Authorize(Roles = "Admin")] public async Task<IHttpActionResult> Put([FromODataUri] string key, TranslatedPost updatePost, [ValueProvider(typeof(CultureValueProviderFactory))] string culture = "en-US") { updatePost.Culture = culture; if (!ModelState.IsValid) { return BadRequest(ModelState); } if (key != updatePost.Id) { return BadRequest(); } var post = new Post(updatePost, new[] { culture }); var modelPost = _postsManager.Put(key, post); try { await _postsManager.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!_postsManager.Exists(modelPost.Id)) { return NotFound(); } else { throw; } } return Updated(modelPost); }
public async Task<IHttpActionResult> Patch([FromODataUri] string key, Delta<TranslatedPost> delta, [ValueProvider(typeof(CultureValueProviderFactory))] string culture = "en-US") { var post = new Post(delta.GetEntity(), culture); var tochange = _postsManager.Patch(key, post); try { await _postsManager.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!_postsManager.Exists(tochange.Id)) { return NotFound(); } else { throw; } } return Updated(tochange); }
public Post Post(Post post) { return _repository.Post(post); }
public TranslatedPost Put(string id, Post updatePost) { return _repository.Put(id, updatePost); }
public TranslatedPost Patch(string id, Post patch) { return _repository.Patch(id, patch); }
public Post Post(Post post) { _db.Posts.Add(post); return post; }
public TranslatedPost Put(string id, Post updatePost) { _db.Entry(updatePost).State = EntityState.Modified; _db.Entry(updatePost.Translations.First()).State = EntityState.Modified; return new TranslatedPost(updatePost); }