public IActionResult AddItemList(int userGroupId, [FromBody] ItemListModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var itemList = _mapper.Map <ItemList>(model);

            try
            {
                var group = _userGroupService.GetById(userGroupId);

                _itemListService.Create(itemList);
                group.ItemList = itemList;

                return(Ok(group));
            }
            catch (AppException ex)
            {
                return(BadRequest(new { message = ex }));
            }
        }
Beispiel #2
0
        public IActionResult Create([FromBody] ItemListModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            // map model to entity
            var itemList = _mapper.Map <ItemList>(model);


            try
            {
                // create item
                _itemListService.Create(itemList);
                return(Ok(itemList));
            }
            catch (AppException ex)
            {
                // return error message if there was an exception
                return(BadRequest(new { message = ex.Message }));
            }
        }