Last post Oct 25, 2019 01:23 PM by polachan
Member
414 Points
1341 Posts
Oct 25, 2019 09:20 AM|polachan|LINK
I want to get the employee name between two dates using my data repository class
[HttpPost] public IActionResult LeaversOverviewCriteria(string FromDate = "", string ToDate = "") { if (HttpContext.Session.GetInt32("UserID") != null) { DateTime dtfrom = new DateTime(); DateTime dtto = new DateTime(); dtfrom = DateTime.ParseExact(FromDate, "dd/MM/yyyy", CultureInfo.InvariantCulture); dtto = DateTime.ParseExact(FromDate, "dd/MM/yyyy", CultureInfo.InvariantCulture); var EmpList = _iRepo.GetAll().Where(u => u.LeaveDate >= dtfrom && u.LeaveDate <= dtto)ToList();; // How can I filter the list using where condition } else { return RedirectToAction("SessionExpiry", "Employee"); } return View(); } Service class public IEnumerable<EmployeeModel> GetAll() { var employees = ctx.goEmployee.ToList(); return employees; } My Repository Interface public interface IDataRepository<TEntity, U> where TEntity : class { IEnumerable<TEntity> GetAll(); TEntity Get(U id); long Add(TEntity b); long Update(U id, TEntity b); long Delete(U id); } Repository Employee Controll class public EmployeeController(IDataRepository<EmployeeModel, long> repo) { _iRepo = repo; } [HttpGet] public IEnumerable<EmployeeModel> Get() { return _iRepo.GetAll(); }Model ClassEmployeeModel.cs [Key] public int EmployeeID { get; set; } public string EmployeeName { get; set; } public DateTime? LeaveDate { get; set; }
Please can you help me how to filter list of employee who are the leave date between DateFrom and DateTo. How can I filter the list from
var EmpList = _iRepo.GetAll()
With Thanks
Pol
Oct 25, 2019 01:23 PM|polachan|LINK
Sorry
I corrected this error that was datatype error
var EmpList = _iRepo.GetAll().Where(u => u.LeaveDate >= dtfrom && u.LeaveDate <= dtto)ToList();
Member
414 Points
1341 Posts
Where condition is not working to list the record between two records in data repository . Pleas...
Oct 25, 2019 09:20 AM|polachan|LINK
I want to get the employee name between two dates using my data repository class
Please can you help me how to filter list of employee who are the leave date between DateFrom and DateTo. How can I filter the list from
var EmpList = _iRepo.GetAll()
With Thanks
Pol
Member
414 Points
1341 Posts
Re: Where condition is not working to list the record between two records in data repository . P...
Oct 25, 2019 01:23 PM|polachan|LINK
Sorry
I corrected this error that was datatype error