Example #1
0
        public void ReadPaqueteTest()
        {
            PaqueteDTO paquete3 = new PaqueteDTO {
                Color = "Azul", EnvioId = 3, Peso = 20, PaqueteId = 3, Tamanyo = 300
            };

            mockPaqueteRepo.Setup(PaqueteRepo => PaqueteRepo.Read(paquete3.PaqueteId)).Returns(paquete3);
            PaqueteDTO resultado = sut.Read(3);

            Assert.IsNotNull(resultado);
        }
Example #2
0
 public ActionResult Create(PaqueteDTO collection)
 {
     try
     {
         var client  = new RestClient(Direcciones.ApiRest + "cliente/nuevopaquete");
         var request = new RestRequest(Method.POST);
         request.AddHeader("content-type", "application/json");
         request.AddHeader("Authorization", "Bearer " + Request.Cookies["Token"].Value);
         List <Cliente> clientes = new List <Cliente>()
         {
             collection.Remitente,
             collection.Destinatario
         };
         request.AddJsonBody(clientes);
         IRestResponse response = client.Execute(request);
         if (response.StatusCode.ToString() == "OK")
         {
             client  = new RestClient(Direcciones.ApiRest + "paquete");
             request = new RestRequest(Method.POST);
             request.AddHeader("content-type", "application/json");
             request.AddHeader("Authorization", "Bearer " + Request.Cookies["Token"].Value);
             clientes = JsonConvert.DeserializeObject <List <Cliente> >(response.Content);
             Paquete paquete = new Paquete()
             {
                 IdTrayecto = collection.IdTrayecto
             };
             clientes.ForEach(x =>
             {
                 if (x.Email == collection.Remitente.Email)
                 {
                     paquete.IdRemitente = x.Id;
                 }
                 else
                 {
                     paquete.IdDestinatario = x.Id;
                 }
             });
             request.AddJsonBody(paquete);
             response = client.Execute(request);
             if (response.StatusCode.ToString() == "OK")
             {
                 ViewBag.OK = "El paquete fue dado de alta correctamente";
                 return(RedirectToAction("index", "paquete"));
             }
         }
         ViewBag.ERROR = "Hubo un problema al dar de alta el paquete: " + response.Content.ToString() + ". Por favor revise todos los datos y vuelva a intentarlo";
         return(Create());
     }
     catch (Exception e)
     {
         ViewBag.ERROR = e.Message;
         return(Create());
     }
 }
Example #3
0
        public void ReadPaqueteTest()
        {
            PaqueteDTO paquete3 = new PaqueteDTO {
                Color = "Azul", EnvioId = EnvioIdTest, Peso = 20, Tamanyo = 300
            };
            PaqueteDTO resultado = sut.Create(paquete3);

            Listado.Add(resultado.PaqueteId);
            paquete3 = sut.Read(resultado.PaqueteId);
            Assert.IsNotNull(paquete3);
        }
Example #4
0
        public void DeletePaqueteTest()
        {
            PaqueteDTO paquete1 = new PaqueteDTO {
                Color = "Negro", EnvioId = 3, Peso = 160, PaqueteId = 5, Tamanyo = 10
            };

            mockPaqueteRepo.Setup(PaqueteRepo => PaqueteRepo.Delete(paquete1.PaqueteId)).Returns(paquete1);
            PaqueteDTO resultado = sut.Delete(paquete1.PaqueteId);

            Assert.IsNotNull(resultado);
        }
Example #5
0
        public void UpdatePaqueteTest()
        {
            PaqueteDTO paquete1 = new PaqueteDTO {
                Color = "rojo", EnvioId = 1, Peso = 10, PaqueteId = 1, Tamanyo = 100
            };

            mockPaqueteRepo.Setup(PaqueteRepo => PaqueteRepo.Update(paquete1)).Returns(paquete1);
            PaqueteDTO resultado = sut.Update(paquete1);

            Assert.IsNotNull(resultado);
        }
Example #6
0
        public void DeletePaqueteTest()
        {
            PaqueteDTO paquete1 = new PaqueteDTO {
                Color = "Negro", EnvioId = EnvioIdTest, Peso = 160, PaqueteId = 1, Tamanyo = 10
            };
            PaqueteDTO paquetecreate = sut.Create(paquete1);

            Listado.Add(paquetecreate.PaqueteId);
            PaqueteDTO resultado = sut.Delete(paquete1.PaqueteId);

            Assert.IsNull(resultado);
        }
Example #7
0
        public PaqueteDTO Read(long paqueteId)
        {
            Paquete entity = null;

            using (var ctx = dbFactory.GetInstance())
            {
                entity = ctx.Paquetes.Find(paqueteId);
            }
            PaqueteDTO dto = paqueteConversor.Entity2DTO(entity);

            return(dto);
        }
Example #8
0
        public void CreatePaqueteTest()
        {
            //EnvioDTO envio1 = new EnvioDTO { DestinatarioId = 1, FechaEntrega = DateTime.Now,  Estado=1, EnvioId=1 };
            PaqueteDTO paquete1 = new PaqueteDTO {
                Color = "rojo", EnvioId = EnvioIdTest, Peso = 10, Tamanyo = 100
            };

            paquete1 = sut.Create(paquete1);
            Listado.Add(paquete1.PaqueteId);
            Assert.IsNotNull(paquete1);
            Assert.AreNotEqual(-1, paquete1.PaqueteId);
        }
Example #9
0
        public IActionResult Create(PersonaModel p)
        {
            PersonaDTO          insertp = new PersonaDTO();
            List <PersonaModel> data    = new List <PersonaModel>();

            data.Add(insertp.Insert(p));

            PaqueteDTO paquete = new PaqueteDTO();

            paquete.status = 200;
            paquete.msn    = "Success";
            paquete.data   = data.ToArray();
            return(Ok(paquete));
        }
Example #10
0
        public PaqueteDTO Delete(long paqueteId)
        {
            Paquete entity = null;

            using (var ctx = dbFactory.GetInstance())
            {
                entity = ctx.Paquetes.Find(paqueteId);
                if (entity != null)
                {
                    ctx.Paquetes.Remove(entity);
                    ctx.SaveChanges();
                }
            }
            PaqueteDTO dto = paqueteConversor.Entity2DTO(entity);

            return(dto);
        }
Example #11
0
        public PaqueteDTO Create(PaqueteDTO paquete)
        {
            Paquete    entity = paqueteConversor.DTO2Entity(paquete);
            PaqueteDTO dto    = null;

            using (var ctx = dbFactory.GetInstance())
            {
                entity = ctx.Paquetes.Add(entity);
                if (entity == null)
                {
                    throw new PaqueteException("No se pudo crear el paquete.");
                }
                ctx.SaveChanges();
                dto = paqueteConversor.Entity2DTO(entity);
            }
            return(dto);
        }
Example #12
0
        public void UpdatePaqueteTest()
        {
            PaqueteDTO paquete1 = new PaqueteDTO {
                Color = "rojo", EnvioId = EnvioIdTest, Peso = 10, Tamanyo = 100
            };
            PaqueteDTO resultado = sut.Create(paquete1);

            Listado.Add(resultado.PaqueteId);
            paquete1        = null;
            resultado.Peso  = 50;
            resultado.Color = "negro";
            paquete1        = sut.Update(resultado);
            Assert.IsNotNull(paquete1);
            Assert.AreEqual(paquete1.PaqueteId, resultado.PaqueteId);
            Assert.AreEqual("negro", paquete1.Color);
            Assert.AreEqual(50, paquete1.Peso);
        }
Example #13
0
        public PaqueteDTO Update(PaqueteDTO paquete)
        {
            PaqueteDTO dto    = null;
            Paquete    entity = paqueteConversor.DTO2Entity(paquete);

            using (var ctx = dbFactory.GetInstance())
            {
                Paquete old = ctx.Paquetes.Find(paquete.IncidenciaId);
                if (old == null)
                {
                    throw new PaqueteException("El paquete que intentó actualizar no existe.");
                }
                ctx.Entry(old).CurrentValues.SetValues(entity);
                entity = ctx.Paquetes.Find(paquete.IncidenciaId);
                ctx.SaveChanges();
            }
            dto = paqueteConversor.Entity2DTO(entity);
            return(dto);
        }
        public IActionResult SelectAll()
        {
            CarteraDTO query = new CarteraDTO();
            PaqueteDTO pack  = new PaqueteDTO();

            List <CarteraModel> lista = query.SelectAll();

            if (lista != null)
            {
                pack.status = 200;
                pack.msn    = "Success";
                pack.data   = lista.ToArray();
                return(Ok(pack));
            }
            else
            {
                pack.status = 400;
                pack.msn    = "No se encontraron registros";
                return(Ok(pack));
            }
        }
        public IActionResult Delete(int id)
        {
            CarteraDTO query = new CarteraDTO();
            PaqueteDTO pack  = new PaqueteDTO();

            CarteraModel cartera = query.Delete(id);

            if (cartera != null)
            {
                List <CarteraModel> data = new List <CarteraModel>();
                data.Add(cartera);

                pack.status = 200;
                pack.msn    = "Success";
                pack.data   = data.ToArray();
                return(Ok(pack));
            }
            else
            {
                return(BadRequest(pack));
            }
        }
Example #16
0
        public IActionResult SelectByName(string name)
        {
            PersonaDTO p    = new PersonaDTO();
            PaqueteDTO pack = new PaqueteDTO();

            List <PersonaModel> lista = p.SelectByName(name);

            if (lista != null)
            {
                pack.status = 200;
                pack.msn    = "Success";
                pack.data   = lista.ToArray();

                return(Ok(pack));
            }
            else
            {
                pack.status = 400;
                pack.msn    = "No se encontraron resultados con el nombre de " + name;
                return(BadRequest(pack));
            }
        }
Example #17
0
        public IActionResult SelectById(int id)
        {
            PersonaDTO   select = new PersonaDTO();
            PaqueteDTO   pack   = new PaqueteDTO();
            PersonaModel p      = select.SelectById(id);

            if (p != null)
            {
                List <PersonaModel> data = new List <PersonaModel>();
                data.Add(p);
                pack.status = 200;
                pack.msn    = "Success";
                pack.data   = data.ToArray();
                return(Ok(pack));
            }
            else
            {
                pack.status = 400;
                pack.msn    = "No se encontraron resultados con el id " + id;
                return(BadRequest(pack));
            }
        }
Example #18
0
        public IActionResult Update(PersonaModel request)
        {
            PersonaDTO persona = new PersonaDTO();
            PaqueteDTO pack    = new PaqueteDTO();

            PersonaModel upgrade = persona.Update(request);

            if (upgrade != null)
            {
                List <PersonaModel> data = new List <PersonaModel>();
                data.Add(upgrade);
                pack.status = 200;
                pack.msn    = "Success";
                pack.data   = data.ToArray();
                return(Ok(pack));
            }
            else
            {
                pack.status = 400;
                pack.msn    = "La persona no esta registrada";
                return(BadRequest(pack));
            }
        }
Example #19
0
        public IActionResult Delete(int id)
        {
            PaqueteDTO paquete = new PaqueteDTO();
            PersonaDTO p       = new PersonaDTO();

            PersonaModel deletep = p.Delete(id);

            if (deletep != null)
            {
                List <PersonaModel> data = new List <PersonaModel>();
                data.Add(deletep);
                paquete.status = 200;
                paquete.msn    = "Success";
                paquete.data   = data.ToArray();
                return(Ok(paquete));
            }
            else
            {
                paquete.status = 400;
                paquete.msn    = "El id " + id + " no esta registrado";
                return(BadRequest(paquete));
            }
        }
        public IActionResult SelectByForeingKey(int ForeingKey)
        {
            CarteraDTO query = new CarteraDTO();
            PaqueteDTO pack  = new PaqueteDTO();

            CarteraModel c = query.SelectByIdForeig(ForeingKey);

            if (c != null)
            {
                List <CarteraModel> data = new List <CarteraModel>();
                data.Add(c);
                pack.status = 200;
                pack.msn    = "Success";
                pack.data   = data.ToArray();
                return(Ok(pack));
            }
            else
            {
                pack.status = 400;
                pack.msn    = "No se encontraron resultados";
                return(BadRequest(pack));
            }
        }
        public IActionResult Update(CarteraModel c)
        {
            PaqueteDTO pack  = new PaqueteDTO();
            CarteraDTO query = new CarteraDTO();

            CarteraModel upgrade = query.Update(c);

            if (upgrade != null)
            {
                List <CarteraModel> data = new List <CarteraModel>();
                data.Add(upgrade);

                pack.status = 200;
                pack.msn    = "Success";
                pack.data   = data.ToArray();
                return(Ok(pack));
            }
            else
            {
                pack.status = 400;
                pack.msn    = "Error al insertar los datos";
                return(BadRequest(pack));
            }
        }
Example #22
0
 public ActionResult Details(int id)
 {
     try
     {
         var client  = new RestClient(Direcciones.ApiRest + "paquete/detalle");
         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")
         {
             PaqueteDTO paquete = JsonConvert.DeserializeObject <PaqueteDTO>(response.Content);
             return(View(paquete));
         }
         ViewBag.Error = response.Content;
         return(RedirectToAction("index", "paquete"));
     }
     catch (Exception e)
     {
         ViewBag.Error = e.Message;
         return(View());
     }
 }
Example #23
0
        public void ListPaqueteTest()
        {
            PaqueteDTO paquete1 = new PaqueteDTO {
                Color = "rojo", EnvioId = 1, Peso = 10, PaqueteId = 1, Tamanyo = 100
            };

            mockPaqueteRepo.Setup(PaqueteRepo => PaqueteRepo.List())
            .Returns(
                () =>
            {
                IList <PaqueteDTO> listado = new List <PaqueteDTO>();
                listado.Add(new PaqueteDTO {
                    Color = "rojo", EnvioId = 1, Peso = 10, PaqueteId = 1, Tamanyo = 100
                });
                listado.Add(new PaqueteDTO {
                    Color = "rojo", EnvioId = 1, Peso = 10, PaqueteId = 1, Tamanyo = 100
                });
                return(listado);
            }
                );
            IList <PaqueteDTO> lista = sut.List();

            Assert.AreEqual(2, lista.Count);
        }
        public IActionResult Create(CarteraModel c)
        {
            CarteraDTO query = new CarteraDTO();
            PaqueteDTO pack  = new PaqueteDTO();

            CarteraModel insert = query.Insert(c);

            if (insert != null)
            {
                List <CarteraModel> data = new List <CarteraModel>();
                data.Add(insert);

                pack.status = 200;
                pack.msn    = "Success";
                pack.data   = data.ToArray();
                return(Ok(pack));
            }
            else
            {
                pack.status = 400;
                pack.msn    = "No se encontraron resultados";
                return(BadRequest(pack));
            }
        }
Example #25
0
 public PaqueteDTO Update(PaqueteDTO paquete)
 {
     return(_paqueteRepository.Update(paquete));
 }
Example #26
0
 // POST api/paquete
 public PaqueteDTO Post(PaqueteDTO value)
 {
     return(_paqueteService.Create(value));
 }
Example #27
0
 public PaqueteDTO Create(PaqueteDTO paquete)
 {
     return(_paqueteRepository.Create(paquete));
 }
Example #28
0
 // PUT api/values/5
 public PaqueteDTO Put(int id, PaqueteDTO value)
 {
     value.IncidenciaId = id;
     return(_paqueteService.Update(value));
 }
Example #29
0
 public ActionResult imprimirpdf(int id)
 {
     try
     {
         var client  = new RestClient(Direcciones.ApiRest + "paquete/detalle");
         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")
         {
             PaqueteDTO paq = JsonConvert.DeserializeObject <Models.PaqueteDTO>(response.Content);
             int        idOrigen = 0, idDestino = 0;
             paq.Trayecto.ListaPuntosControl.ForEach(x =>
             {
                 if (x.Orden == 1)
                 {
                     idOrigen = (int)x.IdAgencia;
                 }
                 if (x.Orden == (paq.Trayecto.ListaPuntosControl.Count - 1))
                 {
                     idDestino = (int)x.IdAgencia;
                 }
             });
             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);
             request.AddQueryParameter("id", idOrigen.ToString());
             response = client.Execute(request);
             if (response.StatusCode.ToString() == "OK")
             {
                 Agencia origen = JsonConvert.DeserializeObject <Agencia>(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);
                 request.AddQueryParameter("id", idDestino.ToString());
                 response = client.Execute(request);
                 if (response.StatusCode.ToString() == "OK")
                 {
                     Agencia destino = JsonConvert.DeserializeObject <Agencia>(response.Content);
                     PDF     pdf     = new PDF();
                     System.Drawing.Image  imagen   = GenerateQRCode(id.ToString(), 160);
                     iTextSharp.text.Image imagenQR = iTextSharp.text.Image.GetInstance(imagen, System.Drawing.Imaging.ImageFormat.Png);
                     byte[] res = pdf.PrepararReport(paq, imagenQR, origen, destino, id);
                     return(File(res, "application/pdf"));
                 }
                 throw new ECompartida(response.Content);
             }
             throw new ECompartida(response.Content);
         }
         throw new ECompartida(response.Content);
     }
     catch (Exception e)
     {
         ViewBag.ERROR = e;
         return(View());
     }
 }