Пример #1
0
        public async Task<Post> UpdateAsync(Post post)
        {
            using (var uow = _uowFac.Create())
            {
                uow.PostRepository.Update(post);
                await uow.SaveChangesAsync();

                return post;
            }
        }
Пример #2
0
        public async Task DeleteAsync(Post post)
        {
            using (var uow = _uowFac.Create())
            {
                post.Deleted = true;

                uow.PostRepository.Update(post);
                await uow.SaveChangesAsync();
            }
        }
Пример #3
0
        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;
            }
        }
Пример #4
0
        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;
            }
        }
Пример #5
0
        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;
            }
        }