Ejemplo n.º 1
0
 public ActionResult Edit([Bind(Include = "IdViaje,IdConductor,IdCorredor,idProducto,Estado,IdPlaca,IdTrailer,alcohotest,Fecha,Checklist")] VIAJE vIAJE)
 {
     if (ModelState.IsValid)
     {
         bool existeViaje = db.VIAJE.Any(x => x.NumeroViaje == vIAJE.NumeroViaje && x.Estado == true); //db.VIAJE.Any(x => x.IdConductor == vIAJE.IdConductor && x.IdCorredor == vIAJE.IdCorredor && x.IdInstructor == vIAJE.IdInstructor && x.idPlaca == vIAJE.idPlaca && x.IdProducto == vIAJE.IdProducto && x.idTrailer == vIAJE.idTrailer && x.Estado == vIAJE.Estado);
         if (!existeViaje)
         {
             db.Entry(vIAJE).State = EntityState.Modified;
             db.SaveChanges();
             return(RedirectToAction("Index"));
         }
         else
         {
             ViewBag.Message = "Ya existe un registro con este numero de viaje," + vIAJE.NumeroViaje + " por favor revise...";
         }
     }
     ViewBag.IdConductor = new SelectList(db.CONDUCTOR, "IdConductor", "Nombre", vIAJE.IdConductor);
     ViewBag.IdCorredor  = new SelectList(db.CORREDOR, "IdCorredor", "Corredor1", vIAJE.IdCorredor);
     ViewBag.IdProducto  = new SelectList(db.PRODUCTO, "idProducto", "Producto1", vIAJE.IdProducto);
     ViewBag.IdTrailer   = new SelectList(db.TRAILER, "IdTrailer", "PlacaTrailer", vIAJE.idTrailer);
     ViewBag.IdPlaca     = new SelectList(db.PLACAS, "IdPlaca", "Placa", vIAJE.idPlaca);
     ViewBag.IdViaje     = new SelectList(db.VIAJE, "IdViaje", "Viaje", vIAJE.IdViaje);
     ViewBag.alcohotest  = vIAJE.Alcohotest;
     ViewBag.Fecha       = vIAJE.Fecha;
     ViewBag.Checklist   = vIAJE.Checklist;
     return(View(vIAJE));
 }
Ejemplo n.º 2
0
        public ActionResult DeleteConfirmed(int id)
        {
            VIAJE vIAJE = db.VIAJE.Find(id);

            //db.VIAJE.Remove(vIAJE);
            vIAJE.Estado = false;
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 3
0
        // GET: VIAJE/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            VIAJE vIAJE = db.VIAJE.Find(id);

            if (vIAJE == null)
            {
                return(HttpNotFound());
            }
            return(View(vIAJE));
        }
Ejemplo n.º 4
0
        public ActionResult Create([Bind(Include = "IdViaje,IdConductor,IdCorredor,IdProducto,Estado,IdPlaca,IdTrailer,Alcohotest,NumeroViaje,Checklist,IdInstructor")] VIAJE vIAJE)
        {
            vIAJE.Fecha = DateTime.Now;
            var errors = ModelState.Values.SelectMany(v => v.Errors);

            if (ModelState.IsValid)
            {
                string idCond        = vIAJE.IdConductor.ToString();
                bool   existeViaje   = db.VIAJE.Any(x => x.NumeroViaje == vIAJE.NumeroViaje);
                bool   existePlaca   = db.VIAJE.Any(x => x.idPlaca == vIAJE.idPlaca);
                bool   existeTrailer = db.VIAJE.Any(x => x.idTrailer == vIAJE.idTrailer);
                bool   existeUsuario = db.VIAJE.Any(x => x.IdConductor == vIAJE.IdConductor && x.Estado == true); //db.VIAJE.Any(x => x.IdConductor == vIAJE.IdConductor && x.IdCorredor == vIAJE.IdCorredor && x.IdInstructor == vIAJE.IdInstructor && x.idPlaca == vIAJE.idPlaca && x.IdProducto == vIAJE.IdProducto && x.idTrailer == vIAJE.idTrailer && x.Estado == vIAJE.Estado);
                string idInst        = JsonConvert.SerializeObject(db.TraerInstructorIdCond(idCond));
                if (!existeViaje)
                {
                    if (!existePlaca)
                    {
                        if (!existeTrailer)
                        {
                            if (!existeUsuario)
                            {
                                vIAJE.Estado       = true;
                                vIAJE.IdInstructor = Convert.ToInt32(idInst);
                                db.VIAJE.Add(vIAJE);
                                db.SaveChanges();

                                VIAJECTRL vIAJECTRL = new VIAJECTRL();
                                vIAJECTRL.Alcohotest   = vIAJE.Alcohotest;
                                vIAJECTRL.Estado       = vIAJE.Estado;
                                vIAJECTRL.Fecha        = DateTime.Now;
                                vIAJECTRL.FechaCtrl    = DateTime.Now;
                                vIAJECTRL.IdConductor  = vIAJE.IdConductor.Value;
                                vIAJECTRL.IdCorredor   = vIAJE.IdCorredor;
                                vIAJECTRL.IdInstructor = vIAJE.IdInstructor;
                                vIAJECTRL.idPlaca      = vIAJE.idPlaca;
                                vIAJECTRL.IdProducto   = vIAJE.IdProducto;
                                vIAJECTRL.idTrailer    = vIAJE.idTrailer;
                                vIAJECTRL.IdViaje      = vIAJE.IdViaje;
                                vIAJECTRL.NumeroViaje  = vIAJE.NumeroViaje;
                                vIAJECTRL.Checklist    = vIAJE.Checklist;

                                db1.VIAJECTRL.Add(vIAJECTRL);
                                db1.SaveChanges();
                                return(RedirectToAction("Index"));
                            }
                            else
                            {
                                ViewBag.Message = "Ya existe un registro con este conductor," + vIAJE.IdConductor + " por favor revise...";
                            }
                        }
                        else
                        {
                            ViewBag.Message = "Ya existe un registro con este numero de trailer," + vIAJE.idTrailer + " por favor revise...";
                        }
                    }
                    else
                    {
                        ViewBag.Message = "Ya existe un registro con este numero de placa," + vIAJE.idPlaca + " por favor revise...";
                    }
                }
                else
                {
                    ViewBag.Message = "Ya existe un registro con este numero de viaje," + vIAJE.NumeroViaje + " por favor revise...";
                }
            }

            ViewBag.IdConductor = new SelectList(db.CONDUCTOR, "IdConductor", "Cedula", vIAJE.IdConductor);
            ViewBag.IdCorredor  = new SelectList(db.CORREDOR, "IdCorredor", "Corredor1", vIAJE.IdCorredor);
            ViewBag.IdProducto  = new SelectList(db.PRODUCTO, "idProducto", "Producto1", vIAJE.IdProducto);
            ViewBag.IdTrailer   = new SelectList(db.TRAILER, "IdTrailer", "PlacaTrailer", vIAJE.idTrailer);
            ViewBag.IdPlaca     = new SelectList(db.PLACAS, "IdPlaca", "Placa", vIAJE.idPlaca);
            ViewBag.IdViaje     = new SelectList(db.VIAJE, "IdViaje", "Viaje", vIAJE.IdViaje);
            ViewBag.alcohotest  = new SelectList(db.VIAJE, "Alcohotest", "Alcohotest", vIAJE.Alcohotest);


            return(View(vIAJE));
        }
Ejemplo n.º 5
0
        // GET: VIAJE/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            JavaScriptSerializer js = new JavaScriptSerializer();
            VIAJE vIAJE             = db.VIAJE.Find(id);
            var   inform            = JsonConvert.SerializeObject(db.TraerConductorId(vIAJE.IdConductor));

            Inform[] inform1 = js.Deserialize <Inform[]>(inform);
            //string IdInst = inform1[4].ToString();

            string[] informC;
            informC = new string[5];
            string IdViaj = "";

            IdViaj = vIAJE.IdConductor.ToString();

            string CedCond  = "";
            string NombInst = "";

            using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["CONTROL"].ConnectionString))
            {
                SqlCommand command1 = new SqlCommand();
                command1.Connection  = connection;
                command1.CommandText = "TraerConductorId";
                command1.CommandType = CommandType.StoredProcedure;
                // Add the input parameter and set its properties.
                SqlParameter parameter1 = new SqlParameter();
                parameter1.ParameterName = "@Id";
                parameter1.SqlDbType     = SqlDbType.Int;
                parameter1.Direction     = ParameterDirection.Input;
                parameter1.Value         = Convert.ToInt32(IdViaj);
                // Add the parameter to the Parameters collection.
                command1.Parameters.Add(parameter1);
                // Open the connection and execute the reader.
                connection.Open();
                using (SqlDataReader reader1 = command1.ExecuteReader())
                {
                    if (reader1.HasRows)
                    {
                        while (reader1.Read())
                        {
                            informC[0] = reader1[0].ToString();
                            informC[1] = reader1[1].ToString();
                            informC[2] = reader1[2].ToString();
                            informC[3] = reader1[3].ToString();
                            informC[4] = reader1[4].ToString();
                        }
                    }
                    else
                    {
                        Console.WriteLine("No rows found.");
                    }
                    CedCond = informC[3];
                    reader1.Close();

                    string IdInst = informC[4].ToString();

                    SqlCommand command2 = new SqlCommand();
                    command2.Connection  = connection;
                    command2.CommandText = "[TraerInstructor]";
                    command2.CommandType = CommandType.StoredProcedure;
                    // Add the input parameter and set its properties.
                    SqlParameter parameter2 = new SqlParameter();
                    parameter2.ParameterName = "@Id";
                    parameter2.SqlDbType     = SqlDbType.Int;
                    parameter2.Direction     = ParameterDirection.Input;
                    parameter2.Value         = Convert.ToInt32(IdInst);
                    // Add the parameter to the Parameters collection.
                    command2.Parameters.Add(parameter2);
                    // Open the connection and execute the reader.
                    using (SqlDataReader reader2 = command2.ExecuteReader())
                    {
                        if (reader2.HasRows)
                        {
                            while (reader2.Read())
                            {
                                NombInst = reader2[0].ToString();
                            }
                        }
                        else
                        {
                            Console.WriteLine("No rows found.");
                        }
                        reader2.Close();
                    }
                }
                connection.Close();
            }

            if (vIAJE == null)
            {
                return(HttpNotFound());
            }

            ViewBag.NombreCond  = informC[0]; // inform1[0].Nombre;
            ViewBag.Celular     = informC[1]; //.Celular1;
            ViewBag.IdConductor = new SelectList(db.CONDUCTOR, "idConductor", "Cedula", vIAJE.IdConductor);
            ViewBag.IdCorredor  = new SelectList(db.CORREDOR, "IdCorredor", "Corredor1", vIAJE.IdCorredor);
            ViewBag.IdProducto  = new SelectList(db.PRODUCTO, "IdProducto", "Producto1", vIAJE.IdProducto);
            ViewBag.IdTrailer   = new SelectList(db.TRAILER, "IdTrailer", "PlacaTrailer", vIAJE.idTrailer);
            ViewBag.IdPlaca     = new SelectList(db.PLACAS, "IdPlaca", "Placa", vIAJE.idPlaca);
            ViewBag.IdViaje     = new SelectList(db.VIAJE, "IdViaje", "Viaje", vIAJE.IdViaje);
            ViewBag.Alcohotest  = "";
            ViewBag.Fecha       = vIAJE.Fecha;
            ViewBag.Checklist   = vIAJE.Checklist;
            ViewBag.NombreInst  = NombInst;

            //ViewBag.Instructor = NombInst;
            return(View(vIAJE));
        }
 /// <summary>
 /// Metodo para establecerle un parqueo a un
 /// viaje.
 /// <remarks>
 /// Nota: se hace realmente una actualizacion
 ///     a la informacion del viaje.
 /// </remarks>
 /// </summary>
 /// <param name="pViaje"> Es un objeto tipo viaje, se debe de
 ///                   ingresar en el cuerpo del llamado a
 ///                   la pagina web.</param>
 public string PutParqueoToViaje([FromBody] VIAJE pViaje)
 {
     dbEntities.usp_PutNoParqueo(pViaje.VI_ID, pViaje.VI_parqueo);
     dbEntities.SaveChanges();
     return(respond);
 }
 /// <summary>
 /// Metodo para ingresar un nuevo viaje
 /// </summary>
 /// <param name="pViajes"> Es un objeto tipo viaje, se debe de
 ///                   ingresar en el cuerpo del llamado a
 ///                   la pagina web.</param>
 public string Post([FromBody] VIAJE pViajes)
 {
     dbEntities.usp_PostViajes(pViajes.VI_choferID, pViajes.VI_fecha, pViajes.VI_fecha);
     dbEntities.SaveChanges();
     return(respond);
 }