Ejemplo n.º 1
0
        public void Update(int id, VehicleViewModel vehicle, string trackingId)
        {
            if (trackingId == null)
            {
                throw new ArgumentException(nameof(trackingId));
            }

            vehicle.LastUpdatedTrackingId = trackingId;
        }
Ejemplo n.º 2
0
        public IActionResult Edit(int id)
        {
            if (id != 42)
            {
                return HttpNotFound();
            }

            // Provide room for one additional inspection if not already full.
            var vehicle = _vehicle;
            var length = vehicle.InspectedDates.Length;
            if (length < 10)
            {
                var array = new DateTimeOffset[length + 1];
                vehicle.InspectedDates.CopyTo(array, 0);

                // Don't update the stored VehicleViewModel instance.
                vehicle = new VehicleViewModel
                {
                    InspectedDates = array,
                    LastUpdatedTrackingId = vehicle.LastUpdatedTrackingId,
                    Make = vehicle.Make,
                    Model = vehicle.Model,
                    Vin = vehicle.Vin,
                    Year = vehicle.Year,
                };
            }

            return View(vehicle);
        }
Ejemplo n.º 3
0
        public IActionResult Edit(int id, VehicleViewModel vehicle)
        {
            if (id != 42)
            {
                return HttpNotFound();
            }

            if (!ModelState.IsValid)
            {
                return View(vehicle);
            }

            if (vehicle.InspectedDates != null)
            {
                // Ignore empty inspection values.
                var nonEmptyDates = vehicle.InspectedDates.Where(date => date != default(DateTimeOffset)).ToArray();
                vehicle.InspectedDates = nonEmptyDates;
            }

            _vehicle = vehicle;

            return RedirectToAction(nameof(Details), new { id = id });
        }