diff --git a/samples/MicroserviceDemo/modules/product/src/ProductManagement.Application.Contracts/MyCompanyName/ProductManagement/CreateProductDto.cs b/samples/MicroserviceDemo/modules/product/src/ProductManagement.Application.Contracts/MyCompanyName/ProductManagement/CreateProductDto.cs new file mode 100644 index 0000000000..693dd0d501 --- /dev/null +++ b/samples/MicroserviceDemo/modules/product/src/ProductManagement.Application.Contracts/MyCompanyName/ProductManagement/CreateProductDto.cs @@ -0,0 +1,13 @@ +namespace ProductManagement +{ + public class CreateProductDto + { + public string Code { get; set; } + + public string Name { get; set; } + + public float Price { get; set; } + + public int StockCount { get; set; } + } +} \ No newline at end of file diff --git a/samples/MicroserviceDemo/modules/product/src/ProductManagement.Application.Contracts/MyCompanyName/ProductManagement/IProductAppService.cs b/samples/MicroserviceDemo/modules/product/src/ProductManagement.Application.Contracts/MyCompanyName/ProductManagement/IProductAppService.cs new file mode 100644 index 0000000000..cfb3aa2c56 --- /dev/null +++ b/samples/MicroserviceDemo/modules/product/src/ProductManagement.Application.Contracts/MyCompanyName/ProductManagement/IProductAppService.cs @@ -0,0 +1,22 @@ +using System; +using System.Threading.Tasks; +using Volo.Abp.Application.Dtos; +using Volo.Abp.Application.Services; + +namespace MyCompanyName.ProductManagement +{ + public interface IProductAppService : IApplicationService + { + Task> GetListPagedAsync(PagedAndSortedResultRequestDto input); + + Task> GetListAsync(); + + Task GetAsync(Guid id); + + Task CreateAsync(CreateProductDto input); + + Task UpdateAsync(Guid id, UpdateProductDto input); + + Task DeleteAsync(Guid id); + } +} \ No newline at end of file diff --git a/samples/MicroserviceDemo/modules/product/src/ProductManagement.Application.Contracts/MyCompanyName/ProductManagement/ProductDto.cs b/samples/MicroserviceDemo/modules/product/src/ProductManagement.Application.Contracts/MyCompanyName/ProductManagement/ProductDto.cs new file mode 100644 index 0000000000..86a4536785 --- /dev/null +++ b/samples/MicroserviceDemo/modules/product/src/ProductManagement.Application.Contracts/MyCompanyName/ProductManagement/ProductDto.cs @@ -0,0 +1,16 @@ +using System; +using Volo.Abp.Application.Dtos; + +namespace ProductManagement +{ + public class ProductDto : AuditedEntityDto + { + public string Code { get; set; } + + public string Name { get; set; } + + public float Price { get; set; } + + public int StockCount { get; set; } + } +} \ No newline at end of file diff --git a/samples/MicroserviceDemo/modules/product/src/ProductManagement.Application.Contracts/MyCompanyName/ProductManagement/UpdateProductDto.cs b/samples/MicroserviceDemo/modules/product/src/ProductManagement.Application.Contracts/MyCompanyName/ProductManagement/UpdateProductDto.cs new file mode 100644 index 0000000000..38b58f8052 --- /dev/null +++ b/samples/MicroserviceDemo/modules/product/src/ProductManagement.Application.Contracts/MyCompanyName/ProductManagement/UpdateProductDto.cs @@ -0,0 +1,13 @@ +namespace ProductManagement +{ + public class UpdateProductDto + { + public string Code { get; set; } + + public string Name { get; set; } + + public float Price { get; set; } + + public int StockCount { get; set; } + } +} \ No newline at end of file diff --git a/samples/MicroserviceDemo/modules/product/src/ProductManagement.Application/MyCompanyName/ProductManagement/ProductAppService.cs b/samples/MicroserviceDemo/modules/product/src/ProductManagement.Application/MyCompanyName/ProductManagement/ProductAppService.cs new file mode 100644 index 0000000000..b2d261898e --- /dev/null +++ b/samples/MicroserviceDemo/modules/product/src/ProductManagement.Application/MyCompanyName/ProductManagement/ProductAppService.cs @@ -0,0 +1,72 @@ +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using ProductManagement; +using Volo.Abp.Application.Dtos; +using Volo.Abp.Application.Services; +using Volo.Abp.Domain.Repositories; + +namespace MyCompanyName.ProductManagement +{ + public class ProductAppService : ApplicationService, IProductAppService + { + private readonly ProductManager _productManager; + private readonly IProductRepository _productRepository; + + public ProductAppService(ProductManager productManager, IProductRepository productRepository) + { + _productManager = productManager; + _productRepository = productRepository; + } + + public async Task> GetListPagedAsync(PagedAndSortedResultRequestDto input) + { + var products = await _productRepository.GetListAsync(input.Sorting, input.MaxResultCount, input.SkipCount); + + var totalCount = await _productRepository.GetCountAsync(); + + var dtos = ObjectMapper.Map, List>(products); + + return new PagedResultDto(totalCount, dtos); + } + + public async Task> GetListAsync() + { + var products = await _productRepository.GetListAsync(); + + var productList = ObjectMapper.Map, List>(products); + + return new ListResultDto(productList); + } + + public async Task GetAsync(Guid id) + { + var product = await _productRepository.GetAsync(id); + + return ObjectMapper.Map(product); + } + + public async Task CreateAsync(CreateProductDto input) + { + var product = await _productManager.CreateAsync(input.Code, input.Name, input.Price, input.StockCount); + + return ObjectMapper.Map(product); + } + + public async Task UpdateAsync(Guid id, UpdateProductDto input) + { + var product = await _productRepository.GetAsync(id); + + product.SetName(input.Name); + product.SetPrice(input.Price); + product.SetStockCount(input.StockCount); + + return ObjectMapper.Map(product); + } + + public async Task DeleteAsync(Guid id) + { + await _productRepository.DeleteAsync(id); + } + } +} \ No newline at end of file