// GET: Bouquet/Details/5
        public ActionResult Details(int id)
        {
            var bouquet = _bouquetService.GetById(id);

            if (bouquet == null)
            {
                return(HttpNotFound());
            }
            var model        = new BouquetViewModel();
            var bouquetSizes = _bouquetService.GetSizesOfBouquet(id);

            model.BouquetId     = bouquet.Id;
            model.BouquetName   = bouquet.Name;
            model.SizeInBouquet = new List <SizeItemInBouquet>();
            foreach (var bouquetSizeItem in bouquetSizes)
            {
                var bouquetSize = new SizeItemInBouquet
                {
                    Size  = (Size)bouquetSizeItem.SizeId,
                    Price = bouquetSizeItem.Price,
                    FlowerListInBouquet = new List <FlowerItemInBouquet>()
                };
                var flowers    = _bouquetService.GetFlowersInBouquetType(bouquetSizeItem.Id);
                var flowerList = new List <FlowerItemInBouquet>();
                foreach (var flower in flowers)
                {
                    var flowerInBouquet = new FlowerItemInBouquet();
                    flowerInBouquet.FlowerId = flower.FlowerId;
                    var f = _flowerService.GetById(flower.FlowerId);
                    flowerInBouquet.FlowerName  = f.Name;
                    flowerInBouquet.Flower      = f;
                    flowerInBouquet.FlowerCount = flower.FlowerCount;
                    flowerList.Add(flowerInBouquet);
                }
                bouquetSize.FlowerListInBouquet = flowerList;
                model.SizeInBouquet.Add(bouquetSize);
            }
            model.FlowerList = _flowerService.GetAll().ToList();

            return(View(model));
        }
Exemple #2
0
        public ActionResult Index()
        {
            var result = new BouquetsViewModel();

            result.Bouquets = new List <BouquetViewModel>();
            var bouquetList = _bouquetService.GetAll();

            foreach (var item in bouquetList)
            {
                var id           = item.Id;
                var bouquets     = new BouquetViewModel();
                var bouquetSizes = _bouquetService.GetSizesOfBouquet(id);
                bouquets.BouquetId     = id;
                bouquets.BouquetName   = item.Name;
                bouquets.SizeInBouquet = new List <SizeItemInBouquet>();
                foreach (var bouquetSizeItem in bouquetSizes)
                {
                    var bouquet = new SizeItemInBouquet();
                    bouquet.Size  = (Size)bouquetSizeItem.SizeId;
                    bouquet.Price = bouquetSizeItem.Price;
                    bouquet.FlowerListInBouquet = new List <FlowerItemInBouquet>();
                    var flowers    = _bouquetService.GetFlowersInBouquetType(bouquetSizeItem.Id);
                    var flowerList = new List <FlowerItemInBouquet>();
                    foreach (var flower in flowers)
                    {
                        var flowerInBouquet = new FlowerItemInBouquet();
                        flowerInBouquet.FlowerId    = flower.FlowerId;
                        flowerInBouquet.FlowerName  = _flowerService.GetById(flower.FlowerId).Name;
                        flowerInBouquet.FlowerCount = flower.FlowerCount;
                        flowerList.Add(flowerInBouquet);
                    }
                    bouquet.FlowerListInBouquet = flowerList;
                    bouquets.SizeInBouquet.Add(bouquet);
                }
                result.Bouquets.Add(bouquets);
            }
            return(View(result));
        }