//*************************** METHODS **************************************** public async Task <IdResponse> HandleAsync(CreateBookingCommand cmd, CancellationToken ct) { if (String.IsNullOrEmpty(cmd.transporterName)) { var transporter = _transporterRepository.GetById(cmd.TransporterId); cmd.transporterName = transporter.Name; cmd.email = transporter.Email; } _bookingRepository.Insert(new Booking { InternalId = cmd.internalId, Email = cmd.email, EndLoading = DateTime.Now, StartLoading = DateTime.Now, TotalPallets = cmd.totalPallets, ActualArrival = DateTime.Now, TransporterName = cmd.transporterName, BookingTime = cmd.bookingTime, Port = cmd.port, TransporterId = cmd.TransporterId, ExternalId = cmd.ExternalId }); List <Order> orders = new List <Order>(); foreach (var order in cmd.Orders) { orders.Add(new Order { BookingId = cmd.internalId, CustomerNumber = 1.ToString(), Id = Guid.NewGuid(), InOut = order.InOut, OrderNumber = order.OrderNumber, WareNumber = order.WareNumber, Comment = order.Comment, ExternalId = order.ExternalId, TotalPallets = order.TotalPallets, BottomPallets = order.TotalPallets, SupplierName = order.SupplierName }); } foreach (var order in orders) { _orderRepository.Insert(order); } var updateRequest = _utilBookingRepository.Update(); return(new IdResponse(cmd.Id)); }
public async Task <IdResponse> HandleAsync(DeleteTransporterCommand cmd, CancellationToken ct) { if (cmd.Id.Equals(Guid.Empty)) { return(IdResponse.Unsuccessful("Id is empty")); } var transporter = _transporterRepository.GetById(cmd.id); var result = _transporterRepository.DeleteByT(transporter); var user = _context.Users.Find(cmd.id.ToString()); _context.Users.Remove(user); _context.SaveChanges(); var transporterDeletedEvent = new TransporterDeletedEvent { TransporterId = cmd.id }; _eventRouter.EventAsync(transporterDeletedEvent); return(new IdResponse(cmd.Id)); }
public async Task <Transporter> HandleAsync(GetTransporterById query, CancellationToken ct) { var result = _transporterRepository.GetById(query.Id); return(result); }