/
EfRentalDal.cs
38 lines (36 loc) · 1.41 KB
/
EfRentalDal.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
using Core.DataAccess.EntityFramework;
using DataAccess.Abstract;
using Entities.Concrete;
using Entities.DTO;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
namespace DataAccess.Concrete.EntityFramework
{
public class EfRentalDal : EfEntityRepositoryBase<Rental, CRSContext>, IRentalDal
{
public List<RentalDetailDto> GetRentalDetails(Expression<Func<Rental, bool>> filter = null)
{
using (CRSContext context = new CRSContext())
{
var result = from r in filter is null ? context.Rentals : context.Rentals.Where(filter)
join c in context.Cars
on r.CarId equals c.Id
join u in context.Users
on r.CustomerId equals u.Id
select new RentalDetailDto
{
Id = r.Id,
CarId = c.Id,
CustomerId = u.Id,
CustomerName = u.FirstName + " " + u.LastName,
RentDate = r.RentDate,
ReturnDate = r.ReturnDate
};
return result.ToList();
}
}
}
}