-
Notifications
You must be signed in to change notification settings - Fork 0
/
EfRentalsDal.cs
37 lines (36 loc) · 1.48 KB
/
EfRentalsDal.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
using Core.DataAccess.EntityFramework;
using DataAccess.Abstract;
using Entities.Concrete;
using Entities.DTOs;
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using System.Linq.Expressions;
namespace DataAccess.Concrete.EntityFramework
{
public class EfRentalsDal : EfEntityRepositoryBase<Rentals, CarDbContext>, IRentalsDal
{
public List<RentDetailDto> GetRentDetailDtos(Expression<Func<Rentals, bool>> filter = null)
{
using (CarDbContext context = new CarDbContext())
{
var result = from r in filter is null ? context.Rentals : context.Rentals.Where(filter)
join c in context.Car on r.CarId equals c.Id
join cu in context.Customers on r.CustomerId equals cu.Id
join u in context.Users on cu.UserId equals u.Id
select new RentDetailDto
{
RentId = r.Id,
CarName = c.DescriptionCar,
CustomerName = u.FirstName,
CustomerSurname = u.LastName,
CompanyName = cu.CompanyName,
RentDate = r.RentDate,
ReturnDate = (DateTime)r.ReturnDate
};
return result.ToList();
}
}
}
}