Esempio n. 1
0
 public ActionResult Edit(int id, Trayecto collection)
 {
     try
     {
         var client  = new RestClient(Direcciones.ApiRest + "trayecto");
         var request = new RestRequest(Method.PUT);
         request.AddHeader("content-type", "application/json");
         request.AddHeader("Authorization", "Bearer " + Request.Cookies["Token"].Value);
         collection.Id = id;
         collection.ListaPuntosControl = null;
         collection.Version            = 0;
         collection.Borrado            = false;
         request.AddJsonBody(collection);
         IRestResponse response = client.Execute(request);
         if (response.StatusCode.ToString() == "OK")
         {
             return(RedirectToAction("Index"));
         }
         ViewBag.ERROR = response.Content;
         return(Edit(id));
     }
     catch (Exception e)
     {
         ViewBag.ERROR = e.Message;
         return(Edit(id));
     }
 }
Esempio n. 2
0
        public Trayecto entidadAModelo(STrayecto t, Trayecto tr)
        {
            tr.nombre  = t.Nombre;
            tr.version = t.Version;
            tr.borrado = t.Borrado;

            return(tr);
        }
Esempio n. 3
0
        // GET: Trayecto/Edit/5
        public ActionResult Edit(int id)
        {
            var client  = new RestClient(Direcciones.ApiRest + "trayecto");
            var request = new RestRequest(Method.GET);

            request.AddHeader("content-type", "application/json");
            request.AddHeader("Authorization", "Bearer " + Request.Cookies["Token"].Value);
            request.AddQueryParameter("id", id.ToString());
            IRestResponse response = client.Execute(request);

            if (response.StatusCode.ToString() == "OK")
            {
                ViewBag.TRAYECTO = JsonConvert.DeserializeObject <Models.Trayecto>(response.Content);
                client           = new RestClient(Direcciones.ApiRest + "trayecto/puntoscontrol");
                response         = client.Execute(request);
                if (response.StatusCode.ToString() == "OK")
                {
                    List <PuntoControl> pclist = JsonConvert.DeserializeObject <List <Models.PuntoControl> >(response.Content);
                    ViewBag.PUNTOSCONTROL = JsonConvert.DeserializeObject <List <Models.PuntoControl> >(response.Content);
                    client  = new RestClient(Direcciones.ApiRest + "agencia");
                    request = new RestRequest(Method.GET);
                    request.AddHeader("content-type", "application/json");
                    request.AddHeader("Authorization", "Bearer " + Request.Cookies["Token"].Value);
                    response = client.Execute(request);
                    if (response.StatusCode.ToString() == "OK")
                    {
                        List <Models.Agencia> a = new List <Models.Agencia>();
                        //a.Add(new Models.Agencia() { Id = 0, Nombre = "Ninguna", Borrado = false, EnvioDomicilio = false, IdEmpresa = 1, Ubicacion = "lerelele" });
                        foreach (var item in JsonConvert.DeserializeObject <List <Models.Agencia> >(response.Content))
                        {
                            a.Add(item);
                        }
                        ViewBag.AGENCIAS = a;
                        Trayecto t = new Trayecto()
                        {
                            Id                 = ViewBag.TRAYECTO.Id,
                            Nombre             = ViewBag.TRAYECTO.Nombre,
                            ListaPuntosControl = pclist
                        };

                        return(View(t));
                    }
                    else
                    {
                        ViewBag.ERROR = response.Content;
                        return(View());
                    }
                }
                ViewBag.ERROR = response.Content;
                return(View());
            }
            ViewBag.ERROR = response.Content;
            return(View());
        }
Esempio n. 4
0
        public STrayecto updateTrayecto(STrayecto a)
        {
            using (trackingFULLEntities en = new trackingFULLEntities())
            {
                try
                {
                    List <string> ids = new List <string>();
                    foreach (SEAPuntoControlAgencia p in a.ListaPuntosControl)
                    {
                        if (p.Id != null)
                        {
                            ids.Add(((int)p.Id).ToString());
                        }
                    }
                    String query = "Select * from PuntoControl WHERE PuntoControl.borrado = 0 and PuntoControl.idTrayecto = " + a.Id;
                    if (ids.Count > 0)
                    {
                        query += " and id NOT IN(" + string.Join(", ", ids) + ")";
                    }
                    en.Database.SqlQuery <SPuntoControl>(query).ToList().ForEach(x =>
                    {
                        x.Borrado = true;
                        en.SaveChanges();
                    });

                    Trayecto ag = en.Trayecto.Find(a.Id);
                    ag = _conv.entidadAModelo(a, ag);
                    DALPuntoControl dalp = new DALPuntoControl();
                    if (a.ListaPuntosControl != null)
                    {
                        a.ListaPuntosControl.ToList().ForEach(x =>
                        {
                            x.IdTrayecto = ag.id;
                            if (x.Id > 0)
                            {
                                dalp.updatePuntoControl(x);
                            }
                            else
                            {
                                dalp.addPuntoControl(x);
                            }
                        });
                    }
                    en.SaveChanges();
                    return(_conv.modeloAEntidad(ag));
                }
                catch (Exception)
                {
                    throw;
                }
            }
        }
Esempio n. 5
0
        public Trayecto entidadAModelo(STrayecto t)
        {
            Trayecto trayecto = new Trayecto()
            {
                nombre  = t.Nombre,
                version = t.Version,
                borrado = t.Borrado
            };

            if (t.Id != null)
            {
                trayecto.id = (int)t.Id;
            }
            return(trayecto);
        }
Esempio n. 6
0
 public STrayecto addTrayecto(STrayecto a)
 {
     using (trackingFULLEntities en = new trackingFULLEntities())
     {
         try
         {
             Trayecto ag = en.Trayecto.Add(_conv.entidadAModelo(a));
             if (a.ListaPuntosControl != null)
             {
                 a.ListaPuntosControl.ForEach(x =>
                 {
                     ag.PuntoControl.Add(_conv.entidadAModelo(x));
                 });
             }
             else
             {
                 ag.PuntoControl.Add(new PuntoControl()
                 {
                     nombre = "Recibido en origen", orden = 1, tiempo = 0, borrado = false
                 });
                 ag.PuntoControl.Add(new PuntoControl()
                 {
                     nombre = "Esperando en origen", orden = 2, tiempo = 0, borrado = false
                 });
                 ag.PuntoControl.Add(new PuntoControl()
                 {
                     nombre = "En viaje", orden = 3, tiempo = 0, borrado = false
                 });
                 ag.PuntoControl.Add(new PuntoControl()
                 {
                     nombre = "Recibido en destino", orden = 4, tiempo = 0, borrado = false
                 });
                 ag.PuntoControl.Add(new PuntoControl()
                 {
                     nombre = "Entregado al cliente", orden = 5, tiempo = 0, borrado = false
                 });
             }
             en.SaveChanges();
             return(_conv.modeloAEntidad(ag));
         }
         catch (Exception e)
         {
             throw;
         }
     }
 }
Esempio n. 7
0
        public string deleteTrayecto(int id)
        {
            using (trackingFULLEntities en = new trackingFULLEntities())
            {
                try
                {
                    Trayecto a = en.Trayecto.Find(id);
                    a.borrado = true;
                    en.SaveChanges();

                    return(null);
                }
                catch (Exception)
                {
                    throw;
                }
            }
        }
Esempio n. 8
0
 public bool isActive(int id)
 {
     using (trackingFULLEntities en = new trackingFULLEntities())
     {
         try
         {
             Trayecto a = en.Trayecto.Find(id);
             if ((bool)a.borrado)
             {
                 return(false);
             }
             return(true);
         }
         catch (Exception)
         {
             throw;
         }
     }
 }
Esempio n. 9
0
        //TRAYECTO

        public STrayecto modeloAEntidad(Trayecto t)
        {
            if (t == null)
            {
                return(null);
            }
            STrayecto trayecto = new STrayecto()
            {
                Id                 = t.id,
                Nombre             = t.nombre,
                Version            = (int)t.version,
                Borrado            = (bool)t.borrado,
                ListaPuntosControl = new List <SPuntoControl>()
            };

            t.PuntoControl.ToList().ForEach(x =>
            {
                if (x.borrado == false || x.borrado == null)
                {
                    trayecto.ListaPuntosControl.Add(modeloAEntidad(x));
                }
            });
            return(trayecto);
        }