Browse Source

Implementing the `OrderReportingAppService` Class

pull/20822/head
Halil İbrahim Kalkan 2 years ago
parent
commit
6fe49b5a2e
  1. BIN
      docs/en/tutorials/modular-crm/images/sql-server-orders-table-content.png
  2. BIN
      docs/en/tutorials/modular-crm/images/visual-studio-order-reporting-app-service-impl.png
  3. 6
      docs/en/tutorials/modular-crm/part-05.md
  4. 61
      docs/en/tutorials/modular-crm/part-06.md

BIN
docs/en/tutorials/modular-crm/images/sql-server-orders-table-content.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.4 KiB

After

Width:  |  Height:  |  Size: 9.2 KiB

BIN
docs/en/tutorials/modular-crm/images/visual-studio-order-reporting-app-service-impl.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

6
docs/en/tutorials/modular-crm/part-05.md

@ -56,12 +56,12 @@ Now, you can return your IDE and add an `Order` class to the `ModularCrm.Orderin
````csharp
using System;
using Volo.Abp.Domain.Entities;
using ModularCrm.Ordering.Contracts.Enums;
using Volo.Abp.Domain.Entities.Auditing;
namespace ModularCrm.Ordering.Entities
{
public class Order : AggregateRoot<Guid>
public class Order : CreationAuditedAggregateRoot<Guid>
{
public Guid ProductId { get; set; }
public string CustomerName { get; set; }
@ -70,7 +70,7 @@ namespace ModularCrm.Ordering.Entities
}
````
We are allowing to place only a single product within an order. In a real-world application, the `Order` entity would be much more complex. However, the complexity of the `Order` entity doesn't effect modularity, so we keep it simple to focus on modularity in this tutorial.
We are allowing to place only a single product within an order. In a real-world application, the `Order` entity would be much more complex. However, the complexity of the `Order` entity doesn't effect modularity, so we keep it simple to focus on modularity in this tutorial. We are inheriting from the [`CreationAuditedAggregateRoot` class](../../framework/architecture/domain-driven-design/entities.md) since I want to know when an order has been created and who has created it.
### Adding an `OrderState` Enumeration

61
docs/en/tutorials/modular-crm/part-06.md

@ -547,7 +547,7 @@ namespace ModularCrm.Orders
// Product data
public Guid ProductId { get; set; }
public Guid ProductName { get; set; }
public string ProductName { get; set; }
}
}
````
@ -560,4 +560,63 @@ After adding these files, the final folder structure should be like that:
##### Implementing the `OrderReportingAppService` Class
Create an `Orders` folder inside of the `ModularCrm.Application` project and add a class named `OrderReportingAppService` inside it. The final folder structure should be like that:
![visual-studio-order-reporting-app-service-impl](images/visual-studio-order-reporting-app-service-impl.png)
Open the `OrderReportingAppService.cs` file and change its content by the following code block:
````csharp
using ModularCrm.Ordering.Entities;
using ModularCrm.Products;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Volo.Abp.Domain.Repositories;
namespace ModularCrm.Orders
{
public class OrderReportingAppService :
ModularCrmAppService,
IOrderReportingAppService
{
private readonly IRepository<Order, Guid> _orderRepository;
private readonly IRepository<Product, Guid> _productRepository;
public OrderReportingAppService(
IRepository<Order, Guid> orderRepository,
IRepository<Product, Guid> productRepository)
{
_orderRepository = orderRepository;
_productRepository = productRepository;
}
public async Task<List<OrderReportDto>> GetLatestOrders()
{
var orders = await _orderRepository.GetQueryableAsync();
var products = await _productRepository.GetQueryableAsync();
var latestOrders = (from order in orders
join product in products on order.ProductId equals product.Id
orderby order.CreationTime descending
select new OrderReportDto
{
OrderId = order.Id,
CustomerName = order.CustomerName,
State = order.State,
ProductId = product.Id,
ProductName = product.Name
})
.Take(10)
.ToList();
return latestOrders;
}
}
}
````
s

Loading…
Cancel
Save