public ActionResult Delete(int id) { Tb_Plantillas tb_plantilla = db.Tb_Plantillas.Find(id); db.Tb_Plantillas.Remove(tb_plantilla); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult CrearPlantilla(List <Tb_ActividadesDetalles> detalles, string nombre, string descripcion) { try { Tb_Plantillas nuevaPlantilla = new Tb_Plantillas(); nuevaPlantilla.Fecha_creacion = DateTime.UtcNow; nuevaPlantilla.Nombre = nombre; nuevaPlantilla.Descripcion = descripcion; nuevaPlantilla.ID_usuario = 1; db.Tb_Plantillas.Add(nuevaPlantilla); db.SaveChanges(); if (detalles != null) { foreach (var item in detalles) { if (item.Descripcion == null) { item.Descripcion = ""; } if (item.ValorTexto == null) { item.ValorTexto = ""; } if (item.ValorMultipleOpciones == null) { item.ValorMultipleOpciones = ""; } item.ID_plantilla = nuevaPlantilla.ID_plantilla; } db.Tb_ActividadesDetalles.AddRange(detalles); db.SaveChanges(); } var result = new { mensaje = "success" }; return(Json(result, JsonRequestBehavior.AllowGet)); } catch { var result = new { mensaje = "error" }; return(Json(result, JsonRequestBehavior.AllowGet)); } }