Inheritance: VehicleAdd
Exemplo n.º 1
0
        public VehicleBase GetVehicleById(int id)
        {
            // Attempt to fetch from the data store
            var fetchedObject = ds.Vehicles.Include("Manufacturer").SingleOrDefault(i => i.Id == id);

            if (fetchedObject == null)
            {
                return(null);
            }
            else
            {
                // Prepare the return result
                var v = new VehicleBase()
                {
                    Id               = fetchedObject.Id,
                    Model            = fetchedObject.Model,
                    Trim             = fetchedObject.Trim,
                    ModelYear        = fetchedObject.ModelYear,
                    MSRP             = fetchedObject.MSRP,
                    ManufacturerId   = fetchedObject.Manufacturer.Id,
                    ManufacturerName = fetchedObject.Manufacturer.Name
                };

                // Return the result
                return(v);
            }
        }
Exemplo n.º 2
0
        // Vehicle

        // ############################################################
        // Get all, get one

        public IEnumerable <VehicleBase> GetAllVehicles()
        {
            // Fetch from the data store
            var fetchedObjects = ds.Vehicles.Include("Manufacturer").OrderBy(m => m.Model);

            // Prepare the return result
            var vehicles = new List <VehicleBase>();

            foreach (var item in fetchedObjects)
            {
                var v = new VehicleBase()
                {
                    Id               = item.Id,
                    Model            = item.Model,
                    Trim             = item.Trim,
                    ModelYear        = item.ModelYear,
                    MSRP             = item.MSRP,
                    ManufacturerId   = item.Manufacturer.Id,
                    ManufacturerName = item.Manufacturer.Name
                };
                vehicles.Add(v);
            }

            // Return the result
            return(vehicles);
        }
Exemplo n.º 3
0
        // ############################################################
        // Add new

        public VehicleBase AddNewVehicle(VehicleAdd newItem)
        {
            // Attempt to fetch the associated object
            var m = ds.Manufacturers.Find(newItem.ManufacturerId);

            if (m == null)
            {
                return(null);
            }
            else
            {
                // Associated object is valid, so continue

                // Create a new design model object
                var addedItem = new Vehicle()
                {
                    Model        = newItem.Model,
                    Trim         = newItem.Trim,
                    ModelYear    = newItem.ModelYear,
                    MSRP         = newItem.MSRP,
                    Manufacturer = m
                };

                // Add and save
                ds.Vehicles.Add(addedItem);
                ds.SaveChanges();

                // Prepare the return object
                var v = new VehicleBase()
                {
                    Id               = addedItem.Id,
                    Model            = addedItem.Model,
                    Trim             = addedItem.Trim,
                    ModelYear        = addedItem.ModelYear,
                    MSRP             = addedItem.MSRP,
                    ManufacturerId   = m.Id,
                    ManufacturerName = m.Name
                };

                // Return the result
                return(v);
            }
        }
Exemplo n.º 4
0
        // ############################################################
        // Add new
        public VehicleBase AddNewVehicle(VehicleAdd newItem)
        {
            // Attempt to fetch the associated object
            var m = ds.Manufacturers.Find(newItem.ManufacturerId);

            if (m == null)
            {
                return null;
            }
            else
            {
                // Associated object is valid, so continue

                // Create a new design model object
                var addedItem = new Vehicle()
                {
                    Model = newItem.Model,
                    Trim = newItem.Trim,
                    ModelYear = newItem.ModelYear,
                    MSRP = newItem.MSRP,
                    Manufacturer = m
                };

                // Add and save
                ds.Vehicles.Add(addedItem);
                ds.SaveChanges();

                // Prepare the return object
                var v = new VehicleBase()
                {
                    Id = addedItem.Id,
                    Model = addedItem.Model,
                    Trim = addedItem.Trim,
                    ModelYear = addedItem.ModelYear,
                    MSRP = addedItem.MSRP,
                    ManufacturerId = m.Id,
                    ManufacturerName = m.Name
                };

                // Return the result
                return v;
            }
        }
Exemplo n.º 5
0
        public VehicleBase GetVehicleById(int id)
        {
            // Attempt to fetch from the data store
            var fetchedObject = ds.Vehicles.Include("Manufacturer").SingleOrDefault(i => i.Id == id);

            if (fetchedObject == null)
            {
                return null;
            }
            else
            {
                // Prepare the return result
                var v = new VehicleBase()
                {
                    Id = fetchedObject.Id,
                    Model = fetchedObject.Model,
                    Trim = fetchedObject.Trim,
                    ModelYear = fetchedObject.ModelYear,
                    MSRP = fetchedObject.MSRP,
                    ManufacturerId = fetchedObject.Manufacturer.Id,
                    ManufacturerName = fetchedObject.Manufacturer.Name
                };

                // Return the result
                return v;
            }
        }
Exemplo n.º 6
0
        // Vehicle
        // ############################################################
        // Get all, get one
        public IEnumerable<VehicleBase> GetAllVehicles()
        {
            // Fetch from the data store
            var fetchedObjects = ds.Vehicles.Include("Manufacturer").OrderBy(m => m.Model);

            // Prepare the return result
            var vehicles = new List<VehicleBase>();

            foreach (var item in fetchedObjects)
            {
                var v = new VehicleBase()
                {
                    Id = item.Id,
                    Model = item.Model,
                    Trim = item.Trim,
                    ModelYear = item.ModelYear,
                    MSRP = item.MSRP,
                    ManufacturerId = item.Manufacturer.Id,
                    ManufacturerName = item.Manufacturer.Name
                };
                vehicles.Add(v);
            }

            // Return the result
            return vehicles;
        }