private void CreateReport(int inventoryId) { var report = new InventoryReport(); var inventory = Inventory.FromDto(_inventoryDao.GetInventoryById(inventoryId)); report.Inventory = inventory; var inventoryProducts = _inventoryDao.GetAllInventoryProductsByInventoryId(inventoryId); var zones = _zoneService.GetAllChildZones(inventory.ZoneId); var productsTiedToZone = _productDao.GetAllActiveProductsForZones(zones.Select(x => x.ToDto()).ToList()); foreach (var product in productsTiedToZone) { if (inventoryProducts.Any(x => x.ZoneId == product.ZoneId && x.ProductId == product.Id)) { report.ScannedItems.Add($"Product with id {product.Id} and description {product.Description} scanned correctly"); } else if (inventoryProducts.Any(x => x.ZoneId != product.ZoneId && x.ProductId == product.Id)) { report.MovedItems.Add($"Product with id {product.Id} and description {product.Description} scanned in wrong zone. Scanned zone id {inventoryProducts.Where(x => x.ProductId == product.Id).First().ZoneId} but should be {product.ZoneId}"); } else { report.MissingItems.Add($"Product with id {product.Id} and description {product.Description} is missing"); } } report.Info = $"Raport creaded : {DateTime.Now}, Inventory started {inventory.StartDate} ended {DateTime.Now},\n Items scanned: {report.ScannedItems.Count}, \n Items missing: {report.MissingItems.Count}, \n Items moved {report.MovedItems.Count}"; _inventoryDao.InsertReport(report.ToDto()); }
public List <Product> GetProductsByCriteria(GetProductBySearchTypeDto getProductBySearchTypeDto) { IEnumerable <ProductDto> productDtos = new List <ProductDto>(); if (getProductBySearchTypeDto == null) { return(new List <Product>()); } switch (getProductBySearchTypeDto.ProductSearchTypeId) { case 1: productDtos = _productDao.GetAllProducts(); break; case 2: productDtos = _productDao.GetAllActiveProductsWithStatus(new ProductStatus().Active.Id); break; case 3: if (getProductBySearchTypeDto.ExtraParams == null || !getProductBySearchTypeDto.ExtraParams.ContainsKey("ZoneId")) { productDtos = new List <ProductDto>(); break; } var zones = _zoneService.GetAllChildZones(int.Parse(getProductBySearchTypeDto.ExtraParams["ZoneId"])); productDtos = _productDao.GetAllActiveProductsForZones(zones.Select(x => x.ToDto()).ToList()); break; case 4: productDtos = _productDao.GetAllActiveProductsWithStatus(new ProductStatus().Missing.Id); break; default: productDtos = new List <ProductDto>(); break; } List <Product> products = new List <Product>(); foreach (var productDto in productDtos) { Product product = Product.FromDto(productDto); product.Zone = _zoneService.GetZoneById(productDto.ZoneId); product.Owner = _ownerService.GetOwnerById(productDto.OwnerId); products.Add(product); } return(products); }