public async Task <IActionResult> Edit(long id, [Bind("Id,DateTime,Quantity,PricePerLitre,Provider")] FuelLog fuelLog)
        {
            if (id != fuelLog.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(fuelLog);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!FuelLogExists(fuelLog.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(fuelLog));
        }
Example #2
0
        public void ShowObject(object keyValue)
        {
            fuelLog = keyValue as FuelLog;
            fuelLogBindingSource.DataSource = fuelLog;
            var vehicle = context.VehicleInfoes.First(v => v.VehicleId == fuelLog.VehicleId);

            plateNoTextBox.Text = vehicle.PlateNumber;
        }
Example #3
0
        private void AddFuelLogRecord()
        {
            var record = new FuelLog {
                VehicleId = this.vehicle.VehicleId
            };
            var dialog = new FuelLogEdit();

            dialog.ShowObject(record);
            var result = dialog.ShowDialog();

            if (result == DialogResult.OK)
            {
                this.vehicle.FuelLogs.Add(dialog.Current);
            }
        }
Example #4
0
        private void AddFuelLog()
        {
            var selected = (VehicleInfo)vehicleListBindingSource.Current;
            var record   = new FuelLog {
                VehicleId = selected.VehicleId
            };
            var dialog = new FuelLogEdit();

            dialog.ShowObject(record);
            var result = dialog.ShowDialog();

            if (result == DialogResult.OK)
            {
                using (var ctx = new FleetEntities())
                {
                    ctx.FuelLogs.AddObject(record);
                    ctx.SaveChanges();
                }
            }
        }
 public async Task <IActionResult> Create(DateTime DateTime, float Quantity, float PricePerLitre, string FuelType, string Provider, long Vehicle)
 {
     try
     {
         FuelLog log = new FuelLog
         {
             DateTime      = DateTime,
             Quantity      = Quantity,
             PricePerLitre = PricePerLitre,
             FuelType      = FuelType,
             Provider      = Provider,
             Vehicle       = _context.Vehicles.Find(Vehicle)
         };
         _context.Add(log);
         await _context.SaveChangesAsync();
     }
     catch (Exception)
     {
     }
     return(RedirectToAction(nameof(Index)));
 }
Example #6
0
 public void SaveChanges()
 {
     this.fuelLogBindingSource.EndEdit();
     this.Current      = fuelLog;
     this.DialogResult = DialogResult.OK;
 }