public async Task <List <SalesProduct> > GetSalesProducts() { if (_SalesProducts == null) { _SalesProducts = new List <SalesProduct>(); var livestocks = await _LiveStockRepo.GetLiveStockProducts(); var productions = await _ProductionRepo.GetProductions(); var salesProducts = await _SalesProductRepo.GetSalesProduct(); var packingInfos = await _PackingRepo.GetPackingInfos(); var resources = await _ResourceRepo.GetResources(); var packResources = await _ResourceRepo.GetPackResources(); foreach (var packResouce in packResources) { packResouce.Resource = resources.FirstOrDefault(d => d.Id == packResouce.ExtraResourceId); } foreach (var packingInfo in packingInfos) { packingInfo.Resources.AddRange(packResources.Where(d => d.SalesProductId == packingInfo.SalesProductId)); } foreach (var production in productions) { production.LivestockProduct = livestocks.FirstOrDefault(d => d.Id == production.LivestockProductId); } foreach (var salesProduct in salesProducts) { salesProduct.Production = productions.FirstOrDefault(d => d.Id == salesProduct.ProductionId); salesProduct.PackingInfo = packingInfos.FirstOrDefault(d => d.SalesProductId == salesProduct.Id) ?? new PackingInfo { SalesProductId = salesProduct.Id, PackingWeight = 1 }; } _SalesProducts.AddRange(salesProducts); } return(_SalesProducts); }
public async Task <ActionResult> Get() { try { var result = await _repository.GetProductions(); if (result == null) { return(NotFound()); } return(Ok(result)); } catch (Exception ex) { throw new JsonException(ex.Message, ex); } }
public JsonResult GetProductions( short MachineNumber, string Operator, short MainTypeId, string Measurements, DateTime FromDate, DateTime ToDate, string DepartmentName ) => new JsonResult(_mapper.Map <IEnumerable <ProductionDto> >( _repository.GetProductions( MachineNumber, Operator, MainTypeId, Measurements, FromDate, ToDate, DepartmentName ) ));