Пример #1
0
        public static void editServiceEvent(ServiceEvent serviceEvent)
        {
            BasicVehicleDbContext db = new BasicVehicleDbContext();

            db.Entry(serviceEvent).State = EntityState.Modified;
            db.SaveChanges();
        }
Пример #2
0
        public static void editVehicle(Vehicle vehicle)
        {
            BasicVehicleDbContext db = new BasicVehicleDbContext();

            db.Entry(vehicle).State = EntityState.Modified;
            db.SaveChanges();
        }
Пример #3
0
        public static void createServiceEvent(ServiceEvent serviceEvent)
        {
            BasicVehicleDbContext db = new BasicVehicleDbContext();

            db.Entry(serviceEvent).State = EntityState.Added;
            db.ServiceEvents.Add(serviceEvent);
            db.SaveChanges();
        }
Пример #4
0
        public static void deleteServiceEvent(ServiceEvent serviceEvent)
        {
            BasicVehicleDbContext db = new BasicVehicleDbContext();

            db.Entry(serviceEvent).State = EntityState.Deleted;
            db.ServiceEvents.Remove(serviceEvent);
            db.SaveChanges();
        }
Пример #5
0
        public static void createVehicle(Vehicle vehicle)
        {
            BasicVehicleDbContext db = new BasicVehicleDbContext();

            db.Entry(vehicle).State = EntityState.Added;
            db.Vehicles.Add(vehicle);
            db.SaveChanges();
        }
Пример #6
0
        public static void deleteVehicle(Vehicle vehicle)
        {
            BasicVehicleDbContext db = new BasicVehicleDbContext();

            db.Entry(vehicle).State = EntityState.Deleted;
            db.Vehicles.Remove(vehicle);
            db.SaveChanges();
        }
Пример #7
0
        public static VehicleServiceEvent getVehicleAndServiceEvents(int?id)
        {
            BasicVehicleDbContext db = new BasicVehicleDbContext();
            VehicleServiceEvent   vehServiceEvents = new VehicleServiceEvent();

            vehServiceEvents.vehicle = getVehicle(id);

            var serviceEvents = db.ServiceEvents.Where(s => s.Vin == vehServiceEvents.vehicle.Vin);

            vehServiceEvents.serviceEvents = serviceEvents.ToList();

            return(vehServiceEvents);
        }
Пример #8
0
        public static ServiceEvent getServiceEvent(int?id)
        {
            BasicVehicleDbContext db = new BasicVehicleDbContext();

            return(db.ServiceEvents.Find(id));
        }
Пример #9
0
        public static List <ServiceEvent> getServiceEvents()
        {
            BasicVehicleDbContext db = new BasicVehicleDbContext();

            return(db.ServiceEvents.ToList());
        }
Пример #10
0
        public static Vehicle getVehicle(int?id)
        {
            BasicVehicleDbContext db = new BasicVehicleDbContext();

            return(db.Vehicles.Find(id));
        }
Пример #11
0
        public static List <Vehicle> getVehicles()
        {
            BasicVehicleDbContext db = new BasicVehicleDbContext();

            return(db.Vehicles.ToList());
        }
Пример #12
0
        public IEnumerable <Vehicle> GetData(out int totalRecords, string globalSearch, string filterFirstName, string filterLastName, bool?filterActive, int?limitOffset, int?limitRowCount, string orderBy, bool desc)
        {
            using (var db = new BasicVehicleDbContext())
            {
                var query = db.Vehicles.AsQueryable();

                if (!String.IsNullOrWhiteSpace(globalSearch))
                {
                    query = query.Where(p => (p.Make + " " + p.Model + " " + p.Vin + " " + p.Year + " " + p.CurrentMileage).Contains(globalSearch));
                }

                totalRecords = query.Count();

                if (!String.IsNullOrWhiteSpace(orderBy))
                {
                    switch (orderBy.ToLower())
                    {
                    case "make":
                        if (!desc)
                        {
                            query = query.OrderBy(p => p.Make);
                        }
                        else
                        {
                            query = query.OrderByDescending(p => p.Make);
                        }
                        break;

                    case "model":
                        if (!desc)
                        {
                            query = query.OrderBy(p => p.Model);
                        }
                        else
                        {
                            query = query.OrderByDescending(p => p.Model);
                        }
                        break;

                    case "year":
                        if (!desc)
                        {
                            query = query.OrderBy(p => p.Year);
                        }
                        else
                        {
                            query = query.OrderByDescending(p => p.Year);
                        }
                        break;

                    case "vin":
                        if (!desc)
                        {
                            query = query.OrderBy(p => p.Vin);
                        }
                        else
                        {
                            query = query.OrderByDescending(p => p.Vin);
                        }
                        break;

                    case "currentmileage":
                        if (!desc)
                        {
                            query = query.OrderBy(p => p.CurrentMileage);
                        }
                        else
                        {
                            query = query.OrderByDescending(p => p.CurrentMileage);
                        }
                        break;

                    case "id":
                        if (!desc)
                        {
                            query = query.OrderBy(p => p.Id);
                        }
                        else
                        {
                            query = query.OrderByDescending(p => p.Id);
                        }
                        break;
                    }
                }


                if (limitOffset.HasValue)
                {
                    query = query.Skip(limitOffset.Value).Take(limitRowCount.Value);
                }

                return(query.ToList());
            }
        }