Example #1
0
        public IHttpActionResult AddList([FromBody] FoodListViewModel viewModel)
        {
            try
            {
                if (viewModel == null)
                {
                    return(BadRequest());
                }

                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

                FoodList item = Mapper.Map <FoodList>(viewModel);
                item.UserId = CurrentUserId;
                _foodListRepository.Add(item);
                int save = _foodListRepository.Save();

                if (save > 0)
                {
                    return(CreatedAtRoute("GetSingleList", new { id = item.Id }, item));
                }

                return(BadRequest());
            }
            catch (Exception exception)
            {
                return(InternalServerError(exception));
            }
        }
Example #2
0
        public IActionResult AddList([FromBody] FoodListDto viewModel)
        {
            if (viewModel == null)
            {
                return(BadRequest());
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            FoodList item = Mapper.Map <FoodList>(viewModel);

            item.UserId = _userManager.GetUserId(HttpContext.User);
            _foodListRepository.Add(item);

            if (_foodListRepository.Save())
            {
                return(CreatedAtRoute("GetSingleList", new { id = item.Id }, item));
            }

            return(BadRequest());
        }
Example #3
0
 public FoodList Add(FoodList foodList)
 {
     return(_foodListRepository.Add(foodList));
 }