示例#1
0
        public async Task <int> Add(RoleToSaveDto entity)
        {
            if (await _unitOfWork.Role.Exists(x => x.Description == entity.Description))
            {
                throw new Exception("Already exists.");
            }

            Role role = _mapper.Map <Role>(entity);

            _unitOfWork.Role.Add(role);

            _unitOfWork.Complete();

            return(role.Id);
        }
 public async Task <IActionResult> Post(RoleToSaveDto roleDto)
 {
     try
     {
         if (await _serviceManager.Role.Add(roleDto))
         {
             return(StatusCode(201));
         }
         else
         {
             return(BadRequest());
         }
     }
     catch (System.Exception e)
     {
         return(HandleException(e));
     }
 }
示例#3
0
        public async Task <bool> Add(RoleToSaveDto entity)
        {
            if (await _unitOfWork.Role.RoleExists(entity.Description))
            {
                throw new Exception("Already exists.");
            }

            Role role = _mapper.Map <Role>(entity);

            _unitOfWork.Role.Add(role);

            if (_unitOfWork.Complete() > 0)
            {
                return(true);
            }

            return(false);
        }
        public async Task <IActionResult> Post(RoleToSaveDto roleDto)
        {
            try
            {
                var id = await _serviceManager.Role.Add(roleDto);

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

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