示例#1
0
        public int AddMeal(NewMealVm mealVm)
        {
            var meal = _mapper.Map <Meal>(mealVm);
            var id   = _mealRepo.AddMeal(meal);

            return(id);
        }
        public void AddMeal(MealDTO mealDTO)
        {
            var meal = _mealMapper.GetMealFromMealDTO(mealDTO);

            _mealRepository.AddMeal(meal);

            mealDTO.Id = meal.MealId;
        }
示例#3
0
 public async Task <ActionResult <MealModel> > AddProduct(MealModelDto dto)
 {
     if (await MealExists(dto.Name))
     {
         return(BadRequest("Meal already exists."));
     }
     return(await repo.AddMeal(dto));
 }
示例#4
0
 public ActionResult Create(Meal meal)
 {
     try
     {
         repository.AddMeal(meal);
         return(RedirectToAction("Index"));
     }
     catch
     {
         return(View());
     }
 }
示例#5
0
        public IActionResult Create(MealInputModel model)
        {
            if (ModelState.IsValid)
            {
                var meal = Meal.New(model.Type);

                _mealRepository.AddMeal(meal);

                return(RedirectToAction(nameof(Index)));
            }

            return(View());
        }
示例#6
0
        public int AddMeal(LoginModel loggedInUser, MealRequest request)
        {
            ValidateObject(request, false);
            CheckPermission(loggedInUser, request.UserId, "You can't add other's meal.");

            var model = new MealModel()
            {
                Date        = request.Date,
                Description = request.Description,
                Calories    = request.Calories,
            };

            return(_mealRepository.AddMeal(request.UserId, model));
        }
示例#7
0
        public ActionResult AddMeal(MealDTO md)
        {
            Meal m = new Meal()
            {
                Id             = Guid.NewGuid(),
                Name           = md.Name,
                Amount         = md.Amount,
                Price          = md.Price,
                MealCategoryId = md.MealCategoryId,
            };

            if (_mealRepository.AddMeal(m))
            {
                return(Ok("A new meal was added successfully!"));
            }
            return(BadRequest("Oops, something went wrong with adding new meal!"));
        }
示例#8
0
        async public Task <Dictionary <ServiceDictionaryKey, object> > TryAddMeal(int patientId, HttpRequest request)
        {
            Dictionary <ServiceDictionaryKey, object> dictionary = new Dictionary <ServiceDictionaryKey, object>();

            try
            {
                string requestBody = await new StreamReader(request.Body).ReadToEndAsync();

                Meal meal = new Meal();
                JsonConvert.PopulateObject(requestBody, meal);
                meal.PatientId = patientId;
                meal           = await _mealRepository.AddMeal(meal);

                dynamic data = _messageSerializer.Serialize(meal);

                dictionary.Add(ServiceDictionaryKey.VALUE, data);
            }

            catch (Exception ex)
            {
                dictionary.AddErrorMessage(ServiceDictionaryKey.ERROR, ex, FeedbackHandler);
            }
            return(dictionary);
        }
示例#9
0
 public IActionResult AdminInputForMeals(AddMealRequestByAdmin data)
 {
     return(Ok(repository.AddMeal(data)));
 }