public async Task <List <InitiativeByYearResultDto> > GetAll(string year) { try { List <InitiativeByYearResultDto> list = new List <InitiativeByYearResultDto>(); var allInitiatives = await baseContext.InitiativesByYears .Include(a => a.Initiative) .Where(x => x.InitiativeYearId == year) .ToListAsync(); foreach (var initiative in allInitiatives) { var lead = await baseContext.User.Where(x => x.Id == initiative.LeadId).FirstOrDefaultAsync(); InitiativeByYearResultDto result = new InitiativeByYearResultDto { initiativeByYear = initiative, Lead = lead }; list.Add(result); } return(list); }catch (Exception ex) { logger.LogError(ex, ex.Message); throw ex; } }
public async Task <InitiativeByYearResultDto> GetById(Guid initiativeId) { try { var initiative = await baseContext.InitiativesByYears .Include(a => a.Initiative) .Where(x => x.Id == initiativeId) .FirstOrDefaultAsync(); var lead = await baseContext.User.Where(x => x.Id == initiative.LeadId).FirstOrDefaultAsync(); var initiativeLead = new InitiativeByYearResultDto { initiativeByYear = initiative, Lead = lead }; return(initiativeLead); }catch (Exception ex) { logger.LogError(ex, ex.Message); throw ex; } }