コード例 #1
0
 public ActionResult AgregarCategoria(CategoriaPregunta model)
 {
     if (ModelState.IsValid)
     {
         categoria.nombre     = model.nombre.Trim();
         categoria.comentario = model.comentario.Trim();
         var verificar = context.CategoriaPreguntas.Where(x => x.nombre == categoria.nombre).ToList();
         if (verificar.Count > 0)
         {
             alerta = new string[] { "simple", "info", "Atención", "Ya existe esta categoría" };
         }
         else
         {
             context.CategoriaPreguntas.Add(categoria);
             if (context.SaveChanges() > 0)
             {
                 alerta = new string[] { "clean", "success", "Exito", "Se ha añadido exitosamente la categoría" };
             }
             else
             {
                 alerta = new string[] { "simple", "error", "Lo sentimos", "Se ha generado un error intentelo de nuevo" };
             }
         }
         return(JavaScript(sweet.SweetAlert(alerta)));
     }
     return(Content(respuesta));
 }