public async Task <(float response, string message, bool isSuccess)> GetTotalInvoice(long customerId, CancellationToken cancellationToken) { var customerDetailsQuery = new GetCustomerByIdQuery(customerId); var customerDetails = await _mediator.Send(customerDetailsQuery); if (!customerDetails.isSuccess) { return(0f, $"Unable to complete request \n{customerDetails.message}", false); } var customerOrdersQuery = new GetAllOrdersByCustomerIdQuery(customerId); var customerOrders = await _mediator.Send(customerOrdersQuery); if (!customerOrders.isSuccess) { return(0f, $"Unable to complete request \n{customerOrders.message}", false); } var discountsQuery = new GetAllDiscountsQuery(); var discounts = await _mediator.Send(discountsQuery); if (!discounts.isSuccess) { return(0f, $"Unable to complete request \n{discounts.message}", false); } var discountManager = new DiscountManager(customerDetails, customerOrders, discounts); var totalInvoiceWithDiscount = discountManager.GetDiscountedTotal(); return(totalInvoiceWithDiscount, "Success", true); }
public async Task <IActionResult> GetAllDiscounts() { var query = new GetAllDiscountsQuery(); var result = await _mediator.Send(query); if (result.isSuccess) { return(Ok(new ApiResponse { ResponseCode = "00", ResponseDescription = result.message, Data = result.response })); } return(NotFound(new ApiResponse { ResponseCode = "01", ResponseDescription = result.message, Data = null })); }
public async Task <IEnumerable <Discount> > Handle(GetAllDiscountsQuery request, CancellationToken cancellationToken) { return(await _discountService.GetDiscounts()); }