Home > Blockchain >  ASP.NET Core Web API - How to get all employees that will end their leave in 3 days time from the cu
ASP.NET Core Web API - How to get all employees that will end their leave in 3 days time from the cu

Time:10-26

In ASP.NET Core-6 Web API Entity Framework, I have employee Leave Model as shown below:

public class Employee
{
    public Guid Id { get; set; }
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public string Email { get; set; }

}

public class LeaveApplication
{
    public Guid Id { get; set; }
    public Guid EmployeeId { get; set; }
    public DateTime StartDate { get; set; }
    public DateTime EndDate { get; set; }
    public PaymentStatus PaymentStatus { get; set; }   
    public bool? IsApproved { get; set; }
    public virtual Emmployee Employee { get; set; }
}

I want to get the list of employees whose Leave will end in the next 3 days, using EndDate and where IsApproved is true.

Note: I am using Entity Framework

How do I achieve this?

Thanks

CodePudding user response:

I think you can use a query like below :


var next3Day = DateTime.Now.Date.AddDays(4);
var employees = context.LeaveApplications
              .Where(r=> r.IsApproved == true && r.EndDate > DateTime.Now && r.EndDate < next3Day).Select(r=> r.Emmployee )
              .ToArrayAsync();
  • Related