Exemple #1
0
        public async Task <IActionResult> Edit(int id, [Bind("VehicleLifeEventId,Comment,DateTime,Description,EnumVehicleLifeEventTypeId,Timestamp,VehicleTrailerMapId,VersionNumber")] VehicleLifeEvent val)
        {
            if (val.VehicleLifeEventId != id)
            {
                return(NotFound());
            }

            this.FixNullFields(val);

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(val);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!Exists(val.VehicleLifeEventId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["EnumVehicleLifeEventTypeId"] = new SelectList(_context.EnumVehicleLifeEventType, "EnumVehicleLifeEventTypeId", "Description", val.EnumVehicleLifeEventTypeId);
            ViewData["VehicleTrailerMapId"]        = new SelectList(_context.VehicleTrailerMap, "VehicleTrailerMapId", "VehicleTrailerMapId", val.VehicleTrailerMapId);
            return(View(val));
        }
Exemple #2
0
 private void FixNullFields(VehicleLifeEvent val)
 {
     if (String.IsNullOrWhiteSpace(val.Comment))
     {
         val.Comment = "N/A";
     }
     if (String.IsNullOrWhiteSpace(val.Description))
     {
         val.Description = "N/A";
     }
 }
Exemple #3
0
        public async Task <IActionResult> Create([Bind("VehicleLifeEventId,Comment,DateTime,Description,EnumVehicleLifeEventTypeId,Timestamp,VehicleTrailerMapId,VersionNumber")] VehicleLifeEvent val)
        {
            this.FixNullFields(val);
            if (ModelState.IsValid)
            {
                _context.Add(val);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["EnumVehicleLifeEventTypeId"] = new SelectList(_context.EnumVehicleLifeEventType, "EnumVehicleLifeEventTypeId", "Description", val.EnumVehicleLifeEventTypeId);
            ViewData["VehicleTrailerMapId"]        = new SelectList(_context.VehicleTrailerMap, "VehicleTrailerMapId", "VehicleTrailerMapId", val.VehicleTrailerMapId);
            return(View(val));
        }