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); }
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); }
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); }
public override IPost GetById(int id) { try { return(_postsFactory.CopyFrom(_postsRepository.Get(id))); } catch (Exception ex) { //LogService.Log.Error(ex); } return(null); }
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); }
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)); }
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)); }
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); }
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))); }
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)); }
public IEnumerable <PostDTO> GetPosts() { var result = _postsRepository.Get(); return(Mapping.Mapper.Map <IEnumerable <PostDTO> >(result)); }
public async Task <IActionResult> Get() { var posts = await postsRepository.Get(); return(Ok(new { posts })); }
public async Task <IActionResult> Get([HttpTrigger(AuthorizationLevel.Function, "get", Route = "posts")] HttpRequest req, ILogger log) { var posts = await _repository.Get(); return(new OkObjectResult(posts)); }
[HttpGet("{id}")] // Read action public Post Get(int id) { return(_repository.Get(id)); }
public async Task <ActionResult <string> > Get(string title) { return(JsonConvert.SerializeObject(await _postsRepo.Get <Post>(title))); }