예제 #1
0
        public async Task <ActionResult> DeleteConfirmed(int id)
        {
            EstadoModels estadoModels = await db.Estado.FindAsync(id);

            db.Estado.Remove(estadoModels);
            await db.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
예제 #2
0
        public async Task <ActionResult> Edit([Bind(Include = "Id,Nome,Sigla")] EstadoModels estadoModels)
        {
            if (ModelState.IsValid)
            {
                db.Entry(estadoModels).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(estadoModels));
        }
예제 #3
0
        public async Task <ActionResult> Create([Bind(Include = "Id,Nome,Sigla")] EstadoModels estadoModels)
        {
            if (ModelState.IsValid)
            {
                db.Estado.Add(estadoModels);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            return(View(estadoModels));
        }
예제 #4
0
        // GET: Estado/Delete/5
        public async Task <ActionResult> Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            EstadoModels estadoModels = await db.Estado.FindAsync(id);

            if (estadoModels == null)
            {
                return(HttpNotFound());
            }
            return(View(estadoModels));
        }
예제 #5
0
        public HttpResponseMessage GetListEstado()
        {
            HttpResponseMessage retorno    = new HttpResponseMessage();
            string connectionString        = ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString;
            List <EstadoModels> listEstado = new List <EstadoModels>();

            try
            {
                using (MySqlConnection conn = new MySqlConnection(connectionString))
                {
                    MySqlCommand comando = new MySqlCommand("SELECT EST.ID, EST.NOME, EST.SIGLA FROM TB_ESTADO EST", conn);

                    try
                    {
                        conn.Open();
                        MySqlDataReader rdr = comando.ExecuteReader();

                        while (rdr.Read())
                        {
                            EstadoModels userEstado = new EstadoModels();
                            userEstado.id    = Convert.ToInt32(rdr[0].ToString());
                            userEstado.nome  = rdr[1].ToString();
                            userEstado.sigla = rdr[2].ToString();

                            listEstado.Add(userEstado);
                        }

                        return(Request.CreateResponse(HttpStatusCode.OK, listEstado));
                    }
                    catch (Exception e)
                    {
                        return(Request.CreateResponse(HttpStatusCode.ExpectationFailed, "Houve um erro ao listar os Estados."));
                    }
                    finally
                    {
                        conn.Close();
                    }
                }
            }
            catch (Exception e)
            {
                return(Request.CreateResponse(HttpStatusCode.ExpectationFailed, "Falha ao conectar no servidor: " + e.Message));
            }
        }