public ActionResult CreateDish() { try { var allIgrendients = igredientRepo.GetAll(); var newDish = new NewDishViewModel(); var igredientCheckboxmodels = new List <IgredientCheckboxViewModel>(); foreach (var igredient in allIgrendients) { igredientCheckboxmodels.Add(new IgredientCheckboxViewModel { IgredientId = igredient.IngredientIDd, Name = igredient.Name, IsChecked = false }); } newDish.Igredients = igredientCheckboxmodels; return(View("SaveDish", newDish)); } catch (Exception e) { log.Error(e.Message); return(View("Error", new HandleErrorInfo(new Exception("Page not Found"), "Chef", "CreateDish"))); } }
public IActionResult AddDish() { NewDishViewModel viewMod = new NewDishViewModel(); viewMod.AllChefs = dbContext.Chefs.ToList(); return(View(viewMod)); }
public async Task <IActionResult> Index() { List <Produkt> produktList; if (HttpContext.Session.GetString("ingredients") == null) { produktList = new List <Produkt>(); } else { var serializedValue = (HttpContext.Session.GetString("ingredients")); produktList = JsonConvert.DeserializeObject <List <Produkt> >(serializedValue); } var categories = await _dishService.GetDishCategoriesAsync(); var viewModel = new NewDishViewModel { SelectedIngredientsList = new List <Produkt>(), FoodTypeSelectList = new SelectList(categories, "MatrattTyp1", "Beskrivning"), IngredientViewModel = new AddIngredientViewModel(), }; viewModel.IngredientViewModel.IngredientsList = await _dishService.GetDishIngredientsAsync(); viewModel.IngredientViewModel.Ingredients = produktList; return(View(viewModel)); }
public IActionResult NewDish() { NewDishViewModel model = new NewDishViewModel() { Chefs = DbContext.Chef.ToList() }; return(View(model)); }
public ActionResult Edit(int id) { Dish dish = null; try { dish = dishRepo.GetById(id); } catch (Exception e) { log.Error(e.Message); return(View("Error", new HandleErrorInfo(new Exception("Dish not found"), "Chef", "Edit"))); } if (dish != null) { NewDishViewModel dishViewModel = new NewDishViewModel(); dishViewModel.DishId = dish.DishId; dishViewModel.Name = dish.Name; dishViewModel.Price = dish.Price; dishViewModel.IsPescatarian = dish.IsPescatarian; dishViewModel.IsVegan = dish.IsVegan; dishViewModel.IsVegetarian = dish.IsVegetarian; dishViewModel.HasPeanuts = dish.HasPeanuts; dishViewModel.HasSeafood = dish.HasSeafood; dishViewModel.Description = dish.Description; List <IgredientCheckboxViewModel> igredientCheckboxesList = new List <IgredientCheckboxViewModel>(); var igrendientList = igredientRepo.GetAll().ToList(); foreach (Igredient igredient in igrendientList) { IgredientCheckboxViewModel igredientCheckboxViewModel = new IgredientCheckboxViewModel(); igredientCheckboxViewModel.IgredientId = igredient.IngredientIDd; igredientCheckboxViewModel.Name = igredient.Name; // Problem with iterating foreach (Igredient ig in dish.Igredients) { if (ig.IngredientIDd == igredientCheckboxViewModel.IgredientId) { igredientCheckboxViewModel.IsChecked = true; break; } } igredientCheckboxesList.Add(igredientCheckboxViewModel); } dishViewModel.Igredients = igredientCheckboxesList; dishViewModel.Image = dish.Image; return(View("SaveDish", dishViewModel)); } else { return(HttpNotFound()); } }
public IActionResult AddDish(NewDishViewModel newModel) { if (ModelState.IsValid) { DbContext.Add(newModel.NewDish); DbContext.SaveChanges(); System.Console.WriteLine("*********** adding new dish ************"); return(RedirectToAction("Dishes")); } return(View("NewDish")); }
private void SaveNewDish_Click(object sender, RoutedEventArgs e) { NewDishViewModel.Save(); Window parentWindow = Application.Current.MainWindow; if (parentWindow.GetType() == typeof(MainWindow)) { (parentWindow as MainWindow).DataContext = new DishesListViewModel(); (parentWindow as MainWindow).Go.Visibility = Visibility.Visible; } }
public async Task <IActionResult> Index(NewDishViewModel model) { if (!ModelState.IsValid) { var serializedValue = (HttpContext.Session.GetString("ingredients")); var produktList = JsonConvert.DeserializeObject <List <Produkt> >(serializedValue); model.IngredientViewModel = new AddIngredientViewModel { Ingredients = produktList }; var categories = await _dishService.GetDishCategoriesAsync(); model.FoodTypeSelectList = new SelectList(categories, "MatrattTyp1", "Beskrivning"); model.IngredientViewModel.IngredientsList = await _dishService.GetDishIngredientsAsync(); return(View(model)); } // Creating the new Dish and store it to the DB. var dish = new Matratt { MatrattNamn = model.Name.ToFirstLetterUpper(), Beskrivning = model.Description.ToFirstLetterUpper(), MatrattTyp = model.FoodType, Pris = model.Price, }; dish = _dishService.AddNewDish(dish); // Get the selected ingredients from the session var value = (HttpContext.Session.GetString("ingredients")); var ingredientsList = JsonConvert.DeserializeObject <List <Produkt> >(value); // Attach them to the dish var dishIngredients = new List <MatrattProdukt>(); foreach (var ingredient in ingredientsList) { dishIngredients.Add(new MatrattProdukt { MatrattId = dish.MatrattId, ProduktId = ingredient.ProduktId }); } // Add the list of MattrattProdukter to the property of the Matratt, save changes. dish.MatrattProdukt = dishIngredients; await _dishService.UpdateDishAsync(dish); return(RedirectToAction("AdminPage", "Admin")); }
public IActionResult CreateDish(NewDishViewModel dish) { System.Console.WriteLine(dish); if (ModelState.IsValid) { dbContext.Add(dish.New_Dish); dbContext.SaveChanges(); return(RedirectToAction("Dishes")); } else { NewDishViewModel viewMod = new NewDishViewModel(); viewMod.AllChefs = dbContext.Chefs.ToList(); return(View("AddDish", viewMod)); } }
public MenuPage SetValidtion(MenuPage model, NewDishViewModel newModel) { if (newModel.SelectedListItem.Count == 0) { model.Ingredienslow = true; } if (newModel.Matratt.MatrattNamn.Length < 2) { model.Matrattsnamnlength = true; } if (newModel.MatrattnamnTaken == true) { model.MatrattsnamnTaken = true; } return(model); }
public IActionResult CreateDish(NewDishViewModel newModel) { Console.WriteLine(newModel); Console.WriteLine(newModel.Dish.Chef); Console.WriteLine(newModel.Dish.Name); Console.WriteLine(newModel.Dish.Calories); Console.WriteLine(newModel.Dish.Tastiness); Console.WriteLine(newModel.Dish.Description); if (ModelState.IsValid) { dbContext.Add(newModel.Dish); dbContext.SaveChanges(); return(RedirectToAction("dishes")); } else { return(View("NewDish")); } }
public ViewModelLocator() { _navigationService = new NavigationService(); _dataService = new DataService(new UserRepository(), new MenuRepository(), new DishRepository(), new CustomerRepository(), new DelivererRepository(), new EventRepository(), new IngredientRepository()); CustomerOverviewViewModel = new CustomerOverviewViewModel(_navigationService, _dataService); DelivererOverviewViewModel = new DelivererOverviewViewModel(_navigationService, _dataService); EventOverviewViewModel = new EventOverviewViewModel(_navigationService, _dataService); LoginViewModel = new LoginViewModel(_navigationService, _dataService); MainViewModel = new MainViewModel(_navigationService, _dataService); EditCustomerViewModel = new EditCustomerViewModel(_navigationService, _dataService); EditDelivererViewModel = new EditDelivererViewModel(_navigationService, _dataService); EditEventViewModel = new EditEventViewModel(_navigationService, _dataService); EditStaffViewModel = new EditStaffViewModel(_navigationService, _dataService); NewDelivererViewModel = new NewDelivererViewModel(_navigationService, _dataService); NewDishViewModel = new NewDishViewModel(_navigationService, _dataService); NewEventViewModel = new NewEventViewModel(_navigationService, _dataService); NewMenuViewModel = new NewMenuViewModel(_navigationService, _dataService); NewStaffViewModel = new NewStaffViewModel(_navigationService, _dataService); StaffViewModel = new StaffViewModel(_navigationService, _dataService); }
public void CreateDish(NewDishViewModel model) { var matratt = new Matratt() { MatrattNamn = model.Matratt.MatrattNamn, Beskrivning = model.Matratt.Beskrivning, MatrattTyp = model.Matratt.MatrattTyp, Pris = model.Matratt.Pris }; _repository.Create(matratt); var matrattbyid = _repository.GetDishByName(model.Matratt.MatrattNamn); foreach (var item in model.SelectedListItem) { var matrattprodukt = new MatrattProdukt(); matrattprodukt.MatrattId = matrattbyid.MatrattId; matrattprodukt.ProduktId = item; matrattbyid.MatrattProdukt.Add(matrattprodukt); } _repository.UpdateDishIngredienses(matrattbyid.MatrattProdukt.ToList()); }
private void NewDish_Click(object sender, RoutedEventArgs e) { DataContext = new NewDishViewModel(); Go.Visibility = Visibility.Collapsed; }
public ActionResult Add(NewDishViewModel dish) { _dishService.Add(_mapper.Map <DishModel>(dish)); return(RedirectToAction("Index", "Menu")); }
public ActionResult Save(NewDishViewModel newDish, HttpPostedFileBase image1) { if (ModelState.IsValid) { // Checking if the dish alredy exists if (newDish.DishId == 0) { var dish = new Dish(); dish.Name = newDish.Name; dish.Description = newDish.Description; dish.Price = newDish.Price; dish.IsPescatarian = newDish.IsPescatarian; dish.IsVegan = newDish.IsVegan; dish.IsVegetarian = newDish.IsVegetarian; dish.HasPeanuts = newDish.HasPeanuts; dish.HasSeafood = newDish.HasSeafood; dish.Enabled = true; // Seting up the image as byte array if (image1 != null) { dish.Image = new byte[image1.ContentLength]; image1.InputStream.Read(dish.Image, 0, image1.ContentLength); } foreach (var item in newDish.Igredients) { if (item.IsChecked == true) { // Same as below Igredient ig = igredientRepo.GetById(item.IgredientId); dish.Igredients.Add(ig); } } try { dishRepo.Insert(dish); log.Info("New dish named " + newDish.Name + " was created"); } catch (Exception e) { log.Error(e.Message); return(View("Error", new HandleErrorInfo(new Exception("Dish not saved"), "Chef", "Save"))); } } else { // If dish already exists in database var dishInDb = dishRepo.GetById(newDish.DishId); dishInDb.Name = newDish.Name; dishInDb.Description = newDish.Description; dishInDb.Price = newDish.Price; dishInDb.IsPescatarian = newDish.IsPescatarian; dishInDb.IsVegan = newDish.IsVegan; dishInDb.IsVegetarian = newDish.IsVegetarian; dishInDb.HasPeanuts = newDish.HasPeanuts; dishInDb.HasSeafood = newDish.HasSeafood; dishInDb.Enabled = true; if (image1 != null) { dishInDb.Image = new byte[image1.ContentLength]; image1.InputStream.Read(dishInDb.Image, 0, image1.ContentLength); } // Reset ingredients i the existing dish dishInDb.Igredients.Clear(); foreach (var item in newDish.Igredients) { if (item.IsChecked == true) { // Should not create new igredients but take those from db Igredient ig = igredientRepo.GetById(item.IgredientId); dishInDb.Igredients.Add(ig); } } log.Info("Dishish named " + dishInDb.Name + " was edited"); } try { dishRepo.Save(); return(RedirectToAction("Index", "Chef")); } catch (Exception e) { log.Error(e.Message); return(View("Error", new HandleErrorInfo(new Exception("Dish not saved"), "Chef", "Save"))); } } else { // In case of not valid form data return(View("SaveDish", newDish)); } }