public ActionResult Edit(Tipo tt)
        {
            if (Roles.IsUserInRole(User.Identity.Name, "Administrador"))
            {

                if (!validarTipo(tt))
                {
                    ViewBag.Erro = "Erro na validação do Tipo";
                    return View(tt);
                }

                string erro = null;
                if (tt.idTipo == 0)
                {
                    erro = tipoModel.adicionarTipo(tt);
                }
                else
                {
                    erro = tipoModel.editarTipo(tt);
                }
                if (erro == null)
                {
                    return RedirectToAction("Index");
                }
                else
                {
                    ViewBag.Erro = erro;
                    return View(tt);
                }
            }
            return Redirect("/Shared/Restrito");
        }
Exemplo n.º 2
0
 public string adicionarTipo(Tipo t)
 {
     string erro = null;
     try
     {
         db.Tipo.AddObject(t);
         db.SaveChanges();
     }
     catch (Exception ex)
     {
         erro = ex.Message;
     }
     return erro;
 }
Exemplo n.º 3
0
        public string excluirTipo(Tipo t)
        {
            string erro = null;

            try
            {
                db.DeleteObject(t);
                db.SaveChanges();
            }
            catch (Exception ex)
            {
                erro = ex.Message;
            }
            return erro;
        }
        public ActionResult Edit(int id)
        {
            if (Roles.IsUserInRole(User.Identity.Name, "Administrador"))
            {
                Tipo tt = new Tipo();
                ViewBag.Titulo = "Novo Tipo";

                if (id != 0)
                {
                    tt = tipoModel.obterTipo(id);
                    ViewBag.Titulo = "Editar Tipo";
                }

                return View(tt);
            }
            return Redirect("/Shared/Restrito");
        }
Exemplo n.º 5
0
 public string editarTipo(Tipo t)
 {
     string erro = null;
     try
     {
         if (t.EntityState == System.Data.EntityState.Detached)
         {
             db.Tipo.Attach(t);
         }
         db.ObjectStateManager.ChangeObjectState(t,
             System.Data.EntityState.Modified);
         db.SaveChanges();
     }
     catch (Exception ex)
     {
         erro = ex.Message;
     }
     return erro;
 }
 /// <summary>
 /// Deprecated Method for adding a new object to the Tipo EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToTipo(Tipo tipo)
 {
     base.AddObject("Tipo", tipo);
 }
 /// <summary>
 /// Create a new Tipo object.
 /// </summary>
 /// <param name="idTipo">Initial value of the idTipo property.</param>
 /// <param name="descricao">Initial value of the Descricao property.</param>
 public static Tipo CreateTipo(global::System.Int32 idTipo, global::System.String descricao)
 {
     Tipo tipo = new Tipo();
     tipo.idTipo = idTipo;
     tipo.Descricao = descricao;
     return tipo;
 }
        private bool validarTipo(Tipo tipo)
        {
            if (tipo.Descricao == "")
                return false;

            return true;
        }