Пример #1
0
        public ActionResult AdicionarTelefone(TelefoneViewModel model)
        {
            if (ModelState.IsValid)
            {
                var telefone = model.Update();
                if (telefone != null)
                {
                    telefone.UsuarioId = User.Identity.GetUserId <int>();
                    db.Telefone.Add(telefone);
                    db.SaveChanges();
                    TempData["Alerta"] = "Criado com sucesso";
                    TempData["Classe"] = "green-alert";
                }
                else
                {
                    TempData["Alerta"] = "Algo deu errado";
                    TempData["Classe"] = "yellow-alert";
                }
            }
            else
            {
                TempData["Alerta"] = "Formulário inválido";
                TempData["Classe"] = "yellow-alert";
            }

            return(RedirectToAction("Index"));
        }
Пример #2
0
 public ActionResult EditarTelefone([Bind(Prefix = "Item2")] TelefoneViewModel model)
 {
     if (ModelState.IsValid)
     {
         var telefone = model.Update();
         if (telefone != null)
         {
             if (User.Identity.GetUserId <int>() == telefone.UsuarioId)
             {
                 db.Entry(telefone).State = System.Data.Entity.EntityState.Modified;
                 db.SaveChanges();
                 TempData["Alerta"] = "Atualizado com sucesso";
                 TempData["Classe"] = "green-alert";
                 return(RedirectToAction("Index"));
             }
             else
             {
                 TempData["Alerta"] = "Você não pode executar esta ação";
                 TempData["Classe"] = "yellow-alert";
                 return(RedirectToAction("Inicio", "Home"));
             }
         }
         else
         {
             TempData["Alerta"] = "Algo deu errado";
             TempData["Classe"] = "yellow-alert";
             return(RedirectToAction("Index"));
         }
     }
     else
     {
         TempData["Alerta"] = "Formulário Inválido";
         TempData["Classe"] = "yellow-alert";
         return(RedirectToAction("Index"));
     }
 }