public async Task <int> Add(AccountToSaveDto entity) { if (await GetMainAccountId(entity.ClientId) > 0) { throw new Exception("This client already has main account."); } Account entityToSave = _mapper.Map <Account>(entity); AccountType accountType = await _unitOfWork.AccountType.Get(entity.AccountTypeId); if (accountType == null) { throw new Exception("Invalid Account Type."); } entityToSave.AccountNo = GenerateAccountNo(accountType.ShortName); entityToSave.CreatedBy = CurrentUser.User.Id; entityToSave.CreatedDate = DateTime.Now; entityToSave.IsActive = true; entityToSave.IsVisible = true; _unitOfWork.Account.Add(entityToSave); _unitOfWork.Complete(); return(entityToSave.Id); }
public async Task <int> Add(AccountToSaveDto entity) { if (await _unitOfWork.Account.Exists(x => x.AccountNo == entity.AccountNo)) { throw new Exception("Already exists."); } Account entityToSave = _mapper.Map <Account>(entity); _unitOfWork.Account.Add(entityToSave); _unitOfWork.Complete(); return(entityToSave.Id); }
public async Task <IActionResult> Post(AccountToSaveDto AccountDto) { try { if (await _serviceManager.Account.Add(AccountDto)) { return(StatusCode(201)); } else { return(BadRequest()); } } catch (System.Exception e) { return(HandleException(e)); } }
public async Task <IActionResult> Post(AccountToSaveDto accountToSaveDto) { try { if (!ModelState.IsValid) { GetModalStateMessage(); } var accountId = await _serviceManager.Account.Add(accountToSaveDto); return(Ok(accountId)); } catch (System.Exception ex) { return(HandleException(ex)); } }
public async Task <bool> Add(AccountToSaveDto entity) { if (await _unitOfWork.Account.AccountExists(entity.AccountNo)) { throw new Exception("Already exists."); } Account entityToSave = _mapper.Map <Account>(entity); _unitOfWork.Account.Add(entityToSave); if (_unitOfWork.Complete() > 0) { return(true); } return(false); }