Exemple #1
0
 public List <Customer> GetGoldAndSilverCustomers(int count)
 {
     using (var db = new RentCDataContext())
     {
         var gsCustomers = from c in db.Customers
                           where c.Reservations.Count >= count
                           select c;
         return(gsCustomers.ToList());
     }
 }
        IEnumerable <ValidationResult> IValidatableObject.Validate(ValidationContext validationContext)
        {
            List <ValidationResult> errormsg = new List <ValidationResult>();

            if (EndDate < StartDate)
            {
                errormsg.Add(new ValidationResult("EndDate must be greater than StartDate", new[] { "EndDate" }));
            }

            using (var db = new RentCDataContext())
            {
                if (!db.Customers.Any(c => c.CostumerID == CostumerID))
                {
                    errormsg.Add(new ValidationResult("Client isn't in the database", new[] { "EndDate" }));
                }
            }

            return(errormsg);
        }
 public IEnumerable <SelectListItem> GetCars(int id)
 {
     if (id > 0)
     {
         using (var context = new RentCDataContext())
         {
             IEnumerable <SelectListItem> cars = context.Cars.AsNoTracking()
                                                 .Where(c => c.LocationID == id)
                                                 .Select(n =>
                                                         new SelectListItem
             {
                 Value = n.CarID.ToString(),
                 Text  = n.Plate
             }).ToList();
             return(new SelectList(cars, "Value", "Text"));
         }
     }
     return(null);
 }
Exemple #4
0
        public (Car, Car) GetMostAndLeastRentedCar()
        {
            using (var db = new RentCDataContext())
            {
                var cars = from c in db.Cars
                           orderby c.Reservations.Count
                           select c;
                Car leastRentedCar = cars.First();
                //  Car mostRentedCar = cars.LastOrDefault();

                var carsDescending = from c in db.Cars
                                     orderby c.Reservations.Count descending
                                     select c;

                Car mostRentedCar = cars.First();

                return(mostRentedCar, leastRentedCar);
            }
        }
 public IEnumerable <SelectListItem> GetLocations()
 {
     using (var context = new RentCDataContext())
     {
         List <SelectListItem> locations = context.Locations.AsNoTracking()
                                           .OrderBy(l => l.Name)
                                           .Select(l =>
                                                   new SelectListItem
         {
             Value = l.LocationID.ToString(),
             Text  = l.Name
         }).ToList();
         var locationtip = new SelectListItem()
         {
             Value = null,
             Text  = "--- select location ---"
         };
         locations.Insert(0, locationtip);
         return(new SelectList(locations, "Value", "Text"));
     }
 }
 public SQLRepository(RentCDataContext context)
 {
     this.context = context;
     this.dbSet   = context.Set <T>();
 }