Ejemplo n.º 1
0
        }/// <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);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// map jewerly type from presentation level to business level
        /// </summary>
        /// <param name="itemToMap"></param>
        /// <returns></returns>
        private BLLJewType PLJewTypeToBLLJewType(PLJewType itemToMap)
        {
            BLLJewType mapJewType = new BLLJewType()
            {
                Name = itemToMap.Name
            };

            return(mapJewType);
        }
Ejemplo n.º 3
0
        public IEnumerable <PLProduct> GetByType(PLJewType jewType)
        {
            if (jewType == null)
            {
                Console.WriteLine("Cant define type");
                return(null);
            }
            BLLJewType typeToDefine     = PLJewTypeToBLLJewType(jewType);
            var        bllProductByType = _jewService.GetByType(typeToDefine);

            if (bllProductByType != null)
            {
                List <PLProduct> plProductByType = new List <PLProduct>();
                foreach (var item in bllProductByType)
                {
                    plProductByType.Add(BLLProductToPLProduct(item));
                }
                return(plProductByType);
            }
            return(null);
        }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            JewWorker myJewWorker = new JewWorker();

            int productId   = 9;
            var productById = myJewWorker.GetById(productId);


            PLGemstone amethyst = new PLGemstone()
            {
                Name = "Amethyst", Size = 2, Colour = "Red", Price = 55
            };
            PLGemstone bigDiamond = new PLGemstone()
            {
                Name = "Diamond", Size = 7, Colour = "Sky Blue", Price = 250
            };
            PLGemstone greatEmerald = new PLGemstone()
            {
                Name = "Emerald", Size = 5, Colour = "Dark Green", Price = 220
            };
            PLGemstone smallSapphire = new PLGemstone()
            {
                Name = "Sapphire", Size = 1, Colour = "Blue", Price = 10
            };

            //add ring with N sapphire (can test >10)
            PLJewType ringType = new PLJewType()
            {
                Name = "Ring"
            };
            List <PLGemstone> smallSapphireCollection = new List <PLGemstone>();
            int sapphireCollectionSize = 9;

            for (int i = 0; i < sapphireCollectionSize; i++)
            {
                smallSapphireCollection.Add(smallSapphire);
            }
            //  myJewWorker.Add(new PLProduct() { Name=$"Ring with {sapphireCollectionSize} sapphires", JewType=ringType,Gemstone=smallSapphireCollection});

            //add new jew type (can change name for Bracelet)
            PLJewType amuletType = new PLJewType()
            {
                Name = "Amulet"
            };
            List <PLGemstone> oneAmethystCollection = new List <PLGemstone>();

            oneAmethystCollection.Add(amethyst);
            // myJewWorker.Add(new PLProduct() { Name = $"Amulet with amethyst", JewType = amuletType, Gemstone = oneAmethystCollection });

            //add ring without gems
            //myJewWorker.Add(new PLProduct() { Name = $"Ring without gems", JewType = ringType });

            bool isHaveGems         = false;
            var  productsWihoutGems = myJewWorker.GetByGemsPresence(isHaveGems);

            if (productsWihoutGems != null)
            {
                Console.WriteLine(isHaveGems == false ? "Products with no gems" : "Products with gems");
                foreach (var item in productsWihoutGems)
                {
                    Console.WriteLine($"Product {item.Name}, type {item.JewType.Name}");
                }
            }
            else
            {
                Console.WriteLine("No product without gems");
            }

            //get items by type
            //PLJewType typeToGet = amuletType;
            PLJewType typeToGet = ringType;
            var       allItems  = myJewWorker.GetByType(typeToGet);

            Console.WriteLine($"We have {allItems.Count()} {typeToGet.Name} in the store");

            Console.WriteLine("All tasks have been done");
            Console.ReadKey();
        }