コード例 #1
0
        // Activar
        public ActionResult Activar(int tipo, int id)
        {
            SistemaEmprendedorEntities bd = new SistemaEmprendedorEntities();
            ActionResponses            ar = null;
            string msg = null;

            if (tipo == 1)
            {
                Evento EventoActivar = bd.Evento.Where(x => x.id == id).Select(x => x).FirstOrDefault();
                if (EventoActivar != null)
                {
                    try
                    {
                        EventoActivar.estatus         = 2;
                        bd.Entry(EventoActivar).State = System.Data.Entity.EntityState.Modified;
                        bd.SaveChanges();
                    }
                    catch (Exception ex)
                    {
                        msg = "Existe un problema al activar este evento, consulta al administrador";
                        ar  = new ActionResponses(ResponseType.ERROR, msg);
                        ViewBag.ActionResponses = ar;
                        TempData["Message"]     = ar;
                        return(RedirectToAction("AdministrarEventos", "Manage"));
                    }
                    msg = "Evento activado correctamente";
                    ar  = new ActionResponses(ResponseType.SUCCESS, msg);
                    ViewBag.ActionResponses = ar;
                    TempData["Message"]     = ar;
                    return(RedirectToAction("AdministrarEventos", "Manage"));
                }
            }

            return(RedirectToAction("Index", "Home"));
        }
コード例 #2
0
        // Eliminar
        public ActionResult Eliminar(int tipo, int id)
        {
            SistemaEmprendedorEntities bd    = new SistemaEmprendedorEntities();
            ActionResponses            ar    = null;
            ManageCatalogo             model = new ManageCatalogo();
            string msg = null;

            if (tipo == 1)
            {
                Evento EventoBorrar = bd.Evento.Where(x => x.id == id).Select(x => x).FirstOrDefault();
                if (EventoBorrar != null)
                {
                    try {
                        model.ListaAsistentesDeEventos = bd.RegistroAEvento.Where(x => x.IdEvento == id).Select(x => x).ToList();
                        if (model.ListaAsistentesDeEventos != null)
                        {
                            foreach (var Asistente in model.ListaAsistentesDeEventos)
                            {
                                bd.Entry(Asistente).State = System.Data.Entity.EntityState.Deleted;
                                bd.SaveChanges();
                            }
                        }
                        bd.Entry(EventoBorrar).State = System.Data.Entity.EntityState.Deleted;
                        bd.SaveChanges();
                    }
                    catch (Exception ex) {
                        msg = "Existe un problema al eliminar este evento, consulta al administrador";
                        ar  = new ActionResponses(ResponseType.ERROR, msg);
                        ViewBag.ActionResponses = ar;
                        TempData["Message"]     = ar;
                        return(RedirectToAction("AdministrarEventos", "Manage"));
                    }
                    msg = "Evento eliminado correctamente";
                    ar  = new ActionResponses(ResponseType.SUCCESS, msg);
                    ViewBag.ActionResponses = ar;
                    TempData["Message"]     = ar;
                    return(RedirectToAction("AdministrarEventos", "Manage"));
                }
            }

            return(RedirectToAction("Index", "Home"));
        }