public async Task <MealDto> UpdateMeal(int mealId, MealDto meal) { var myMeal = await _mealRepository.GetMeal(mealId); if (myMeal == null) { _logger.LogInformation("Error while changing a meal"); throw new MealNotFoundException(); } var result = await _mealRepository.UpdateMeal(meal); return(result); }
public Meal GetMeal(string userId, int mealId) { DataTable mealTable = _mealRepository.GetMeal(mealId); DataTable ingredientsTable = _ingredientRepository.GetIngredients(userId, mealId); return(_mealMapper.HydrateMeal(mealTable, ingredientsTable).FirstOrDefault()); }
public void CopyRecipe(int id) { var model = _mealRepository.GetMeal(id); var newMeal = new Meal() { Name = model.Name, MealType = model.MealType, Who = model.Who == Who.Cathal ? Who.Yasmin : Who.Cathal }; int newid = _mealRepository.Add(newMeal); foreach (var item in model.MealIngredients) { //copy ingredient with meaure = null int newIngredientId = CopyIngredient(item.IngredientId); var newIngredient = new MealIngredient() { IngredientId = newIngredientId, MealId = newid }; _mealIngredientRepository.Add(newIngredient); } }
public ViewModels.MealForListVm GetMeal(int mealId) { var meal = _mealRepo.GetMeal(mealId); var mealVm = _mapper.Map <ViewModels.MealForListVm>(meal); mealVm.Items = new List <ItemInMealDetailVm>(); var itemsInMeal = _itemInMealService.GetAllItemsInMeal(mealVm.Id); foreach (var e in itemsInMeal) { var item = _itemService.GetItemById(e.ItemId); var itemInMealDetailVm = CreateItemInMealDetailVm(item, itemsInMeal); mealVm.Items.Add(itemInMealDetailVm); } return(mealVm); }
public MealModel GetMeal(LoginModel loggedInUser, int userId, int mealId) { CheckPermission(loggedInUser, userId, "You can't get other's meal."); var meal = _mealRepository.GetMeal(userId, mealId); if (meal == null) { throw new NoContentException("Meal does not exists."); } return(meal); }
public IActionResult Index(int id) { var model = _mealingredientRepository.GetIngredientsForMeal(id); var newModel = new List <MealIngredientViewModel>(); foreach (var item in model) { var temp = new MealIngredientViewModel(); temp.Id = item.Ingredient.Id; temp.ItemName = item.Ingredient.Item.Name; temp.Measure = item.Ingredient.Measure; temp.Unit = item.Ingredient.Item.Unit; temp.MealId = id; newModel.Add(temp); } var meal = _mealRepository.GetMeal(id); ViewBag.MealName = meal.Name; ViewBag.MealId = meal.Id; return(View(newModel)); }
public IActionResult Show(int mealId) { // Get student from logged in user Student student = studentRepository.GetStudent(GetUserId()); ViewBag.UserIsLoggedIn = student != null; // Render view with meal transformed into meal date return(View(MealTransformer.TransformIntoMealDate(mealRepository.GetMeal(mealId), student))); }
public async Task <ScheduledMealDto> ScheduleMeal(int userId, int mealId, DateTime date) { var user = await _userRepository.GetUser(userId); if (user == null) { _logger.LogInformation("Error while scheduling a meal"); throw new UserNotFoundException(); } var meal = await _mealRepository.GetMeal(mealId); if (meal == null) { _logger.LogInformation("Error while scheduling a meal"); throw new MealNotFoundException(); } var result = await _scheduledMealRepository.CreateScheduledMeal(userId, mealId, date); return(result); }
public Meal GetMealById(int id) { return(_repository.GetMeal(id)); }
public IActionResult Edit(int id) { var model = _mealRepository.GetMeal(id); return(View(model)); }
public InfoScreenQuery( ILunchplanRepository lunchplans, IMealRepository meals, IMessageRepository messages, IAdminRepository admins ) { Name = "Query"; FieldAsync <AdminType>( "admin", arguments: new QueryArguments( new QueryArgument <IntGraphType> { Name = "id" }, new QueryArgument <StringGraphType> { Name = "username" } ), resolve: async ctx => { if (ctx.HasArgument("id")) { return(await admins.GetAdmin(ctx.GetArgument <int>("id"))); } if (ctx.HasArgument("username")) { return(await admins.FindByUsername(ctx.GetArgument <string>("username"))); } return(null); } ); FieldAsync <LunchplanType>( "lunchplan", arguments: new QueryArguments( new QueryArgument <IntGraphType> { Name = "week" } ), resolve: async ctx => { if (ctx.HasArgument("week")) { return(await lunchplans.GetLunchplan(ctx.GetArgument <int>("week"))); } return(null); } ); FieldAsync <MealType>( "meal", arguments: new QueryArguments( new QueryArgument <IntGraphType> { Name = "id" } ), resolve: async ctx => { if (ctx.HasArgument("id")) { return(await meals.GetMeal(ctx.GetArgument <int>("id"))); } return(null); } ); FieldAsync <ListGraphType <MealType> >( "meals", resolve: async ctx => await meals.ListMeals() ); FieldAsync <MessageType>( "message", arguments: new QueryArguments( new QueryArgument <IntGraphType> { Name = "id" } ), resolve: async ctx => { if (ctx.HasArgument("id")) { return(await messages.GetMessage(ctx.GetArgument <int>("id"))); } return(null); } ); FieldAsync <ListGraphType <MessageType> >( "messages", resolve: async ctx => await messages.ListMessages() ); FieldAsync <MessageType>( "newestMessage", resolve: async ctx => await messages.GetNewestMessage() ); }
public ActionResult Details(int id) { MealDetailView view = new MealDetailView(repository.GetMeal(id), repository.GetStudentsMeal(id)); return(View(view)); }