public async Task <UpsertBaseBudgetDetailResponse> UpsertBaseBudgetDetailAsync(UpsertBaseBudgetDetailRequest request) { return(await Task.Run(() => { UpsertBaseBudgetDetailResponse _response = new UpsertBaseBudgetDetailResponse(); using (AsyncAutomateAccountingEntities _dbContext = new AsyncAutomateAccountingEntities()) { if (request.BaseObject != null) { try { BudgetDetail _BudgetDetail = request.BaseObject.ToBudgetDetail(); UpsertEntity <BudgetDetail>(request.BaseObject.Id, ref _BudgetDetail, _dbContext); _response.BaseObject = _BudgetDetail.ToBaseBudgetDetail(); } catch (Exception ex) { AssignStatusData(_response, false, string.Format("Some error occurred during DB interaction. Message is something like : \n{0}", ex.Message)); } } else { AssignStatusData(_response, false, "No entity data recieved to insert/update."); } } return _response; })); }
public async Task <GetBaseBudgetDetailsResponse> GetBaseBudgetDetailsAsync(GetBaseBudgetDetailsRequest request) { return(await Task.Run(() => { GetBaseBudgetDetailsResponse _response = new GetBaseBudgetDetailsResponse(); using (AsyncAutomateAccountingEntities _dbContext = new AsyncAutomateAccountingEntities()) { ExpressionStarter <BudgetDetail> _predicateBudgetDetail = PredicateBuilder.New <BudgetDetail>(true); if (request.Id.HasValue) { _predicateBudgetDetail = _predicateBudgetDetail.And(p => p.Id == request.Id); } List <BudgetDetail> _BudgetDetails = _dbContext.BudgetDetails.AsExpandable().Where(_predicateBudgetDetail).ToList(); if (_BudgetDetails.Any()) { _response.BaseObjects = _BudgetDetails.ToBaseBudgetDetail(); } } return _response; })); }
public async Task <GetBaseLedgerPostingsResponse> GetBaseLedgerPostingsAsync(GetBaseLedgerPostingsRequest request) { return(await Task.Run(() => { GetBaseLedgerPostingsResponse _response = new GetBaseLedgerPostingsResponse(); using (AsyncAutomateAccountingEntities _dbContext = new AsyncAutomateAccountingEntities()) { ExpressionStarter <LedgerPosting> _predicateLedgerPosting = PredicateBuilder.New <LedgerPosting>(true); if (request.Id.HasValue) { _predicateLedgerPosting = _predicateLedgerPosting.And(p => p.Id == request.Id); } List <LedgerPosting> _ledgerPostings = _dbContext.LedgerPostings.AsExpandable().Where(_predicateLedgerPosting).ToList(); if (_ledgerPostings.Any()) { _response.BaseObjects = _ledgerPostings.ToBaseLedgerPostings(); } } return _response; })); }
public async Task <GetBaseFieldsResponse> GetBaseFieldsAsync(GetBaseFieldsRequest request) { return(await Task.Run(() => { GetBaseFieldsResponse _response = new GetBaseFieldsResponse(); using (AsyncAutomateAccountingEntities _dbContext = new AsyncAutomateAccountingEntities()) { ExpressionStarter <Field> _predicateField = PredicateBuilder.New <Field>(true); if (request.Id.HasValue) { _predicateField = _predicateField.And(p => p.Id == request.Id); } List <Field> _Fields = _dbContext.Fields.AsExpandable().Where(_predicateField).ToList(); if (_Fields.Any()) { _response.BaseObjects = _Fields.ToBaseField(); } } return _response; })); }
public async Task <GetBaseSuffixPrifixesResponse> GetBaseSuffixPrifixesAsync(GetBaseSuffixPrifixesRequest request) { return(await Task.Run(() => { GetBaseSuffixPrifixesResponse _response = new GetBaseSuffixPrifixesResponse(); using (AsyncAutomateAccountingEntities _dbContext = new AsyncAutomateAccountingEntities()) { ExpressionStarter <SuffixPrefix> _predicateSuffixPrifix = PredicateBuilder.New <SuffixPrefix>(true); if (request.Id.HasValue) { _predicateSuffixPrifix = _predicateSuffixPrifix.And(p => p.Id == request.Id); } List <SuffixPrefix> _SuffixPrifixes = _dbContext.SuffixPrefixes.AsExpandable().Where(_predicateSuffixPrifix).ToList(); if (_SuffixPrifixes.Any()) { _response.BaseObjects = _SuffixPrifixes.ToBaseSuffixPrifix(); } } return _response; })); }
public void UpsertEntity <Tentity>(int?identityValue, ref Tentity entityObject, AsyncAutomateAccountingEntities dbContext) where Tentity : class { if (identityValue.HasValue) { dbContext.Entry(entityObject).State = System.Data.Entity.EntityState.Modified; } else { dbContext.Set <Tentity>().Add(entityObject); } dbContext.SaveChanges(); }