Beispiel #1
0
        public ActionResult Create([Bind(Include = "TipoImovelID,NomeTipo")] TipoImovel tipoImovel)
        {
            if (ModelState.IsValid)
            {
                db.TiposImovel.Add(tipoImovel);
                db.SaveChanges();
                try
                {
                    string str   = Request["pai"];
                    int    PaiId = int.Parse(str);
                    if (PaiId > 0)
                    {
                        TipoImovel TipoPai = db.TiposImovel.Find(PaiId);
                        if (TipoPai != null)
                        {
                            TipoPai.SubTipos.Add(tipoImovel);
                            db.Entry(tipoImovel).State = EntityState.Modified;
                            db.SaveChanges();
                        }
                    }
                }
                catch (Exception) {}
                return(RedirectToAction("Index"));
            }

            return(View(tipoImovel));
        }
Beispiel #2
0
 public ActionResult Editar(int id, TipoImovel tipoImovel)
 {
     using (TipoImovelConnection tipoImovels = new TipoImovelConnection())
     {
         tipoImovels.Update(id, tipoImovel);
         return(RedirectToAction("Index", "TipoImovel"));
     }
 }
Beispiel #3
0
 public ActionResult Cadastrar(TipoImovel estado)
 {
     using (TipoImovelConnection tipoImovel = new TipoImovelConnection())
     {
         tipoImovel.Create(estado);
         return(RedirectToAction("Index", "TipoImovel"));
     }
 }
Beispiel #4
0
        public ActionResult DeleteConfirmed(int id)
        {
            TipoImovel tipoImovel = db.TiposImovel.Find(id);

            db.TiposImovel.Remove(tipoImovel);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Beispiel #5
0
 public ActionResult Apagar(int id, TipoImovel estado)
 {
     using (TipoImovelConnection tipoImovel = new TipoImovelConnection())
     {
         tipoImovel.Delete(id);
         return(RedirectToAction("Index", "TipoImovel"));
     }
 }
Beispiel #6
0
 public ActionResult Editar(int id)
 {
     using (TipoImovelConnection tipoImovel = new TipoImovelConnection())
     {
         ViewBag.Status = Enum.GetValues(typeof(Status));
         TipoImovel estado = tipoImovel.Read(id);
         return(View(estado));
     }
 }
Beispiel #7
0
        public void Create(TipoImovel tipoImovel)
        {
            SqlCommand cmd = new SqlCommand();

            cmd.Connection  = connection;
            cmd.CommandText = @"INSERT INTO Tipos_Imoveis VALUES(@Nome, @Status)";
            cmd.Parameters.AddWithValue("@Nome", tipoImovel.Nome);
            cmd.Parameters.AddWithValue("@Status", tipoImovel.Status);
            cmd.ExecuteNonQuery();
        }
 public ActionResult Inserir(TipoImovel tipoImovel)
 {
     if (ModelState.IsValid)
     {
         db.TipoImovel.Add(tipoImovel);
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(tipoImovel));
 }
Beispiel #9
0
 public ActionResult Edit([Bind(Include = "TipoImovelID,NomeTipo")] TipoImovel tipoImovel)
 {
     if (ModelState.IsValid)
     {
         db.Entry(tipoImovel).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(tipoImovel));
 }
 public ActionResult Alterar(TipoImovel tipoImovel)
 {
     if (ModelState.IsValid)
     {
         db.Entry(tipoImovel).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(tipoImovel));
 }
Beispiel #11
0
 public Imovel(int cod_imovel, float metro_quadrado, string descricao, int numero_quartos, int numero_banheiros, TipoImovel tipoImovel, int proprietarioRefId, int enderecoRefId)
 {
     this.cod_imovel       = cod_imovel;
     this.metro_quadrado   = metro_quadrado;
     this.descricao        = descricao;
     this.numero_quartos   = numero_quartos;
     this.numero_banheiros = numero_banheiros;
     _tipoImovel           = tipoImovel;
     ProprietarioRefId     = proprietarioRefId;
     EnderecoRefId         = enderecoRefId;
 }
Beispiel #12
0
        public void Update(int id, TipoImovel tipoImovel)
        {
            SqlCommand cmd = new SqlCommand();

            cmd.Connection  = connection;
            cmd.CommandText = @"UPDATE Tipos_Imoveis SET nome = @nome, status = @status WHERE id = @id";
            cmd.Parameters.AddWithValue("@id", id);
            cmd.Parameters.AddWithValue("@nome", tipoImovel.Nome);
            cmd.Parameters.AddWithValue("@status", tipoImovel.Status);
            cmd.ExecuteNonQuery();
        }
Beispiel #13
0
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            TipoImovel tipoImovel = db.TiposImovel.Find(id);

            if (tipoImovel == null)
            {
                return(HttpNotFound());
            }
            return(View(tipoImovel));
        }
 public ActionResult EfetuarExclusao(int id)
 {
     try
     {
         TipoImovel tipoImovel = db.TipoImovel.Find(id);
         db.TipoImovel.Remove(tipoImovel);
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     catch
     {
         return(RedirectToAction("ErroExcluir"));
     }
 }
Beispiel #15
0
 public ActionResult Apagar(int id)
 {
     using (TipoImovelConnection tipoImovel = new TipoImovelConnection())
     {
         if (tipoImovel.Check(id))
         {
             ViewBag.Status = Enum.GetValues(typeof(Status));
             TipoImovel tipoImovels = tipoImovel.Read(id);
             return(View(tipoImovels));
         }
         TempData["Erro"] = "O Tipo de Imovel está em uso e não pode ser Excluido!!!";
         return(RedirectToAction("Index", "TipoImovel"));
     }
 }
Beispiel #16
0
        public TipoImovel Read(int id)
        {
            TipoImovel tipoImovel = new TipoImovel();
            SqlCommand cmd        = new SqlCommand();

            cmd.Connection  = connection;
            cmd.CommandText = @"SELECT * FROM Tipos_Imoveis WHERE id = @id";
            cmd.Parameters.AddWithValue("@id", id);
            SqlDataReader reader = cmd.ExecuteReader();

            if (reader.Read())
            {
                tipoImovel.Id     = (int)reader["id"];
                tipoImovel.Nome   = (string)reader["nome"];
                tipoImovel.Status = (Status)reader["status"];
            }
            return(tipoImovel);
        }
Beispiel #17
0
        public List <TipoImovel> ReadAll()
        {
            List <TipoImovel> lista = new List <TipoImovel>();
            SqlCommand        cmd   = new SqlCommand();

            cmd.Connection  = connection;
            cmd.CommandText = @"select * from Tipos_Imoveis order by nome";
            SqlDataReader reader = cmd.ExecuteReader();

            while (reader.Read())
            {
                TipoImovel tipoImovel = new TipoImovel();
                tipoImovel.Id     = (int)reader["id"];
                tipoImovel.Nome   = (string)reader["nome"];
                tipoImovel.Status = (Status)reader["status"];
                lista.Add(tipoImovel);
            }
            return(lista);
        }
        public ActionResult Excluir(int id)
        {
            TipoImovel tipoImovel = db.TipoImovel.Find(id);

            return(View(tipoImovel));
        }