public async Task<Post> UpdateAsync(Post post) { using (var uow = _uowFac.Create()) { uow.PostRepository.Update(post); await uow.SaveChangesAsync(); return post; } }
public async Task DeleteAsync(Post post) { using (var uow = _uowFac.Create()) { post.Deleted = true; uow.PostRepository.Update(post); await uow.SaveChangesAsync(); } }
public async Task<Post> InsertAsync(Post post) { using (var uow = _uowFac.Create()) { post.Id = new Guid(); uow.PostRepository.Insert(post); await uow.SaveChangesAsync(); return post; } }
public async Task<IHttpActionResult> PostPost(Post post) { try { if (!ModelState.IsValid) return BadRequest(ModelState); var result = await _postService.InsertAsync(post); return Ok(result); } catch (Exception) { throw; } }
public async Task<IHttpActionResult> PutPost(Post post) { try { if (!ModelState.IsValid) return BadRequest(ModelState); if (post.Id == Guid.Empty) return BadRequest(); var result = await _postService.UpdateAsync(post); return Ok(result); } catch (Exception) { throw; } }