Exemple #1
0
        public async Task <VehicleMake> AddNewVehicleMake(VehicleMake vehicle)
        {
            context.Add(vehicle);
            await context.SaveChangesAsync();

            return(vehicle);
        }
Exemple #2
0
        public async Task <VehicleMake> UpdateVehicleMake(VehicleMake vehicleMakeChanges)
        {
            var vehicle = context.vehicleMakes.Attach(vehicleMakeChanges);

            vehicle.State = Microsoft.EntityFrameworkCore.EntityState.Modified;
            await context.SaveChangesAsync();

            return(vehicleMakeChanges);
        }
        public async Task <int> AddMake(VehicleMake make)
        {
            if (db != null)
            {
                db.vehicleMakes.Add(make);
                await db.SaveChangesAsync();

                return(make.ID);
            }

            return(0);
        }
        public async Task <int> UpdateMake(VehicleMake make)
        {
            if (db != null)
            {
                //Update that model
                //db.vehicleModels.Update(model);
                db.Entry(make).State = EntityState.Modified;

                //Commit the transaction
                await db.SaveChangesAsync();

                return(make.ID);
            }
            return(0);
        }
Exemple #5
0
        public async Task <VehicleMake> DeleteVehicleMake(int id)
        {
            VehicleMake vehicle = await context.vehicleMakes.FindAsync(id);

            if (vehicle != null)
            {
                //context.Remove(vehicle_fk);
                var commandText   = "delete from VehicleModel where MakeId = @id";
                var vehicle_model = new SqlParameter("@id", id);
                context.Database.ExecuteSqlCommand(commandText, vehicle_model);

                context.vehicleMakes.Remove(vehicle);
                await context.SaveChangesAsync();
            }
            return(vehicle);
        }