public async Task Handle(JObject jObject, ILog log, CancellationToken cancellationToken) { try { log.Info("Consume ProductUpdatedEvent"); var dataConsomed = jObject.ToObject <ProductUpdatedEvent>(); var data = await _ProductQueries.GetProduct(dataConsomed.Id); if (data != null) { data = _mapper.Map <MstProduct>(dataConsomed); log.Info("Update Product"); //Consume data to Read Db _ProductRepository.Update(data); await _uow.CommitAsync(); } } catch (Exception ex) { log.Error("Error Updating data Product", ex); throw ex; } }
public async Task <ProductDTO> GetCartProduct(int ProductID) { var product = await _repository.GetProduct(ProductID); if (product == null) { throw new Exception("Couldn't find product"); } return(product); }
public async Task <IActionResult> Get(Guid id) { try { var data = await _productQueries.GetProduct(id); return(Ok(new ApiOkResponse(data, data != null ? 1 : 0))); } catch (Exception ex) { _logger.LogCritical(ex, $"Error on Get Customer [{id}]"); return(BadRequest(new ApiBadRequestResponse(500, "Something Wrong"))); } }
public async Task Handle(JObject jObject, ILog log, CancellationToken cancellationToken) { try { bool orderIsValid = true; string message = null; log.Info("Consume OrderCreatedEvent"); var dataConsomed = jObject.ToObject <OrderCreatedEvent>(); var allProduct = dataConsomed.OrderDetail .Select(x => x.ProductId) .ToList(); //Consume data and validate the data allProduct.ForEach(async item => { var dataIsExist = await _productQueries.GetProduct(item); if (dataIsExist == null) { orderIsValid = false; } }); if (orderIsValid == false) { message = "Product not found"; } var @event = new OrderValidatedEvent { Action = "Product", Data = dataConsomed, OrderId = dataConsomed.OrderId, IsValid = orderIsValid, Messages = new List <string> { message } }; await _producer.Send(@event, AppGlobalTopic.PosTopic); } catch (Exception ex) { log.Error("Error Validating order by product", ex); throw ex; } }
public async Task Handle(JObject jObject, ILog log, CancellationToken cancellationToken) { try { log.Info("Consume ProductDeletedEvent"); var dataConsomed = jObject.ToObject<ProductDeletedEvent>(); var data = await _ProductQueries.GetProduct(dataConsomed.ProductId); log.Info("Delete Product"); //Consume data to Read Db _ProductRepository.Delete(data); await _uow.CommitAsync(); } catch (Exception ex) { log.Error("Error Deleteing data Product", ex); throw ex; } }