}/// <summary> /// map product from business layer to presentation layer /// </summary> /// <param name="itemToMap"></param> /// <returns></returns> private PLProduct BLLProductToPLProduct(BLLProduct itemToMap) { PLJewType mapJewType = new PLJewType() { Name = itemToMap.JewType.Name }; List <PLGemstone> mapGemstones = new List <PLGemstone>(); if (itemToMap.Gemstone != null) { foreach (var gem in itemToMap.Gemstone) { mapGemstones.Add(new PLGemstone() { Name = gem.Name, Size = gem.Size, Colour = gem.Colour }); } } //product price from DB is mapped here PLProduct plProduct = new PLProduct() { Name = itemToMap.Name, Price = itemToMap.Price, JewTypeId = itemToMap.JewTypeId, JewType = mapJewType, Gemstone = mapGemstones }; return(plProduct); }
/// <summary> /// map item from presentation layer to business layer /// </summary> /// <param name="itemToMap"></param> /// <returns></returns> private BLLProduct PLProductToBLLProduct(PLProduct itemToMap) { BLLJewType mapJewType = new BLLJewType() { Name = itemToMap.JewType.Name }; List <BLLGemstone> mapGemstones = new List <BLLGemstone>(); //send information about price of each gemstone if (itemToMap.Gemstone != null) { foreach (var gem in itemToMap.Gemstone) { mapGemstones.Add(new BLLGemstone() { Name = gem.Name, Size = gem.Size, Colour = gem.Colour, Price = gem.Price }); } } // no information about product price BLLProduct bllProduct = new BLLProduct() { Name = itemToMap.Name, JewTypeId = itemToMap.JewTypeId, JewType = mapJewType, Gemstone = mapGemstones }; //i dont know: shoul I for each BLLGemstone assign bllProduct as product? return(bllProduct); }/// <summary>
/// <summary> /// check for null /// </summary> /// <param name="newProduct"></param> /// <returns></returns> private bool IsTypeNull(PLProduct newProduct) { if (newProduct.JewType == null) { return(true); } return(false); }
public ActionResult Edit(int id) { SLProduct.ProductInfo Product = this.ProductList.GetProductDetail(id - 1); PLProduct plProduct = ProductClientService.DTO_to_PL_Product(Product); return(View("Edit", plProduct)); }
public void Add(PLProduct newProduct) { if (IsTypeNull(newProduct)) { Console.WriteLine("You need define product type"); return; } BLLProduct productToAdd = PLProductToBLLProduct(newProduct); _jewService.Add(productToAdd); }
public PLProduct GetById(int id) { if (id <= 0) { Console.WriteLine("Id should be positive"); return(null); } BLLProduct bllProductById = _jewService.GetById(id); if (bllProductById != null) { PLProduct plProductById = BLLProductToPLProduct(bllProductById); return(plProductById); } Console.WriteLine($"No product with id={id}"); return(null); }