public async Task <ProductWithDefect> GetAsyncByShopAndIdDTO(int id, int?shopId)
        {
            var res = await RepositoryDbSet
                      .Include(a => a.Product).ThenInclude(aa => aa.ProductName).ThenInclude(t => t.Translations)
                      .Include(d => d.Defect).ThenInclude(aa => aa.Description).ThenInclude(t => t.Translations)
                      .Where(p => p.Product.ShopId == shopId && p.Id == id)
                      .Select(p => new
            {
                Id = p.Id,
                DefectDescription             = p.Defect.Description,
                DefectId                      = p.DefectId,
                DefectRecordingTime           = p.DefectRecordingTime,
                ProductId                     = p.ProductId,
                ProductName                   = p.Product.ProductName,
                Quantity                      = p.Quantity,
                DefectDescriptionTranslations = p.Defect.Description.Translations,
                ProductNameTranslations       = p.Product.ProductName.Translations
            })
                      .FirstOrDefaultAsync();

            var result = new ProductWithDefect()
            {
                Id = res.Id,
                DefectDescription   = res.DefectDescription.Translate(),
                DefectId            = res.DefectId,
                DefectRecordingTime = res.DefectRecordingTime,
                ProductId           = res.ProductId,
                ProductName         = res.ProductName.Translate(),
                Quantity            = res.Quantity
            };

            return(result);
        }
Esempio n. 2
0
        public static BLL.App.DTO.ProductWithDefect MapFromDAL(DAL.App.DTO.ProductWithDefect productWithDefect)
        {
            var res = productWithDefect == null ? null : new BLL.App.DTO.ProductWithDefect
            {
                Id                  = productWithDefect.Id,
                ProductId           = productWithDefect.ProductId,
                ProductName         = productWithDefect.ProductName,
                DefectRecordingTime = productWithDefect.DefectRecordingTime,
                Quantity            = productWithDefect.Quantity,
                DefectId            = productWithDefect.DefectId,
                DefectDescription   = productWithDefect.DefectDescription,
            };

            return(res);
        }