Exemple #1
0
        public async Task <int> Add(MenuToSaveDto entity)
        {
            if (await _unitOfWork.Menu.Exists(x => x.Title == entity.Title))
            {
                throw new Exception("Already exists.");
            }

            Menu menu = _mapper.Map <Menu>(entity);

            _unitOfWork.Menu.Add(menu);

            _unitOfWork.Complete();

            return(menu.Id);
        }
        public async Task <IActionResult> Post(MenuToSaveDto menuToSaveDto)
        {
            try
            {
                var id = await _serviceManager.Menu.Add(menuToSaveDto);

                if (id > 0)
                {
                    var role = await _serviceManager.Menu.Get(id);

                    return(Ok(role));
                }
                return(BadRequest());
            }
            catch (System.Exception e)
            {
                return(HandleException(e));
            }
        }