Ejemplo n.º 1
0
        public IHttpActionResult Put(int id, Importacion a_modificar)
        {
            if (id != a_modificar.Id)
            {
                return(BadRequest());
            }

            try
            {
                using (MiContextoContext db = new MiContextoContext())
                {
                    int cantidad = db.importaciones.Count(p => p.Id == id);
                    if (cantidad == 0)
                    {
                        return(NotFound());
                    }

                    db.Entry(a_modificar).State = EntityState.Modified;
                    db.SaveChanges();

                    return(Ok(a_modificar));
                }
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
Ejemplo n.º 2
0
        public IHttpActionResult Get(int id)
        {
            Importacion impor = null;

            try
            {
                using (MiContextoContext db = new MiContextoContext())
                {
                    impor = db.importaciones.Include(i => i.Producto)
                            .Include(i => i.Producto.Cliente)
                            .Where(i => i.Id == id)
                            .FirstOrDefault();
                    if (impor == null)
                    {
                        return(NotFound());
                    }
                }
            }
            catch
            {
                return(InternalServerError());
            }

            return(Ok(impor));
        }
Ejemplo n.º 3
0
        public ActionResult Create(NuevaImportacionViewModel nuevo)
        {
            if (Session["cedula"] != null)
            {
                Importacion nuevaImportacion = new Importacion();
                bool        existe           = false;

                using (MiContextoContext db = new MiContextoContext())
                {
                    var listaProds = db.Productos
                                     .Join(db.Clientes, prod => prod.Cliente.Id, c => c.Id, (prod, c) => new { prod, c })
                                     .Where(e => e.prod.Codigo == nuevo.CodigoProd).FirstOrDefault();
                    if (listaProds != null)
                    {
                        nuevaImportacion.Producto = listaProds.prod;
                        existe = true;
                    }
                }
                if (existe)
                {
                    nuevaImportacion.Cantidad            = nuevo.Cantidad;
                    nuevaImportacion.FechaIngreso        = nuevo.FechaIngreso;
                    nuevaImportacion.FechaSalidaPrevista = nuevo.FechaSalidaPrevista;
                    nuevaImportacion.PrecioPorUnidad     = nuevo.PrecioPorUnidad;
                    try
                    {
                        Uri uri = new Uri(url + "/Post/");

                        HttpClient cliente = new HttpClient();

                        Task <HttpResponseMessage> tarea = cliente.PostAsJsonAsync(uri, nuevaImportacion);
                        tarea.Wait();

                        if (!tarea.Result.IsSuccessStatusCode)
                        {
                            ViewBag.Error = tarea.Result.StatusCode;
                            return(View(nuevo));
                        }
                        else
                        {
                            return(RedirectToAction("Index"));
                        }
                    }
                    catch
                    {
                        return(View(nuevo));
                    }
                }
                else
                {
                    ViewBag.Mensaje = "No existe producto con tal codigo";
                    return(View(nuevo));
                }
            }
            else
            {
                return(Redirect("/home/Index"));
            }
        }
Ejemplo n.º 4
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            using (MiContextoContext db = new MiContextoContext())
            {
                db.Database.CreateIfNotExists();
            }
        }
Ejemplo n.º 5
0
        public IHttpActionResult GetByProdName(string prodName)
        {
            List <Importacion> lstImportacion = new List <Importacion>();

            try
            {
                using (MiContextoContext db = new MiContextoContext())
                {
                    lstImportacion = db.importaciones
                                     .Include(i => i.Producto)
                                     .Include(i => i.Producto.Cliente)
                                     .Where(i => i.Producto.Nombre.Contains(prodName))
                                     .ToList();
                }
            }
            catch
            {
                return(InternalServerError());
            }
            return(Ok(lstImportacion));
        }
Ejemplo n.º 6
0
        public IHttpActionResult GetByClientRut(string clientRut)
        {
            List <Importacion> lstImportacion = new List <Importacion>();

            try
            {
                using (MiContextoContext db = new MiContextoContext())
                {
                    lstImportacion = db.importaciones
                                     .Include(i => i.Producto)
                                     .Include(i => i.Producto.Cliente)
                                     .Where(i => i.Producto.Cliente.Rut == clientRut)
                                     .ToList();
                }
            }
            catch
            {
                return(InternalServerError());
            }
            return(Ok(lstImportacion));
        }
Ejemplo n.º 7
0
        public IHttpActionResult Post(Importacion nuevo)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            try
            {
                using (MiContextoContext db = new MiContextoContext())
                {
                    db.importaciones.Add(nuevo);
                    db.SaveChanges();
                }
            }
            catch
            {
                return(InternalServerError());
            }
            return(Created("api/productos/" + nuevo.Id, nuevo));
        }
Ejemplo n.º 8
0
        public IHttpActionResult GetByDate()
        {
            List <Importacion> lstImportacion = new List <Importacion>();

            try
            {
                using (MiContextoContext db = new MiContextoContext())
                {
                    lstImportacion = db.importaciones
                                     .Include(i => i.Producto)
                                     .Include(i => i.Producto.Cliente)
                                     .Where(i => i.FechaSalidaPrevista < DateTime.Today && i.FechaSalidaReal == null)
                                     .ToList();
                }
            }
            catch
            {
                return(InternalServerError());
            }
            return(Ok(lstImportacion));
        }