public IActionResult AddMeal(AddMealViewModel addMealViewModel, int id) { if (ModelState.IsValid) { //var StudentID = addMealViewModel.StudentID; Student student = context.Students.Single(s => s.ID == id); FoodAmount newFoodAmount = context.FoodAmounts.Single(f => f.ID == addMealViewModel.FoodAmountID); MealTime newMealTime = context.MealTimes.Single(m => m.ID == addMealViewModel.MealTimeID); MealDescription newMealDescription = new MealDescription { StudentID = student.ID, Description = addMealViewModel.Description, MealTime = newMealTime, FoodAmount = newFoodAmount }; context.MealDescriptions.Add(newMealDescription); context.SaveChanges(); return(Redirect(string.Format("/Form/ToddlerForm/{0}", student.ID))); } return(View(addMealViewModel)); }
public async Task <IActionResult> AddMeal(AddMealViewModel model) { if (ModelState.IsValid) { if (Request.Form.Files.Any()) { var file = model.MealImage; if (file != null && file.Length > 0) { string uri = ImageSave(file, "mealImage"); model.ImageUrl = uri; } } // meal contents images if (model.MealContents != null && model.MealContents.Any()) { foreach (var content in model.MealContents) { content.ImageUrl = Utility.FileHelper.SaveImage(model.MealImage, "MealContentImages"); } } await restaurantApi.AddnewMeal(model); return(RedirectToAction("Success")); } var allRestaurants = await restaurantApi.GetAllRestaurants(); var mealCategories = await restaurantApi.GetAllMealCategories(); ViewBag.RestaurantId = allRestaurants; ViewBag.MealCategoryId = mealCategories; return(View(model)); }
public async Task <IActionResult> Create(AddMealViewModel addMealViewModel) { if (ModelState.IsValid) { WeatherType newWeatherType = _context.WeatherTypes.Single(w => w.ID == addMealViewModel.WeatherTypeID); CookingMethod newCookingMethod = _context.CookingMethods.Single(m => m.ID == addMealViewModel.CookingMethodID); CookingMethod newAltCookingMethod = _context.CookingMethods.Single(a => a.ID == addMealViewModel.AltCookingMethodID); CookingTime newCookingTime = _context.CookingTimes.Single(t => t.ID == addMealViewModel.CookingTimeID); PrepTime newPrepTime = _context.PrepTimes.Single(p => p.ID == addMealViewModel.PrepTimeID); //Add the new default meal to the default meal table Meal newMeal = new Meal { Name = addMealViewModel.Name, Description = addMealViewModel.Description, Location = addMealViewModel.Location, UserID = addMealViewModel.UserID, WeatherType = newWeatherType, CookingMethod = newCookingMethod, AltCookingMethod = newAltCookingMethod, CookingTime = newCookingTime, PrepTime = newPrepTime }; _context.Meals.Add(newMeal); await _context.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(addMealViewModel)); }
/*************** ADD MEAL ***************/ public IActionResult AddMeal() { AddMealViewModel model = new AddMealViewModel(); model.Ingredients = _tomasosContext.Produkt.ToList(); model.Categories = _tomasosContext.MatrattTyp.ToList(); return(PartialView("_AddMealPartial", model)); }
public ActionResult Add() { var categories = this.meals.Categories(); var addMealVm = new AddMealViewModel() { Categories = new SelectList(categories, "Id", "Name") }; return(this.View(addMealVm)); }
public void PutOrderMeal(AddMealViewModel model) { if (!ModelState.IsValid) { throw new Exception("Couldn't add meal to order"); } var meal = Mapper.Map <AddMealViewModel, OrderedMeal>(model); orderService.AddMeal(meal); }
public async Task UpdateMeal(AddMealViewModel meal) { using (HttpClient client = new HttpClient()) { client.BaseAddress = new Uri(baseUrl); var httpContent = new StringContent(JsonConvert.SerializeObject(meal), Encoding.UTF8, "application/json"); HttpResponseMessage msg = await client.PutAsync("meals", httpContent); msg.EnsureSuccessStatusCode(); } }
/*************** UPDATE MEAL ***************/ public IActionResult UpdateMeal(int id) { AddMealViewModel model = new AddMealViewModel(); model.Ingredients = _tomasosContext.Produkt.ToList(); model.Categories = _tomasosContext.MatrattTyp.ToList(); model.Meals = _tomasosContext.Matratt.ToList(); model.Recipe = _tomasosContext.Matratt.SingleOrDefault(x => x.MatrattId == id); //var model = MealList.SingleOrDefault(x => x.Matratt.MatrattId == id); return(PartialView("_UpdateMealPartial", model)); }
public IActionResult UpdateMeal(AddMealViewModel form) { var meal = _tomasosContext.Matratt.SingleOrDefault(x => x.MatrattId == form.Recipe.MatrattId); var currentIngredients = (from p in _tomasosContext.Produkt join mp in _tomasosContext.MatrattProdukt on p.ProduktId equals mp.ProduktId where mp.MatrattId == form.Recipe.MatrattId select p.ProduktId).ToList(); if (meal.MatrattNamn != form.Recipe.MatrattNamn) { meal.MatrattNamn = form.Recipe.MatrattNamn; } if (meal.MatrattTyp != form.Recipe.MatrattTyp) { meal.MatrattTyp = form.Recipe.MatrattTyp; } if (meal.Pris != form.Recipe.Pris) { meal.Pris = form.Recipe.Pris; } var InExistingButNotInForm = currentIngredients.Except(form.SelectedIngredientIds).ToList(); var InFormButNotInExisting = form.SelectedIngredientIds.Except(currentIngredients).ToList(); if (InExistingButNotInForm.Count > 0) { foreach (var ingredient in InExistingButNotInForm) { var i = _tomasosContext.MatrattProdukt .Where(x => x.MatrattId == meal.MatrattId) .Where(x => x.ProduktId == ingredient).SingleOrDefault(); _tomasosContext.MatrattProdukt.Remove(i); } } if (InFormButNotInExisting.Count > 0) { foreach (var ingredient in InFormButNotInExisting) { _tomasosContext.MatrattProdukt.Add(new MatrattProdukt { MatrattId = meal.MatrattId, ProduktId = ingredient }); } } if (ModelState.IsValid) { _tomasosContext.SaveChanges(); } return(RedirectToAction("AlterMenu", "Admin")); }
public ActionResult Add(AddMealViewModel mealVm) { if (this.ModelState.IsValid) { var meal = this.Mapper.Map <Meal>(mealVm); meal.Image = this.images.GetImageFromHttpFileBase(mealVm.Image); this.meals.Add(meal); this.meals.Save(); return(this.RedirectToAction("Details", new { id = meal.Id })); } return(this.View(mealVm)); }
public async Task <IActionResult> AddMealFromExistingRecipe([FromBody] AddMealViewModel mealViewModel) { try { var meal = Mapper.Map <Meal>(mealViewModel); await _mealService.AddMealFromExistingRecipe(UserId, meal); return(Ok(meal.Id)); } catch (Exception ex) { _logger.LogError(LoggingEvents.MEALS_ADD_MEAL_FROM_EXISTING_RECIPE, ex, $"Add meal from existing recipe failed; user id - {UserId}; meal view model - {JsonConvert.SerializeObject(mealViewModel)}"); return(this.InternalServerError()); } }
public void CheckCorrectPriceOutput() { //Unit test..test var addvm = new AddMealViewModel(); List <IngredientModel> testList = new List <IngredientModel>(); IngredientModel model1 = new IngredientModel("TestOne", 1, 5.99m, 1); IngredientModel model2 = new IngredientModel("TestTwo", 2, 2.99m, 1); IngredientModel model3 = new IngredientModel("TestThree", 3, 6.99m, 1); IngredientModel model4 = new IngredientModel("TestFour", 4, 7.00m, 1); testList.Add(model1); testList.Add(model2); testList.Add(model3); testList.Add(model4); Assert.AreEqual(addvm.TotalPrice(testList), 22.97m); }
public ActionResult AddMeal(int mealId, int recipeId) { AddMealViewModel addMealView = new AddMealViewModel(); _dal.AssignRecipeToMeal(mealId, recipeId); addMealView.Recipes = _dal.GetAllRecipesByUserId((int)Session[UserKey]); addMealView.MealRecipes = _dal.GetRecipesByMealId(mealId); addMealView.Meal = _dal.GetMealByMealId(mealId); addMealView.Meal.Id = mealId; return(RedirectToAction("AddMeal", new { name = addMealView.Meal.Name, desc = addMealView.Meal.Description, category = addMealView.Meal.CategoryId, creator = addMealView.Meal.CreatorId, id = (int?)mealId })); }
public async Task <IActionResult> Edit(AddMealViewModel model) { if (ModelState.IsValid) { try { if (Request.Form.Files.Any()) { var file = model.MealImage; if (file != null && file.Length > 0) { string uri = ImageSave(file, "mealImage"); model.ImageUrl = uri; } } // meal contents images if (model.MealContents != null && model.MealContents.Any()) { foreach (var content in model.MealContents) { content.ImageUrl = ImageSave(model.MealImage, "mealcontent"); } } await mealApi.UpdateMeal(model); return(RedirectToAction("index")); } catch (Exception ex) { ModelState.AddModelError("", "An error occured during update!"); return(View(model)); } } var allRestaurants = await restaurantApi.GetAllRestaurants(); var mealCategories = await restaurantApi.GetAllMealCategories(); ViewBag.RestaurantId = new SelectList(allRestaurants, "Id", "Name", model.RestaurantId); ViewBag.MealCategoryId = new SelectList(mealCategories, "Id", "Name", model.MealCategoryId); return(View(model)); }
public IActionResult AddMeal(AddMealViewModel model) { Matratt matratt = new Matratt(); matratt = model.Recipe; foreach (var ingredient in model.SelectedIngredientIds) { matratt.MatrattProdukt.Add(new MatrattProdukt { MatrattId = model.Recipe.MatrattId, ProduktId = ingredient }); } if (ModelState.IsValid) { _tomasosContext.Add(matratt); _tomasosContext.SaveChanges(); return(RedirectToAction("AdminPanel", "Admin")); } return(View()); }
public ActionResult AddMeal(string name, string desc, int category, int?creator, int?id) { AddMealViewModel addMeal = new AddMealViewModel(); if (id > 0) { addMeal.Meal = _dal.GetMealByMealId((int)id); addMeal.MealRecipes = _dal.GetRecipesByMealId((int)id); } bool doesExist = _dal.MealExists(name); if (IsAuthenticated) { if (!doesExist) //checks if meal exists before adding to DB { Meal meal = new Meal(); meal.Name = name; meal.Description = desc; meal.UserId = (int)Session[UserKey]; meal.CategoryId = category; meal.CreatorId = meal.UserId; meal.Id = _dal.AddMeal(meal); addMeal.Meal = meal; } else { addMeal.Meal = _dal.GetMealByMealName(name); } addMeal.Recipes = _dal.GetAllRecipesByUserId((int)Session[UserKey]); _nextView = "AddMeal"; } return(GetAuthenticatedView(_nextView, addMeal)); }
// GET: Meals/Create public IActionResult Create() { var claimsIdentity = (ClaimsIdentity)this.User.Identity; var claim = claimsIdentity.FindFirst(System.Security.Claims.ClaimTypes.NameIdentifier); var userId = claim.Value; if (userId != null) { AddMealViewModel addMealViewModel = new AddMealViewModel( userId, _context.WeatherTypes.ToList(), _context.CookingMethods.ToList(), _context.CookingMethods.ToList(), _context.CookingTimes.ToList(), _context.PrepTimes.ToList()); return(View(addMealViewModel)); } else { return(RedirectToAction("Home/Index")); } }
public async Task <IActionResult> AddMeal(AddMealViewModel model) { if (ModelState.IsValid) { var file = Request.Form.Files[0]; if (file != null && file.Length > 0) { string uri = SaveImageAndGetUri(); model.ImageUrl = uri; } await restaurantApi.AddnewMeal(model); return(RedirectToAction("Success")); } var allRestaurants = await restaurantApi.GetAllRestaurants(); var mealCategories = await restaurantApi.GetAllMealCategories(); ViewBag.RestaurantId = allRestaurants; ViewBag.MealCategoryId = mealCategories; return(View(model)); }
public IActionResult AddAMeal(AddMealViewModel addMealViewModel) { if (ModelState.IsValid) { Meal meal = new Meal() { Name = addMealViewModel.Name, Note = addMealViewModel.Note }; meal.Ingredients = new List <Ingredient>(); for (int i = 0; i < addMealViewModel.Ingredients.Count(); i++) { if (!string.IsNullOrEmpty(addMealViewModel.Ingredients[i]) && addMealViewModel.Ingredients[i] != "") { Ingredient ingredient = new Ingredient() { //make it so that each ingredient is added as upper case(all) //and check if already in db Name = addMealViewModel.Ingredients[i], CategoryID = addMealViewModel.CategoryIDs[i] }; meal.Ingredients.Add(ingredient); } } context.Meals.Add(meal); context.SaveChanges(); return(Redirect("/Manage/Index")); } AddMealViewModel newAddMealViewModel = new AddMealViewModel(context.Categories.ToList()); return(View(newAddMealViewModel)); }
public IActionResult AddMeal() { AddMealViewModel addMealViewModel = new AddMealViewModel(context.MealTimes.ToList(), context.FoodAmounts.ToList()); return(View(addMealViewModel)); }
public IActionResult AddAMeal() { AddMealViewModel addMealViewModel = new AddMealViewModel(context.Categories.ToList()); return(View(addMealViewModel)); }
public async Task <IActionResult> Register(RegisterViewModel model, string returnUrl = null) { ViewData["ReturnUrl"] = returnUrl; if (ModelState.IsValid) { var user = new ApplicationUser { UserName = model.Email, Email = model.Email }; var result = await _userManager.CreateAsync(user, model.Password); if (result.Succeeded) { //add default meals to new account var allDefaultMeals = _context.DefaultMeals.ToList(); Meal allNewMeals = new Meal(); foreach (DefaultMeal defaultMeal in allDefaultMeals) { AddMealViewModel meal = new AddMealViewModel( user.Id, defaultMeal.Name, defaultMeal.Description, defaultMeal.WeatherTypeID, defaultMeal.CookingMethodID, defaultMeal.AltCookingMethodID, defaultMeal.CookingTimeID, defaultMeal.PrepTimeID ); Meal newMeal = new Meal { Name = meal.Name, Description = meal.Description, Location = meal.Location, UserID = meal.UserID, WeatherTypeID = meal.WeatherTypeID, CookingMethodID = meal.CookingMethodID, AltCookingMethodID = meal.AltCookingMethodID, CookingTimeID = meal.CookingTimeID, PrepTimeID = meal.PrepTimeID }; _context.Meals.Add(newMeal); // await _context.SaveChangesAsync(); } // _context.SaveChanges(); await _context.SaveChangesAsync(); ///// } // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=532713 // Send an email with this link //var code = await _userManager.GenerateEmailConfirmationTokenAsync(user); //var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: HttpContext.Request.Scheme); //await _emailSender.SendEmailAsync(model.Email, "Confirm your account", // $"Please confirm your account by clicking this link: <a href='{callbackUrl}'>link</a>"); await _signInManager.SignInAsync(user, isPersistent : false); _logger.LogInformation(3, "User created a new account with password."); return(RedirectToLocal(returnUrl)); } AddErrors(result); } // If we got this far, something failed, redisplay form return(View(model)); }