Esempio n. 1
0
        public String ActualizarPosicion([FromBody] Posicionconductor pos)
        {
            var tc = HttpContext.RequestServices.GetService(typeof(taxverContext)) as taxverContext;

            try
            {
                var posicion = tc.Posicionconductor.FirstOrDefault(posc => posc.IdConductor == pos.IdConductor);
                if (posicion != null)
                {
                    posicion.Lat = pos.Lat;
                    posicion.Lng = pos.Lng;
                    tc.Posicionconductor.Update(posicion);
                    tc.SaveChanges();
                    return("si");
                }
                else
                {
                    return("si");
                }
            }
            catch (Exception e)
            {
                return(e.Message);
            }
        }
Esempio n. 2
0
 public async Task <ActionResult> Create(Conductor c, DateTime fechaN, IFormFile file)
 {
     try
     {
         var tc     = HttpContext.RequestServices.GetService(typeof(taxverContext)) as taxverContext;
         var entity = tc.Vehiculo.FirstOrDefault(ve => ve.IdVehiculo == c.IdVehiculo);
         if (entity != null)
         {
             entity.Status = 3;
             tc.Vehiculo.Update(entity);
             tc.SaveChanges();
         }
         c.IdPersonaNavigation.FechaNacimiento = fechaN;
         c.IdPersonaNavigation.Status          = 1;
         tc.Persona.Add(c.IdPersonaNavigation);
         tc.SaveChanges();
         try
         {
             c.IdPersonaNavigation.IdPersona = tc.Persona.Last().IdPersona;
             var path     = _env.WebRootPath;
             var filePath = System.IO.Path.Combine(path, "Fotos");
             if (!System.IO.Directory.Exists(filePath))
             {
                 System.IO.Directory.CreateDirectory(filePath);
             }
             var filecomp = c.IdPersonaNavigation.IdPersona + c.IdPersonaNavigation.Nombre + c.IdPersonaNavigation.ApellidoPaterno + c.IdPersonaNavigation.ApellidoMaterno + ".jpg";
             var fileName = filePath + System.IO.Path.DirectorySeparatorChar + filecomp;
             if (file.Length > 0)
             {
                 using (var stream = new FileStream(fileName, FileMode.Create))
                 {
                     await file.CopyToAsync(stream);
                 }
             }
             c.Foto = "Fotos/" + filecomp;
         }
         catch (Exception e)
         {
             return(Content("" + e));
         }
         c.IdPersona = tc.Persona.Last().IdPersona;
         c.Status    = 1;
         c.Tarifa    = 9;
         c.IdUsuario = HttpContext.Session.GetInt32("id");
         tc.Conductor.Add(c);
         tc.SaveChanges();
         Posicionconductor pos = new Posicionconductor();
         pos.Lat         = "0";
         pos.Lng         = "0";
         pos.Status      = 2;
         pos.IdConductor = tc.Conductor.LastOrDefault().IdConductor;
         tc.Posicionconductor.Add(pos);
         tc.SaveChanges();
         try
         {
         }
         catch (Exception e)
         {
             return(Content("" + e));
         }
         return(RedirectToAction(nameof(Ver)));
     }
     catch (Exception e)
     {
         return(Content("" + e));
     }
 }