protected internal override void ConstraintValidation(Order order, out Order order2) { Departament departament = null; Customer customer = null; products = JsonConvert.DeserializeObject <List <ProductOrder> >(order.ProductOrder); orderID = order.Id; OrderStatus = order.Status; bool isValid = true; //Validates the departament if (!order.Departament.IsNull()) { departament = _departamentRepository.GetById(order.Departament.Id); if (departament.IsNull()) { _bus.RaiseEvent(new DomainNotification("Departament invalid", "The departament is not valid")); isValid = false; } } // Validate the Customer if (!order.Customer.IsNull()) { customer = _customerRepository.GetById(order.Customer.Id); if (departament.IsNull()) { _bus.RaiseEvent(new DomainNotification("Customer invalid", "The customer is not valid")); isValid = false; } } // validates all products foreach (var product in products) { var p = _productRepository.GetById(product.Id); if (p.IsNull()) { _bus.RaiseEvent(new DomainNotification("Product invalid", $"The product with ID {product.Id} and description {product.Description} is not valid")); isValid = false; continue; } if (!p.Active) { _bus.RaiseEvent(new DomainNotification("Product inactive", $"The product {product.Description} is inactive. Inactive products cannot be sale")); isValid = false; continue; } product.Description = p.Description; } if (!isValid) { order2 = null; return; } UpdateStock(); order.Customer = customer; order.Departament = departament; order.ProductOrder = JsonConvert.SerializeObject(products); order2 = order; }
public ActionResponse <DepartamentDto> GetById(Guid id) { var response = _departamentRepository.GetById(id); return(response); }
public DbDepartament GetDepartamentById(long id) { var departament = _departamentRepository.GetById(id); return(departament); }