public virtual async Task <IList <T> > ExecuteQuery(IQueryable <T> query, IBaseQueryOptions options) { if (query == null || options == null) { return(null); } // options.UserId is added in the controller for current user query = query.Where(r => r.UserId == options.UserId); if (options.MarkedForDeletion != null) { query = query.Where(r => r.MarkedForDeletion == options.MarkedForDeletion); } if (options.Skip > 0) { query = query.Skip(options.Skip); } if (options.Limit > 0) { query = query.Take(options.Limit); } return(await query.ToListAsync()); }
public virtual async Task <T> GetById(int id, IBaseQueryOptions options) { //var item = await _dbContext.FindAsync(id); // Override if you need to include related objects var query = _dbContext.AsQueryable(); return(await ExecuteQueryById(id, query, options)); }
public override async Task <Register> GetById(int id, IBaseQueryOptions options = null) { if (options != null && options.IncludeRelated) { var query = _db.Registers.AsQueryable() .Include(e => e.RegisterEntries); return(await base.ExecuteQueryById(id, query, options)); } return(await base.GetById(id, options)); }
public override async Task <BudgetCategory> GetById(int id, IBaseQueryOptions options = null) { if (options != null && options.IncludeRelated) { var query = _db.BudgetCategories.AsQueryable() .Include(t => t.BudgetGroup) .Include(i => i.BudgetItems); return(await base.ExecuteQueryById(id, query, options)); } return(await base.GetById(id, options)); }
public override async Task <BudgetCycleItem> GetById(int id, IBaseQueryOptions options = null) { if (options != null && options.IncludeRelated) { var query = _db.BudgetCyclesItems.AsQueryable() .Include(c => c.BudgetCycle) .Include(i => i.BudgetItem); return(await base.ExecuteQueryById(id, query, options)); } return(await base.GetById(id, options)); }
public override async Task <MemorizedTransaction> GetById(int id, IBaseQueryOptions options = null) { if (options != null && options.IncludeRelated) { var query = _db.MemorizedTransactions.AsQueryable() .Include(i => i.BudgetItem); return(await base.ExecuteQueryById(id, query, options)); } return(await base.GetById(id, options)); }
public virtual async Task <T> ExecuteQueryById(int id, IQueryable <T> query, IBaseQueryOptions options) { if (query == null || options == null) { return(null); } // options.UserId is added in the controller for current user query = query.Where(r => r.UserId == options.UserId); return(await query.FirstOrDefaultAsync(q => q.Id == id)); }
public override async Task <RegisterSplitEntry> GetById(int id, IBaseQueryOptions options = null) { if (options != null && options.IncludeRelated) { var query = _db.RegisterSplitEntries.AsQueryable() .Include(r => r.RegisterEntry) .Include(i => i.BudgetItem); return(await base.ExecuteQueryById(id, query, options)); } return(await base.GetById(id, options)); }
/// <summary> /// Get Item by Id /// </summary> /// <typeparam name="D">Data Transfer Object class</typeparam> /// <param name="controller"></param> /// <param name="repo"></param> /// <param name="id"></param> /// <param name="options"></param> /// <returns></returns> public async Task <IActionResult> GetItem <D>(ControllerBase controller, IDbResourceRepository <T, O> repo, int id, IBaseQueryOptions options) { try { string desc = GetControllerDescription(controller); _logger.LogInfo($"{desc}: {id}"); // set options.UserId for the current authenticated user var user = await _userService.GetCurrentUser(); if (user == null) { _logger.LogWarn($"{desc}: Invalid request submitted - Not a valid user"); return(controller.BadRequest()); } options.UserId = user?.Id; var item = await repo.GetById(id, options); if (item == null) { _logger.LogWarn($"{desc}: Item {id} was not found or does not belong to {user?.Email} "); return(controller.NotFound()); } var response = _mapper.Map <D>(item); _logger.LogInfo($"{desc} - Successful"); return(controller.Ok(response)); } catch (Exception e) { return(InternalError(controller, $"Server Error: {e.Message} - {e.InnerException}")); } }