Esempio n. 1
0
        private async Task setDbErrorMessage(DrinkCategory dbValues,
                                             DrinkCategory clientValues, RestaurantContext context)
        {
            if (dbValues.Name != clientValues.Name)
            {
                ModelState.AddModelError("DrinkCategory.Name",
                                         $"Current value: { dbValues.Name}");
            }
            if (dbValues.MinProductionCost != clientValues.MinProductionCost)
            {
                ModelState.AddModelError("DrinkCategory.MinProductionCost",
                                         $"Current value: {dbValues.MinProductionCost:c}");
            }
            if (dbValues.Alcoholic != clientValues.Alcoholic)
            {
                ModelState.AddModelError("DrinkCategory.Alcoholic",
                                         $"Current value: {dbValues.Alcoholic}");
            }
            if (dbValues.CompanyID != clientValues.CompanyID)
            {
                Company dbCompany = await _context.Companies
                                    .FindAsync(dbValues.CompanyID);

                ModelState.AddModelError("DrinkCategory.CompanyID",
                                         $"Current value: {dbCompany?.Name}");
            }

            ModelState.AddModelError(string.Empty,
                                     "The record you attempted to edit was modifed by another user after you. "
                                     + "The edit operation was canceled and the current values in the database "
                                     + "have been displayed. If you still want to edit this record, click "
                                     + "the Save button again.");
        }
Esempio n. 2
0
        public async Task <IActionResult> Edit(int id, [Bind("ID,Name")] DrinkCategory drinkCategory)
        {
            if (id != drinkCategory.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(drinkCategory);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!DrinkCategoryExists(drinkCategory.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(drinkCategory));
        }
        // GET: DrinkCategories/Edit/5
        public IActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var drinkCategory = new DrinkCategory();

            if (id.Value == -1)
            {
                drinkCategory.Drinks = _drinkRepository.NewDrinks.ToList();
                ViewBag.IsNewList    = true;
            }
            else
            {
                drinkCategory = _categoryRepository.GetDrinkCategoryById(id.Value);
                if (drinkCategory == null)
                {
                    return(NotFound());
                }
                ViewBag.IsNewList = false;
            }
            ViewBag.Parents  = _categoryRepository.Categories.Where(c => c.Id != id && c.ParentId != id);
            ViewBag.CatTypes = _categoryRepository.CategorieTypes;
            return(View(drinkCategory));
        }
        public IActionResult Edit(int id, DrinkCategory drinkCategory, string activetab = "")
        {
            if (id != drinkCategory.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _categoryRepository.UpdateDrinkCategory(drinkCategory);
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!_categoryRepository.DrinkCategoryExists(drinkCategory.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }

                return(new RedirectResult(Url.Action("Edit", new { id }) + activetab));
            }
            ViewBag.Parents  = _categoryRepository.Categories.Where(c => c.Id != id && c.ParentId != id);
            ViewBag.CatTypes = _categoryRepository.CategorieTypes;
            return(View(drinkCategory));
        }
Esempio n. 5
0
 //DrinkCategory
 #region
 public static DrinkCategoryDto MappingDto(this DrinkCategory drinkCategory)
 {
     return(new DrinkCategoryDto
     {
         Id = drinkCategory.Id,
         Title = drinkCategory.Title
     });
 }
        public ActionResult DeleteConfirmed(int id)
        {
            DrinkCategory drinkCategory = db.DrinkCategories.Find(id);

            db.DrinkCategories.Remove(drinkCategory);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
 public void AddDrinkCategory(DrinkCategory drinkCategory)
 {
     if (drinkCategory.Photos != null)
     {
         drinkCategory.Photos = drinkCategory.Photos.Where(p => !p.IsDeleted).ToList();
     }
     _appDbContext.DrinkCategories.Add(drinkCategory);
     _appDbContext.SaveChanges();
 }
 public ActionResult Edit([Bind(Include = "idCategoryDrink,name")] DrinkCategory drinkCategory)
 {
     if (ModelState.IsValid)
     {
         db.Entry(drinkCategory).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(drinkCategory));
 }
Esempio n. 9
0
        //private void LoadPizzaPage()
        //{
        //    var currentMainPage = (Application.Current.MainPage as MasterDetailPage);
        //    currentMainPage.Detail = new NavigationPage(new PizzaPage());
        //    Application.Current.MainPage = currentMainPage;
        //}

        private void LoadPreviousDrinkSelections(DrinkCategory categoryDisplayed)
        {
            //Get drink Order items and load to current screen category.
            //Will load to DrinkDisplayDictionary with key of categoryDisplayed.
            var currentOrder = OrderManager.Instance.OrderInProgress;

            foreach (var orderItem in currentOrder.OrderItems)
            {
                if (orderItem is Drink)
                {
                    var drinkAlreadyOnTempOrder = (Drink)orderItem;

                    //Save items to Dictionary that is on the current order.
                    var drinkKey = Tuple.Create <DrinkType, DrinkSize>(drinkAlreadyOnTempOrder.DrinkType, drinkAlreadyOnTempOrder.DrinkSize);
                    if (DrinksOnTempOrderDictionary.ContainsKey(drinkKey))
                    {
                        DrinksOnTempOrderDictionary[drinkKey] = drinkAlreadyOnTempOrder;
                    }
                    else
                    {
                        DrinksOnTempOrderDictionary.Add(drinkKey, drinkAlreadyOnTempOrder);
                    }

                    //if drink on current order is in category displayed, then we'll want
                    //to show what the order already has.
                    if (drinkAlreadyOnTempOrder.DrinkCategory == categoryDisplayed)
                    {
                        if (!DrinkDisplayDictionary.ContainsKey(categoryDisplayed))
                        {
                            LoadDrinkCategoryForDisplay(categoryDisplayed);
                        }

                        //Populate current drink items displayed with item count of
                        //drinks already on the order.
                        var drinksDisplayed = DrinkDisplayDictionary[categoryDisplayed];
                        foreach (var drinkDisplayItem in drinksDisplayed)
                        {
                            foreach (var drink in drinkDisplayItem.RowDrinks)
                            {
                                if (drink.DrinkType == drinkAlreadyOnTempOrder.DrinkType &&
                                    drink.DrinkSize == drinkAlreadyOnTempOrder.DrinkSize)
                                {
                                    drink.ItemCount = drinkAlreadyOnTempOrder.ItemCount;
                                }
                            }

                            //if (saveDrinkTypeToScrollTo == drinkDisplayItem.Drink.DrinkType)
                            //{
                            //    drinkDisplayIndexToScrollTo = drinkDisplayItem.DrinkDisplayItemIndex;
                            //}
                        }
                    }
                }
            }
        }
Esempio n. 10
0
        private IActionResult HandleDeletedDrinkCategory()
        {
            var deletedDrinkCategory = new DrinkCategory();

            // ModelStat contains the posted data because of the deletion error
            // and will overide the Drink Category instance values when displaying page()
            ModelState.AddModelError(string.Empty,
                                     "Unable to save. The drink category was deleted by another user.");
            CompanyNameSL = new SelectList(_context.Companies, "ID", "Name", DrinkCategory.CompanyID);
            return(Page());
        }
Esempio n. 11
0
        public async Task <IActionResult> Create([Bind("ID,Name")] DrinkCategory drinkCategory)
        {
            if (ModelState.IsValid)
            {
                _context.Add(drinkCategory);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(drinkCategory));
        }
Esempio n. 12
0
        private void LoadDrinkCategoryForDisplay(DrinkCategory newDrinkCategory)
        {
            List <DrinkDisplayRow> rows = new List <DrinkDisplayRow>();

            try
            {
                if (DrinkDisplayDictionary.ContainsKey(newDrinkCategory))
                {
                    rows = DrinkDisplayDictionary[newDrinkCategory];
                }
                else
                {
                    List <Drink> drinksForDisplay = MenuDrinks.GetDrinksList(newDrinkCategory);
                    if (newDrinkCategory == DrinkCategory.DraftBeer)
                    {
                        var pints    = new List <Drink>();
                        var pitchers = new List <Drink>();
                        foreach (var drink in drinksForDisplay)
                        {
                            if (drink.DrinkSize == DrinkSize.Pint)
                            {
                                pints.Add(drink);
                            }
                            else
                            {
                                pitchers.Add(drink);
                            }
                        }
                        rows = GetDrinkDisplayRows(pints);
                        rows.AddRange(GetDrinkDisplayRows(pitchers));
                    }
                    else
                    {
                        rows = GetDrinkDisplayRows(drinksForDisplay);
                    }

                    DrinkDisplayDictionary.Add(newDrinkCategory, rows);
                }

                if (newDrinkCategory == DrinkCategory.DraftBeer)
                {
                    DrinksGroups = new ObservableCollection <DrinksGroup>(ConvertBeerRowsToGroups(rows));
                }
                else
                {
                    DrinkDisplayItems = new ObservableCollection <DrinkDisplayRow>(rows);
                }
            }
            catch (Exception ex)
            {
                var error = ex.InnerException;
                throw;
            }
        }
 public IActionResult Create(DrinkCategory drinkCategory)
 {
     if (ModelState.IsValid)
     {
         _categoryRepository.AddDrinkCategory(drinkCategory);
         return(RedirectToAction(nameof(Index)));
     }
     ViewBag.Parents  = _categoryRepository.Categories;
     ViewBag.CatTypes = _categoryRepository.CategorieTypes;
     return(View(drinkCategory));
 }
Esempio n. 14
0
        public static List <Drink> GetDrinksList(DrinkCategory drinkCategory)
        {
            switch (drinkCategory)
            {
            case DrinkCategory.SoftDrink:
                if (SoftDrinks == null || SoftDrinks.Count <= 0)
                {
                    CreateSoftDrinks();
                }
                return(SoftDrinks);

            case DrinkCategory.DraftBeer:
                if (DraftBeers == null || DraftBeers.Count <= 0)
                {
                    CreateDraftBeers();
                }
                return(DraftBeers);

            case DrinkCategory.BottledBeer:
                if (BottledBeers == null || BottledBeers.Count <= 0)
                {
                    CreateBottledBeers();
                }
                return(BottledBeers);

            case DrinkCategory.GlassWine:
                if (GlassWines == null || GlassWines.Count <= 0)
                {
                    CreateGlassWines();
                }
                return(GlassWines);

            case DrinkCategory.BottleWine:
                if (BottleWines == null || BottleWines.Count <= 0)
                {
                    CreateBottleWines();
                }
                return(BottleWines);
                //case DrinkCategory.HouseWine:
                //    if (HouseWines == null || HouseWines.Count <= 0)
                //    {
                //        CreateHouseWines();
                //    }
                //    return HouseWines;
                //case DrinkCategory.HotDrink:
                //    if (HotDrinks == null || HotDrinks.Count <= 0)
                //    {
                //        CreateHotDrinks();
                //    }
                //    return HotDrinks;
            }
            return(new List <Drink>());
        }
        // GET: DrinkCategories/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            DrinkCategory drinkCategory = db.DrinkCategories.Find(id);

            if (drinkCategory == null)
            {
                return(HttpNotFound());
            }
            return(View(drinkCategory));
        }
Esempio n. 16
0
        public IViewComponentResult Invoke(DrinkCategory cat)
        {
            var isMobileTablet = _device.Type == DeviceType.Mobile || _device.Type == DeviceType.Tablet;
            var isOpen         = DateTime.Now.TimeOfDay > TimeSpan.FromHours(8) && DateTime.Now.TimeOfDay < TimeSpan.FromHours(17);
            var drinks         = cat.Id == 0 ? _drinkRepository.PreferredDrinks.ToList() : cat.Id == -1 ? _drinkRepository.NewDrinks.ToList(): _drinkRepository.DrinksByCategory(cat.Id).ToList();
            var notifyPopup    = _notifyPopupRepository.GetActiveNotifyPopup();

            ViewData["IsOpen"]         = isOpen;
            ViewData["NotifyPopup"]    = notifyPopup;
            ViewData["isMobileTablet"] = isMobileTablet;
            ViewData["cat"]            = cat;

            return(View(drinks));
        }
Esempio n. 17
0
        public async Task <IActionResult> OnGetAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            DrinkCategory = await _context.DrinkCategories
                            .Include(d => d.CompanyHead).FirstOrDefaultAsync(m => m.DrinkCategoryID == id);

            if (DrinkCategory == null)
            {
                return(NotFound());
            }
            return(Page());
        }
        public ActionResult Create([Bind(Include = "idCategoryDrink,name")] DrinkCategory drinkCategory)
        {
            int idcare = Convert.ToInt32(Request["idCategoryDrink"]);
            var ds     = db.DrinkCategories.Where(x => x.idCategoryDrink == idcare);

            if (ds.Count() > 0)
            {
                ModelState.AddModelError("", "Mã danh mục đã tồn tại");
            }
            if (ModelState.IsValid)
            {
                db.DrinkCategories.Add(drinkCategory);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(drinkCategory));
        }
 // To protect from overposting attacks, enable the specific properties you want to bind to, for
 // more details, see https://aka.ms/RazorPagesCRUD.
 public async Task<IActionResult> OnPostAsync(string[] selectedCategories)
 {
     var newDrink = new Drink();
     if(selectedCategories != null)
     {
         newDrink.DrinkCategories = new List<DrinkCategory>();
         foreach(var cat in selectedCategories)
         {
             var catToAdd = new DrinkCategory
             {
                 CategoryID = int.Parse(cat)
             };
             newDrink.DrinkCategories.Add(catToAdd);
         }
     }
     if(await TryUpdateModelAsync<Drink>(newDrink,"Drink",i => i.Name, i => i.Company, i => i.Price, i => i.ExpiringDate, i => i.StoreID)){
         _context.Drink.Add(newDrink);
         await _context.SaveChangesAsync();
         return RedirectToPage("./Index");
     }
     PopulateAssignedCategoryData(_context, newDrink);
     return Page();
 }
        public void UpdateDrinkCategory(DrinkCategory drinkCategory)
        {
            if (drinkCategory.Photos != null)
            {
                foreach (var photoModel in drinkCategory.Photos)
                {
                    if (photoModel.Id != 0)
                    {
                        var photo = _appDbContext.DrinkCategoryPhotos.Find(photoModel.Id);
                        _appDbContext.Entry(photo).State = EntityState.Detached;
                        //deleted
                        if (photoModel.IsDeleted)
                        {
                            _appDbContext.DrinkCategoryPhotos.Remove(photo);
                        }
                        else
                        {
                            photo.IsPrimary = photoModel.IsPrimary;
                            _appDbContext.Update(photo);
                        }
                    }
                    else
                    {
                        if (!photoModel.IsDeleted)
                        {
                            photoModel.DrinkCategoryId = drinkCategory.Id;
                            _appDbContext.DrinkCategoryPhotos.Add(photoModel);
                        }
                    }
                }
            }

            _appDbContext.Entry(drinkCategory).State = EntityState.Modified;
            _appDbContext.Update(drinkCategory);
            _appDbContext.SaveChanges();
        }
Esempio n. 21
0
        public void OnDrinksSelected(DrinkCategory newDrinkCategory)
        {
            try
            {
                if (IsDrinkSelectedForEdit)
                {
                    List <Drink> drinksForDisplay = MenuDrinks.GetDrinksList(newDrinkCategory);
                    for (int i = 0; i < drinksForDisplay.Count; i++)
                    {
                        if (drinksForDisplay[i].DrinkType == drinkSelectedForEditDrinkType &&
                            drinksForDisplay[i].DrinkSize == drinkSelectedForEditDrinkSize)
                        {
                            if (newDrinkCategory == DrinkCategory.DraftBeer)
                            {
                                if (i < 5)
                                {
                                    DrinkForEditIndex = (int)Math.Floor(i / 3M);
                                }
                                else
                                {
                                    switch (i)
                                    {
                                    case 5:
                                    case 6:
                                    case 7:
                                        DrinkForEditIndex = 2;
                                        break;

                                    case 8:
                                        DrinkForEditIndex = 3;
                                        break;
                                    }
                                }
                            }
                            else
                            {
                                DrinkForEditIndex = (int)Math.Floor(i / 3M);
                            }
                            break;
                        }
                    }
                }
                else
                {
                    ScrollToTopOfList?.Invoke(this, EventArgs.Empty);
                }
                //Load new drinks onto page.
                LoadDrinkCategoryForDisplay(newDrinkCategory);
            }
            catch (Exception ex)
            {
                var error = ex.InnerException;
                throw;
            }

            //In case we've already added drinks to this order and are returning to that
            //drink category, we want to show what was added previously.
            LoadPreviousDrinkSelections(newDrinkCategory);
            switch (newDrinkCategory)
            {
            case DrinkCategory.SoftDrink:
                SoftDrinksSelected  = true;
                BottledBeerSelected = false;
                DraftBeerSelected   = false;
                GlassWineSelected   = false;
                BottleWineSelected  = false;
                break;

            case DrinkCategory.DraftBeer:
                DraftBeerSelected   = true;
                SoftDrinksSelected  = false;
                BottledBeerSelected = false;
                GlassWineSelected   = false;
                BottleWineSelected  = false;
                break;

            case DrinkCategory.BottledBeer:
                BottledBeerSelected = true;
                SoftDrinksSelected  = false;
                DraftBeerSelected   = false;
                GlassWineSelected   = false;
                BottleWineSelected  = false;
                break;

            case DrinkCategory.GlassWine:
                GlassWineSelected   = true;
                SoftDrinksSelected  = false;
                BottledBeerSelected = false;
                DraftBeerSelected   = false;
                BottleWineSelected  = false;
                break;

            case DrinkCategory.BottleWine:
                BottleWineSelected  = true;
                SoftDrinksSelected  = false;
                BottledBeerSelected = false;
                DraftBeerSelected   = false;
                GlassWineSelected   = false;
                break;
            }
            currentDrinkCategorySelected = newDrinkCategory;
        }
Esempio n. 22
0
        public static void Initialize(RestaurantContext context)
        {
            //context.Database.EnsureDeleted(); // makes sure the database starts fresh by deleting any old databases
            // Migrations added -- 01/27/2020 --
            // context.Database.EnsureCreated(); // creates new database if there isn't one already.

            // Looks for any Food
            // Change conditional to check for all models
            if (context.Foods.Any())
            {
                return; //DB has been seeded aka has foods
            }


            //Initialize Foods
            var foods = new Food[]
            {
                new Food
                {
                    Name           = "Taco",
                    ExpirationDate = DateTime.Parse("2020-01-25"),
                    Quantity       = 20
                },
                new Food
                {
                    Name           = "Burger",
                    ExpirationDate = DateTime.Parse("2020-02-01"),
                    Quantity       = 30
                },
                new Food
                {
                    Name           = "Sandwich",
                    ExpirationDate = DateTime.Parse("2020-01-01"),
                    Quantity       = 50
                },
                new Food
                {
                    Name           = "Ramen",
                    ExpirationDate = DateTime.Parse("2020-03-05"),
                    Quantity       = 100
                },
                new Food
                {
                    Name           = "Pizza",
                    ExpirationDate = DateTime.Parse("2020-04-01"),
                    Quantity       = 25
                },
                new Food
                {
                    Name           = "Hot Dog",
                    ExpirationDate = DateTime.Parse("2020-12-31"),
                    Quantity       = 15
                }
            };

            foreach (Food f in foods)
            {
                context.Foods.Add(f);
            }
            context.SaveChanges();

            //Initialize Beverage Companies
            var companys = new Company[]
            {
                new Company
                {
                    Name        = "Coca-Cola",
                    FoundedDate = DateTime.Parse("1920-01-15")
                },
                new Company
                {
                    Name        = "Nestle",
                    FoundedDate = DateTime.Parse("1845-05-24")
                },
                new Company
                {
                    Name        = "Heineken",
                    FoundedDate = DateTime.Parse("1953-03-24")
                }
            };

            foreach (Company c in companys)
            {
                context.Companies.Add(c);
            }
            context.SaveChanges();

            //Initialize Drink Categories

            var drinkCats = new DrinkCategory[]
            {
                //Single will look for 1 instance, it throws an exception if 0 or more than 1 is found.
                new DrinkCategory
                {
                    Name = "Soft Drink",
                    MinProductionCost = 1000.00m,
                    Alcoholic         = "no",
                    CompanyID         = companys.Single(c => c.Name == "Coca-Cola").CompanyID
                },
                new DrinkCategory
                {
                    Name = "Bottled Water",
                    MinProductionCost = 2020.20m,
                    Alcoholic         = "no",
                    CompanyID         = companys.Single(c => c.Name == "Nestle").CompanyID
                },
                new DrinkCategory
                {
                    Name = "Beer",
                    MinProductionCost = 150.00m,
                    Alcoholic         = "yes",
                    CompanyID         = companys.Single(c => c.Name == "Heineken").CompanyID
                }
            };

            foreach (DrinkCategory d in drinkCats)
            {
                context.DrinkCategories.Add(d);
            }
            context.SaveChanges();

            //Initialize Drinks
            var drinks = new Drink[]
            {
                new Drink
                {
                    DrinkID         = 1001,
                    Name            = "Coke",
                    Size            = 20.0,
                    DrinkCategoryID = drinkCats.Single(d => d.Name == "Soft Drink").DrinkCategoryID
                },
                new Drink
                {
                    DrinkID         = 1002,
                    Name            = "Water",
                    Size            = 32.0,
                    DrinkCategoryID = drinkCats.Single(d => d.Name == "Bottled Water").DrinkCategoryID
                },
                new Drink
                {
                    DrinkID         = 1003,
                    Name            = "Sprite",
                    Size            = 16.0,
                    DrinkCategoryID = drinkCats.Single(d => d.Name == "Soft Drink").DrinkCategoryID
                },
                new Drink
                {
                    DrinkID         = 1004,
                    Name            = "Lager",
                    Size            = 12.0,
                    DrinkCategoryID = drinkCats.Single(d => d.Name == "Beer").DrinkCategoryID
                }
            };

            foreach (Drink d in drinks)
            {
                context.Drinks.Add(d);
            }
            context.SaveChanges();

            //Initalize CompanyHQs

            var companyHQs = new CompanyHQ[]
            {
                new CompanyHQ
                {
                    CompanyID = companys.Single(c => c.Name == "Coca-Cola").CompanyID,
                    Location  = "Atlanta, Georgia"
                },
                new CompanyHQ
                {
                    CompanyID = companys.Single(c => c.Name == "Nestle").CompanyID,
                    Location  = "Vevey, Switzerland"
                },
                new CompanyHQ
                {
                    CompanyID = companys.Single(c => c.Name == "Heineken").CompanyID,
                    Location  = "Amsterdam, Netherlands"
                }
            };

            foreach (CompanyHQ c in companyHQs)
            {
                context.CompanyHQs.Add(c);
            }
            context.SaveChanges();

            //Initialize CompanyAssignments

            var drinkAssigns = new DrinkAssignment[]
            {
                new DrinkAssignment
                {
                    DrinkID   = drinks.Single(d => d.Name == "Coke").DrinkID,
                    CompanyID = companys.Single(c => c.Name == "Coca-Cola").CompanyID
                },
                new DrinkAssignment
                {
                    DrinkID   = drinks.Single(d => d.Name == "Water").DrinkID,
                    CompanyID = companys.Single(c => c.Name == "Nestle").CompanyID
                },
                new DrinkAssignment
                {
                    DrinkID   = drinks.Single(d => d.Name == "Sprite").DrinkID,
                    CompanyID = companys.Single(c => c.Name == "Coca-Cola").CompanyID
                },
                new DrinkAssignment
                {
                    DrinkID   = drinks.Single(d => d.Name == "Lager").DrinkID,
                    CompanyID = companys.Single(c => c.Name == "Heineken").CompanyID
                }
            };

            foreach (DrinkAssignment d in drinkAssigns)
            {
                context.DrinkAssignments.Add(d);
            }
            context.SaveChanges();


            //Initialize Menus
            var menus = new Menu[]
            {
                new Menu
                {
                    FoodID      = foods.Single(f => f.Name == "Taco").FoodID,
                    DrinkID     = drinks.Single(d => d.Name == "Sprite").DrinkID,
                    HealthGrade = HealthGrade.F
                },
                new Menu
                {
                    FoodID      = foods.Single(f => f.Name == "Pizza").FoodID,
                    DrinkID     = drinks.Single(d => d.Name == "Water").DrinkID,
                    HealthGrade = HealthGrade.C
                },
                new Menu
                {
                    FoodID      = foods.Single(f => f.Name == "Burger").FoodID,
                    DrinkID     = drinks.Single(d => d.Name == "Water").DrinkID,
                    HealthGrade = HealthGrade.D
                },
                new Menu
                {
                    FoodID      = foods.Single(f => f.Name == "Hot Dog").FoodID,
                    DrinkID     = drinks.Single(d => d.Name == "Lager").DrinkID,
                    HealthGrade = HealthGrade.B
                },
                new Menu
                {
                    FoodID      = foods.Single(f => f.Name == "Ramen").FoodID,
                    DrinkID     = drinks.Single(d => d.Name == "Water").DrinkID,
                    HealthGrade = HealthGrade.A
                },
                new Menu
                {
                    FoodID      = foods.Single(f => f.Name == "Sandwich").FoodID,
                    DrinkID     = drinks.Single(d => d.Name == "Lager").DrinkID,
                    HealthGrade = HealthGrade.D
                }
            };

            foreach (Menu m in menus)
            {
                //
                var menuInDatabase = context.Menus.Where(
                    f =>
                    f.Food.FoodID == m.FoodID &&
                    f.Drink.DrinkID == m.DrinkID).SingleOrDefault();

                if (menuInDatabase == null)
                {
                    context.Menus.Add(m);
                }
            }
            context.SaveChanges();
        }
Esempio n. 23
0
 public static void MappingDrinkCategory(this DrinkCategoryDto drinkCategoryDto, DrinkCategory drinkCategory)
 {
     drinkCategory.Id    = drinkCategoryDto.Id;
     drinkCategory.Title = drinkCategoryDto.Title;
 }