public IEnumerable <BLLProduct> GetByType(BLLJewType type) { JewType searchForType = BLLJewTypeToJewType(type); JewType searchResultJewTypeInDB = _myJewStore.SearchByJewType(searchForType); if (searchResultJewTypeInDB != null) { var searchProductTypeInDB = _myJewStore.GetByType(searchResultJewTypeInDB); if (searchProductTypeInDB != null) { List <BLLProduct> searchProductByType = new List <BLLProduct>(); foreach (var item in searchProductTypeInDB) { searchProductByType.Add(ProductToBLLProduct(item)); } return(searchProductByType); } else { Console.WriteLine("No items of such type"); return(null); } } else { Console.WriteLine("This type diesnt exist in DB"); return(null); } }
private Product BLLProductToProduct(BLLProduct itemToMap) { JewType mapJewType = new JewType() { Name = itemToMap.JewType.Name }; List <Gemstone> mapGemstones = new List <Gemstone>(); if (itemToMap.Gemstone != null) { foreach (var gem in itemToMap.Gemstone) { mapGemstones.Add(new Gemstone() { Name = gem.Name, Size = gem.Size, Colour = gem.Colour, Price = gem.Price }); } } decimal productPrice = itemToMap.Gemstone.Sum(x => x.Price); Product product = new Product() { Name = itemToMap.Name, Price = productPrice, JewTypeId = itemToMap.JewTypeId, JewType = mapJewType, Gemstone = mapGemstones }; return(product); }
private JewType BLLJewTypeToJewType(BLLJewType itemToMap) { JewType mapJewType = new JewType() { Id = itemToMap.Id, Name = itemToMap.Name }; return(mapJewType); }
public void Add(BLLProduct newProduct) { int numberOfGems = newProduct.Gemstone.Count; //check jems number, error, if more than 10 gems in one product if (numberOfGems > 10) { Console.WriteLine($"Maximum 10 gems per product, but you have {numberOfGems}. Item add failed."); return; } Product itemToAdd = BLLProductToProduct(newProduct); //check if we have such type of product in DB, assign existing type JewType searchJewTypeInDB = _myJewStore.SearchByJewType(itemToAdd.JewType); if (searchJewTypeInDB != null) { itemToAdd.JewType = searchJewTypeInDB; } _myJewStore.Add(itemToAdd); }
public JewType SearchByJewType(JewType curType) { var jewType = _curJewStoreContext.JewTypes.Where(x => x.Name == curType.Name).FirstOrDefault(); return(jewType); }
public IEnumerable <Product> GetByType(JewType type) { var productByType = _curJewStoreContext.Products.Include(product => product.JewType).Include(product => product.Gemstone).Where(x => x.JewType.Name == type.Name).ToList(); return(productByType); }