コード例 #1
0
        public async Task <IActionResult> Edit(string id, [Bind("DNI,Nombre,Apellidos,Puntos")] Conductor conductor)
        {
            object Error;

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(conductor);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
                catch (Exception ex)
                {
                    Error = new ErrorViewModel
                    {
                        Error   = "Error al momento de modificar la información en el Sistema.",
                        Message = ex.Message
                    };

                    return(View("~/Views/Shared/Error.cshtml", Error));
                }
            }
            Error = new ErrorViewModel
            {
                Error   = "Error al momento de ingresar la información al Sistema.",
                Message = "Verificar la información ingresada"
            };

            return(View("~/Views/Shared/Error.cshtml", Error));
        }
コード例 #2
0
        public async Task <IActionResult> Create([Bind("Id,Descripcion,Puntos,DNI_Conductor,Matricula_Vehiculo")] InfraccionViewModel infracciones)
        {
            object Error;

            if (ModelState.IsValid)
            {
                try
                {
                    var Vehiculo = await _context.Vehiculos.FindAsync(infracciones.Matricula_Vehiculo);

                    var Conductor = await _context.Conductores.FindAsync(Vehiculo.DNI_Conductor);

                    infracciones.DNI_Conductor = Conductor.DNI;
                    infracciones.Fecha         = DateTime.Today;
                    infracciones.Hora          = DateTime.Now.ToShortTimeString();
                    _context.Add(infracciones.ToEntity());
                    await _context.SaveChangesAsync();

                    Conductor.Puntos = (Conductor.Puntos - infracciones.Puntos);
                    _context.Update(Conductor);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
                catch (Exception ex)
                {
                    Error = new ErrorViewModel
                    {
                        Error   = "Error al momento de ingresar la informacion al Sistema.",
                        Message = ex.Message
                    };
                    return(View("~/Views/Shared/Error.cshtml", Error));
                }
            }
            Error = new ErrorViewModel
            {
                Error   = "Error al momento de ingresar la información al Sistema.",
                Message = "Verificar la información ingresada"
            };

            return(View("~/Views/Shared/Error.cshtml", Error));
        }