コード例 #1
0
        public void Get()
        {
            // Arrange
            var id = 3;

            _repository.Insert(new Post {
                Id = id, Text = id.ToString()
            });

            // Act
            var actual = _repository.Get(id);

            // Assert
            Assert.NotNull(actual);
            Assert.Equal(id, actual.Id);
        }
コード例 #2
0
        public async Task Run([TimerTrigger("0 */1 * * * *")] TimerInfo myTimer, ILogger log)
        {
            var posts = await _repository.Get();

            log.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}");
            log.LogInformation(posts[0].Body);
        }
コード例 #3
0
        public async Task <Post> GetPostWithComments(int id)
        {
            var post = await postsRepo.Get <Post>(id);

            var comments = await commentsRepo.GetAll <Comment>(post.Id);

            post.Comments = comments.ToList();

            return(post);
        }
コード例 #4
0
 public override IPost GetById(int id)
 {
     try
     {
         return(_postsFactory.CopyFrom(_postsRepository.Get(id)));
     }
     catch (Exception ex)
     {
         //LogService.Log.Error(ex);
     }
     return(null);
 }
コード例 #5
0
ファイル: PostsService.cs プロジェクト: ignacy130/audecyzje
        public async Task Edit(int id, int parentId, string title, string content, bool isPublished, string editorId)
        {
            var post = await _postsRepository.Get(id);

            post.ParentId   = parentId;
            post.Title      = title;
            post.Content    = content;
            post.ModifiedAt = DateTime.Now;

            if (!post.IsPublished && isPublished && post.PublishedAt == null)
            {
                post.IsPublished = isPublished;
                post.PublishedAt = DateTime.Now;
            }
            else
            {
                post.IsPublished = isPublished;
            }

            await _postsRepository.Update(post);
        }
コード例 #6
0
        public async Task <IActionResult> Details(int id)
        {
            var post = await postsRepo.Get <Post>(id);

            var comments = await commentsRepo.GetAll <Comment>(id);

            var vm = new PostDetailsViewModel
            {
                Post     = post,
                Comments = comments.ToList(),
            };

            return(View(vm));
        }
コード例 #7
0
        public async Task <IActionResult> Details(int id, string slug = null)
        {
            ViewData["RouteData"] = this.RouteData;

            var post = await postsRepo.Get <Post>(id);

            var comments = await commentsRepo.GetAll <Comment>(id);

            var vm = new PostDetailsViewModel
            {
                Post     = post,
                Comments = comments.ToList(),
            };

            return(View(vm));
        }
コード例 #8
0
        public async Task <Unit> Handle(UpdatePostCommand command, CancellationToken ct)
        {
            var post = await _postsRepository.Get(command.PostId, ct);

            if (post == null)
            {
                return(Unit.Value);
            }

            _mapper.Map(command, post);
            post.UpdatedAt = DateTimeOffset.Now;

            await _postsRepository.Update(post, ct);

            return(Unit.Value);
        }
コード例 #9
0
        public IActionResult dostuff()
        {
            using var transaction = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions()
            {
                IsolationLevel = IsolationLevel.RepeatableRead
            });

            var author = _authorRepository.Create(RandomString(10));
            var posts  = _postsRepository.Create(RandomString(10), RandomString(10), author);

            var post = _postsRepository.Get(posts);

            var authorAgain = post;

            return(Ok(JsonSerializer.Serialize(authorAgain)));
        }
コード例 #10
0
        public IActionResult dostuff()
        {
            using var transaction = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions()
            {
                IsolationLevel = IsolationLevel.RepeatableRead
            });

            var author = _authorRepository.Create(RandomString(10));
            var posts  = _postsRepository.Create(RandomString(10), RandomString(10), author);

            Thread.Sleep(3000);

            var post = _postsRepository.Get(posts);

            transaction.Complete();
            return(Ok(post));
        }
コード例 #11
0
        public IEnumerable <PostDTO> GetPosts()
        {
            var result = _postsRepository.Get();

            return(Mapping.Mapper.Map <IEnumerable <PostDTO> >(result));
        }
コード例 #12
0
        public async Task <IActionResult> Get()
        {
            var posts = await postsRepository.Get();

            return(Ok(new { posts }));
        }
コード例 #13
0
        public async Task <IActionResult> Get([HttpTrigger(AuthorizationLevel.Function, "get", Route = "posts")] HttpRequest req, ILogger log)
        {
            var posts = await _repository.Get();

            return(new OkObjectResult(posts));
        }
コード例 #14
0
 [HttpGet("{id}")] // Read action
 public Post Get(int id)
 {
     return(_repository.Get(id));
 }
コード例 #15
0
 public async Task <ActionResult <string> > Get(string title)
 {
     return(JsonConvert.SerializeObject(await _postsRepo.Get <Post>(title)));
 }