Пример #1
0
        public List <Model.Rent> CheckAvailability(RentSearchRequest search)
        {
            var rents = _context.Rents.Where(w => w.VehicleId == search.VehicleId).
                        Where(w => w.StartDate.Date <= search.StartDate.Value.Date && w.EndDate.Date >= search.StartDate.Value.Date || w.EndDate.Date <= search.EndDate.Value.Date && w.EndDate.Date >= search.EndDate.Value.Date).ToList();

            if (rents.Count > 0)
            {
                return(_mapper.Map <List <Model.Rent> >(rents));
            }
            else
            {
                return(null);
            }
        }
Пример #2
0
        public List <Model.Rent> Get(RentSearchRequest search)
        {
            var query = _context.Rents.Include(i => i.User).Include(i => i.Vehicle).AsQueryable();

            if (search.StartDate != null && search.EndDate != null)
            {
                var sd = search.StartDate.Value.Date;
                var ed = search.EndDate.Value.Date;

                query = query.Where(e => e.StartDate.Date >= sd && e.EndDate.Date <= ed);
            }

            if (!string.IsNullOrWhiteSpace(search.UserName))
            {
                query = query.Where(w => w.User.FirstName == search.UserName);
            }

            if (!string.IsNullOrWhiteSpace(search.UserLastName))
            {
                query = query.Where(w => w.User.LastName == search.UserLastName);
            }

            if (search.UserId != 0)
            {
                query = query.Where(w => w.UserId == search.UserId);
            }

            if (!string.IsNullOrWhiteSpace(search.VehicleName))
            {
                query = query.Where(w => w.Vehicle.Name == search.VehicleName);
            }

            if (search.VehicleId != 0)
            {
                query = query.Where(w => w.Vehicle.Id == search.VehicleId);
            }

            if (search.RentId > 0)
            {
                query = query.Where(w => w.Id == search.RentId);
            }
            query = query.OrderBy(x => x.StartDate);



            return(_mapper.Map <List <Model.Rent> >(query.ToList()));
        }
Пример #3
0
        public ActionResult <List <Model.Rent> > CheckAvailability([FromQuery] RentSearchRequest request)
        {
            var rent = _service.CheckAvailability(request);

            return(rent);
        }
Пример #4
0
        public ActionResult <List <Model.Rent> > Get([FromQuery] RentSearchRequest request)
        {
            var rent = _service.Get(request);

            return(rent);
        }