public IActionResult AddMeal([FromBody] MealCreateRequestDTO mealRequest) { if (mealRequest == null) { return(BadRequest("Request is null!")); } if (!ModelState.IsValid) { return(BadRequest("Data validation errors!")); } try { var meal = new Meal { Name = mealRequest.Name, Description = mealRequest.Description, Price = mealRequest.Price, GeneralPriority = mealRequest.GeneralPriority, LocalPriority = mealRequest.LocalPriority, ImageUrl = mealRequest.ImageUrl, MealCategoryId = mealRequest.MealCategoryId, RestaurantId = mealRequest.RestaurantId, MealTypeId = mealRequest.MealTypeId }; mealService.AddMeal(meal); return(Ok("Meal added!")); } catch (Exception ex) { return(BadRequest("An error occured while saving meal")); } }
public IActionResult Create(int?id, MealDTO meal) { var result = new MealDTO { Id = meal.Id, Name = meal.Name, Price = meal.Price }; mealService.AddMeal(meal); return(RedirectToAction("GetAll", "Meal")); }
public MealModel Post([FromBody] MealRequest request) { if (request.MealId > 0) { _mealService.EditMeal(_loggedInUser, request); } else { request.MealId = _mealService.AddMeal(_loggedInUser, request); } return(_mealService.GetMeal(_loggedInUser, request.UserId, request.MealId)); }
public async Task <IActionResult> Edit(byte id, Meal newMeal) { if (ModelState.IsValid) { await mealService.AddMeal(id, User, newMeal); return(RedirectToAction(nameof(MealController.Edit), "Meal")); } var dailyMealViewModel = await mealService.BuildDailyMealViewModel(id, User, newMeal); return(View(dailyMealViewModel)); }
public async Task <IActionResult> AddMeal(Meal meal) { return(Ok(await _mealService.AddMeal(meal))); }
public IActionResult AddMeal(NewMealVm model) { _mealService.AddMeal(model); return(View(model)); }