Browse Source

Microservicedemo: added product application layer

pull/746/head
Yunus Emre Kalkan 7 years ago
parent
commit
9e2e8a2936
  1. 13
      samples/MicroserviceDemo/modules/product/src/ProductManagement.Application.Contracts/MyCompanyName/ProductManagement/CreateProductDto.cs
  2. 22
      samples/MicroserviceDemo/modules/product/src/ProductManagement.Application.Contracts/MyCompanyName/ProductManagement/IProductAppService.cs
  3. 16
      samples/MicroserviceDemo/modules/product/src/ProductManagement.Application.Contracts/MyCompanyName/ProductManagement/ProductDto.cs
  4. 13
      samples/MicroserviceDemo/modules/product/src/ProductManagement.Application.Contracts/MyCompanyName/ProductManagement/UpdateProductDto.cs
  5. 72
      samples/MicroserviceDemo/modules/product/src/ProductManagement.Application/MyCompanyName/ProductManagement/ProductAppService.cs

13
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; }
}
}

22
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<PagedResultDto<ProductDto>> GetListPagedAsync(PagedAndSortedResultRequestDto input);
Task<ListResultDto<ProductDto>> GetListAsync();
Task<ProductDto> GetAsync(Guid id);
Task<ProductDto> CreateAsync(CreateProductDto input);
Task<ProductDto> UpdateAsync(Guid id, UpdateProductDto input);
Task DeleteAsync(Guid id);
}
}

16
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<Guid>
{
public string Code { get; set; }
public string Name { get; set; }
public float Price { get; set; }
public int StockCount { get; set; }
}
}

13
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; }
}
}

72
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<PagedResultDto<ProductDto>> GetListPagedAsync(PagedAndSortedResultRequestDto input)
{
var products = await _productRepository.GetListAsync(input.Sorting, input.MaxResultCount, input.SkipCount);
var totalCount = await _productRepository.GetCountAsync();
var dtos = ObjectMapper.Map<List<Product>, List<ProductDto>>(products);
return new PagedResultDto<ProductDto>(totalCount, dtos);
}
public async Task<ListResultDto<ProductDto>> GetListAsync()
{
var products = await _productRepository.GetListAsync();
var productList = ObjectMapper.Map<List<Product>, List<ProductDto>>(products);
return new ListResultDto<ProductDto>(productList);
}
public async Task<ProductDto> GetAsync(Guid id)
{
var product = await _productRepository.GetAsync(id);
return ObjectMapper.Map<Product, ProductDto>(product);
}
public async Task<ProductDto> CreateAsync(CreateProductDto input)
{
var product = await _productManager.CreateAsync(input.Code, input.Name, input.Price, input.StockCount);
return ObjectMapper.Map<Product, ProductDto>(product);
}
public async Task<ProductDto> 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, ProductDto>(product);
}
public async Task DeleteAsync(Guid id)
{
await _productRepository.DeleteAsync(id);
}
}
}
Loading…
Cancel
Save