public async Task <int> Add(GroupToSaveDto entity) { if (await _unitOfWork.Group.Exists(x => x.Description == entity.Description)) { throw new Exception("Already exists."); } Group group = _mapper.Map <Group>(entity); _unitOfWork.Group.Add(group); _unitOfWork.Complete(); return(group.Id); }
public async Task <IActionResult> Post(GroupToSaveDto GroupDto) { try { if (await _serviceManager.Group.Add(GroupDto)) { return(StatusCode(201)); } else { return(BadRequest()); } } catch (System.Exception e) { return(HandleException(e)); } }
public async Task <bool> Add(GroupToSaveDto entity) { if (await _unitOfWork.Group.GroupExists(entity.Description)) { throw new Exception("Already exists."); } Group group = _mapper.Map <Group>(entity); _unitOfWork.Group.Add(group); if (_unitOfWork.Complete() > 0) { return(true); } return(false); }