public async Task <ActionResult <AngajatiDetails> > GetAngajat(long id) { var angajat = await _context .Angajati // .Include(a => a.Santier ) .FirstOrDefaultAsync(a => a.Id_Angajat == id); if (angajat == null) { return(NotFound()); } return(AngajatiDetails.FromAngajat(angajat)); /* * var angajat = await _context.Angajati.FindAsync(id); * * if (angajat == null) * { * return NotFound(); * } * * return angajat; */ }
public async Task <ActionResult <IEnumerable <AngajatiDetails> > > GetAngajati( [FromQuery] DateTimeOffset?from = null, [FromQuery] DateTimeOffset?to = null) { //filter by date from - date to IQueryable <Angajat> result = _context.Angajati; if (from != null && to != null) { result = result.Where(c => from <= c.Data && c.Data <= to); } else if (from == null && to != null) { result = result.Where(c => c.Data <= to); } else if (from != null && to == null) { result = result.Where(c => c.Data >= from); } var resultList = await result // .Include(f => f.Santier) .Select(f => AngajatiDetails.FromAngajat(f)) .ToListAsync(); return(resultList); // return await _context.Angajati.ToListAsync(); }