public async Task <ActionResult> Actualizar() { Assembly asm = Assembly.GetAssembly(typeof(WebComunidad.MvcApplication)); var controlleractionlist = asm.GetTypes() .Where(type => typeof(System.Web.Mvc.Controller).IsAssignableFrom(type)) .SelectMany( type => type.GetMethods(BindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.Public)) .Where( m => !m.GetCustomAttributes(typeof(System.Runtime.CompilerServices.CompilerGeneratedAttribute), true) .Any()) .Select( x => new { Controller = x.DeclaringType.Name, Action = x.Name, ReturnType = x.ReturnType.Name, Attributes = String.Join(",", x.GetCustomAttributes().Select(a => a.GetType().Name.Replace("Attribute", ""))) }) .Where(x => x.Attributes.Contains("Authorize")) .OrderBy(x => x.Controller).ThenBy(x => x.Action).ToList() .Select(z => new { Controller = z.Controller, Action = z.Action, }).Distinct(); List <AspNetRole> listRolesAAgregar = new List <AspNetRole>(); var rolesDb = db.AspNetRoles.ToList(); int maxId = Convert.ToInt32(rolesDb.Max(ro => Convert.ToInt32(ro.Id))); foreach (var r in controlleractionlist) { maxId = maxId + 1; AspNetRole rol = new AspNetRole(); rol.Name = r.Controller + r.Action; rol.Id = maxId.ToString(); if (!rolesDb.Exists(rrr => rrr.Name == rol.Name)) { db.Entry(rol).State = EntityState.Added; db.AspNetRoles.Add(rol); } } db.SaveChanges(); TempData["MsjExito"] = "Roles Actualizados Con Exito"; return(RedirectToAction("Index", "Roles")); }
public ActionResult ModificarTarjeta(Models.Socios.CambioTarjetaModels m) { using (var dbTransaction = db.Database.BeginTransaction()) { try { var t = db.tarjeta_socio.Find(m.TarjetaNueva.id); if (t.socio_id != null || t.fecha_baja != null) { TempData["MsjError"] = "La Tarjeta se encuentra Utilizada"; return(RedirectToAction("CambioTarjeta", new { idSocio = m.Socio.id })); } tarjeta_socio tVieja = db.socios.Find(m.Socio.id).TarjetaActual; if (tVieja != null && tVieja.id != 0) { tVieja.activada = false; tVieja.fecha_baja = DateTime.Now; db.Entry(tVieja).State = EntityState.Modified; } t.activada = true; t.socio_id = m.Socio.id; db.Entry(t).State = EntityState.Modified; db.SaveChanges(); dbTransaction.Commit(); TempData["MsjExito"] = "Tarjeta Cambiada Con Exito"; return(RedirectToAction("CambioTarjeta", new { idSocio = m.Socio.id })); } catch (Exception ex) { dbTransaction.Rollback(); TempData["MsjError"] = ex.Message; return(RedirectToAction("CambioTarjeta", new { idSocio = m.Socio.id })); } } }