Skip to content

How to use repository in entity for validation or other situation? #10472

Answered by EngincanV
CAH-FlyChen asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @CAH-FlyChen, there are two things you can do,

  • Firstly, you can pass the IProductRepository interface as a parameter to the Lock method
public class stock:entity
{
       public async Task Lock(IProductRepository productRepository, Stock stock, int qty, string batchNo)
        {
            var item = stock.Details.Single(t => t.BatchNo == batchNo);
            if (qty > stock.AvalableQty)
            {
                var prod = (await productRepository.WithDetailsAsync(t => t.ProductTemplate)).Single(t => t.Id == stock.ProductId);
                       throw new ZionCommonException($"product{prod.ProductTemplate.Name} [{prod.ProductTemplate.MainOE}],batch:{batchNo} is not enough");

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@CAH-FlyChen
Comment options

Answer selected by CAH-FlyChen
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants