Untitled

mail@pastecode.io avatar
unknown
csharp
2 years ago
1.3 kB
1
Indexable
Never
using System;
using System.Threading.Tasks;
using AsgardMarketplace.Domain.Models;
using AsgardMarketplace.Domain.Repositories;

namespace AsgardMarketplace.Domain.Services
{
    public class OrderService
    {
        private readonly AsgardRepository _repo;
        private readonly NotificationService _notificationService;
        public OrderService(AsgardRepository repo)
        {
            _repo = repo;
            _notificationService = new NotificationService();
        }

        public async Task RemoveOrders()
        {
            await _repo.RemoveOrders();
        }

        public async Task<bool> MarkOrderAsDelivered(string seller, string orderId)
        {

            var result = await _repo.MarkCompleted(Guid.Parse(orderId));

            if (result.Item1 == true) //If marking successful
            {

                _notificationService.SendNotification(
                    seller,             // Seller
                    result.Item2.Buyer,  // Buyer
                    orderId,     // OrderId
                    "Orderred delivered" // Message
                    );
            }

            return result.Item1;
        }

        public async Task<Order> MarkOrderAsPaid(string orderId)
        {
            return await _repo.MarkOrderAsPaid(Guid.Parse(orderId));
        }
    }
}