Пример #1
0
        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"));
            }
        }
Пример #2
0
        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"));
        }
Пример #3
0
 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));
 }
Пример #4
0
        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));
        }
Пример #5
0
 public async Task <IActionResult> AddMeal(Meal meal)
 {
     return(Ok(await _mealService.AddMeal(meal)));
 }
Пример #6
0
 public IActionResult AddMeal(NewMealVm model)
 {
     _mealService.AddMeal(model);
     return(View(model));
 }