public ActionResult Edit(Status s)
        {
            if (Roles.IsUserInRole(User.Identity.Name, "Administrador"))
            {
                if (!validarStatus(s))
                {
                    ViewBag.Erro = "Erro na validação do Status";
                    return View(s);
                }

                string erro = null;
                if (s.idStatus == 0)
                {
                    erro = statusModel.adicionarStatus(s);
                }
                else
                {
                    erro = statusModel.editarStatus(s);
                }
                if (erro == null)
                {
                    return RedirectToAction("Index");
                }
                else
                {
                    ViewBag.Erro = erro;
                    return View(s);
                }
            }
            return Redirect("/Shared/Restrito");
        }
예제 #2
0
 public string adicionarStatus(Status s)
 {
     string erro = null;
     try
     {
         db.Status.AddObject(s);
         db.SaveChanges();
     }
     catch (Exception ex)
     {
         erro = ex.Message;
     }
     return erro;
 }
예제 #3
0
        public string excluirStatus(Status s)
        {
            string erro = null;

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

                if (id != 0)
                {
                    s = statusModel.obterStatus(id);
                    ViewBag.Titulo = "Editar Status";
                }

                return View(s);
            }
            return Redirect("/Shared/Restrito");
        }
예제 #5
0
        public string editarStatus(Status s)
        {
            string erro = null;

            try
            {
                if (s.EntityState == System.Data.EntityState.Detached)
                {
                    db.Status.Attach(s);
                }
                db.ObjectStateManager.ChangeObjectState(s,
                    System.Data.EntityState.Modified);
                db.SaveChanges();
            }
            catch (Exception ex)
            {
                erro = ex.Message;
            }
            return erro;
        }
 /// <summary>
 /// Deprecated Method for adding a new object to the Status EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToStatus(Status status)
 {
     base.AddObject("Status", status);
 }
 /// <summary>
 /// Create a new Status object.
 /// </summary>
 /// <param name="idStatus">Initial value of the idStatus property.</param>
 /// <param name="descricao">Initial value of the Descricao property.</param>
 public static Status CreateStatus(global::System.Int32 idStatus, global::System.String descricao)
 {
     Status status = new Status();
     status.idStatus = idStatus;
     status.Descricao = descricao;
     return status;
 }
        private bool validarStatus(Status status)
        {
            if (status.Descricao == "")
                return false;

            return true;
        }