示例#1
0
            public async Task <AddPostResponse> Handle(AddPostRequest request, CancellationToken cancellationToken)
            {
                var posts = await _blogContext.Post.AddAsync(request.PostToAdd, cancellationToken);

                await _blogContext.SaveChangesAsync(cancellationToken);

                return(new AddPostResponse());
            }
示例#2
0
            public async Task <UpdatePostResponse> Handle(UpdatePostRequest request, CancellationToken cancellationToken)
            {
                var post = await _blogContext.Post.SingleOrDefaultAsync(p => p.Id == request.PostToUpdate.Id, cancellationToken);

                post.Title       = request.PostToUpdate.Title;
                post.Description = request.PostToUpdate.Title;
                post.CategoryId  = request.PostToUpdate.CategoryId;

                await _blogContext.SaveChangesAsync(cancellationToken);

                return(new UpdatePostResponse());
            }
示例#3
0
        public async Task <DeleteCustomerCardCommandDto> Handle(DeleteCustomerCardCommand request, CancellationToken cancellationToken)
        {
            var result = await _context.customerCards.FirstOrDefaultAsync(x => x.id == request.id);

            _context.customerCards.Remove(result);
            await _context.SaveChangesAsync(cancellationToken);

            return(new DeleteCustomerCardCommandDto
            {
                Message = "Success delete customer card data",
                Success = true,
                Data = result
            });
        }
示例#4
0
        public async Task <CreateCreatorCommandDto> Handle(CreateCreatorCommand request, CancellationToken cancellationToken)
        {
            var creator = new Domain.Entities.Creator
            {
                name = request.Data.Name,
                age  = request.Data.Age
            };

            _context.Creators.Add(creator);
            await _context.SaveChangesAsync(cancellationToken);

            return(new CreateCreatorCommandDto
            {
                Success = true,
                Message = "Creator successfully created",
            });
        }
示例#5
0
 public async Task <int> ExecuteAsync(Post post)
 {
     this.context.Posts.Add(post);
     return(await context.SaveChangesAsync());
 }