コード例 #1
0
        public async Task <ActionResult> Nuevo(tblViajesViajeros tblViajesViajeros)
        {
            // TODO: Add insert logic here
            var httpClient = new HttpClient();
            var Json       = await httpClient.GetStringAsync(ConfigurationManager.AppSettings["Viajeros"].ToString());

            var Viajero = JsonConvert.DeserializeObject <List <tblViajeros> >(Json);

            Viajero = Viajero.Where(c => c.Cedula == tblViajesViajeros.Cedula).ToList();

            if (Viajero.Count > 0)
            {
                try
                {
                    var contet = httpClient.PostAsJsonAsync <tblViajesViajeros>(ConfigurationManager.AppSettings["ViajerosViajes"].ToString(), tblViajesViajeros);

                    return(RedirectToAction("Lista"));
                }
                catch (Exception e)
                {
                    return(View(e.Message));
                }
            }
            else
            {
                Json = await httpClient.GetStringAsync(ConfigurationManager.AppSettings["Viajes"].ToString());

                var ListaViajes = JsonConvert.DeserializeObject <List <tblViajes> >(Json);
                ViewBag.CodigoViaje = new SelectList(ListaViajes, "CodigoViaje", "Destino");
                ModelState.AddModelError("Cedula", "cedula no esta registrada por favor registre");
                return(View());
            }
        }
コード例 #2
0
        public IHttpActionResult PosttblViajesViajeros(tblViajesViajeros tblViajesViajeros)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.tblViajesViajeros.Add(tblViajesViajeros);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateException)
            {
                if (tblViajesViajerosExists(tblViajesViajeros.IdViajes))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtRoute("DefaultApi", new { id = tblViajesViajeros.IdViajes }, tblViajesViajeros));
        }
コード例 #3
0
        public IHttpActionResult PuttblViajesViajeros(int id, tblViajesViajeros tblViajesViajeros)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != tblViajesViajeros.IdViajes)
            {
                return(BadRequest());
            }

            db.Entry(tblViajesViajeros).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!tblViajesViajerosExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
コード例 #4
0
        public IHttpActionResult GettblViajesViajeros(int id)
        {
            tblViajesViajeros tblViajesViajeros = db.tblViajesViajeros.Find(id);

            if (tblViajesViajeros == null)
            {
                return(NotFound());
            }

            return(Ok(tblViajesViajeros));
        }
コード例 #5
0
        public IHttpActionResult DeletetblViajesViajeros(int id)
        {
            tblViajesViajeros tblViajesViajeros = db.tblViajesViajeros.Find(id);

            if (tblViajesViajeros == null)
            {
                return(NotFound());
            }

            db.tblViajesViajeros.Remove(tblViajesViajeros);
            db.SaveChanges();

            return(Ok(tblViajesViajeros));
        }
コード例 #6
0
        public ActionResult Editar(int id, tblViajesViajeros tblViajesViajeros)
        {
            try
            {
                // TODO: Add update logic here
                var httpClient = new HttpClient();
                var contet     = httpClient.PutAsJsonAsync <tblViajesViajeros>(ConfigurationManager.AppSettings["Viajes"].ToString() + id, tblViajesViajeros);

                return(RedirectToAction("Lista"));
            }
            catch (Exception ex)
            {
                return(View(ex));
            }
        }
コード例 #7
0
        public async Task <ActionResult> Eliminar(int id, tblViajesViajeros tblViajesViajeros)
        {
            try
            {
                // TODO: Add delete logic here
                var httpClient = new HttpClient();
                var Json       = await httpClient.DeleteAsync(ConfigurationManager.AppSettings["ViajerosViajes"].ToString() + id);

                return(RedirectToAction("Lista"));
            }
            catch (Exception e)
            {
                return(View(e));
            }
        }