public void Create(CreateClaimInfoModel model) { var claimInfo = new ClaimInfo() { Issuer = model.Issuer, ClaimType = model.ClaimType, Value = model.Value, MethodTypeValue = model.MethodTypeValue }; Context.ClaimInfos.Add(claimInfo); Context.SaveChanges(); }
// GET: ClaimAdmin //public ActionResult Index() //{ // return View(); //} public ActionResult Index() { var abs = Assembly.GetExecutingAssembly(); var ts = abs.GetTypes(); var list = new List <CreateClaimInfoModel>(); foreach (Type type in ts) { if (type.BaseType != null && type.BaseType == typeof(Controller)) { var ms = type.GetMethods(); foreach (MethodInfo methodInfo in ms) { foreach (var methodAttribute in methodInfo.CustomAttributes) { #region MyRegion //if (methodAttribute.AttributeType == typeof(DescriperAttribute)) //{ // var nas = methodAttribute.NamedArguments; // if (nas != null) // foreach (CustomAttributeNamedArgument namedArgument in nas) // { // Console.WriteLine("CustomAttributeNamedArgument:"); // Console.WriteLine("name:" + namedArgument.MemberName + "||value:" + namedArgument.TypedValue.Value); // } //} //else #endregion if (methodAttribute.AttributeType == typeof(ClaimsAccessAttribute)) { #region MyRegion var nas = methodAttribute.NamedArguments; if (nas != null) { var claimIfo = new CreateClaimInfoModel(); foreach (CustomAttributeNamedArgument namedArgument in nas) { //Console.WriteLine("MyAttribute:"); //Console.WriteLine("name:" + namedArgument.MemberName + "||value:" + namedArgument.TypedValue.Value); if (namedArgument.MemberName.Equals("Issuer")) { claimIfo.Issuer = (string)namedArgument.TypedValue.Value; } else if (namedArgument.MemberName.Equals("ClaimType")) { claimIfo.ClaimType = (string)namedArgument.TypedValue.Value; } else if (namedArgument.MemberName.Equals("Value")) { claimIfo.Value = (string)namedArgument.TypedValue.Value; } else if (namedArgument.MemberName.Equals("MethodTypeValue")) { claimIfo.MethodTypeValue = (MethodType)namedArgument.TypedValue.Value; } } list.Add(claimIfo); } #endregion } } } } } //todo 存在问题:只能在第一次初始插入claim if (ClaimInfoManager.GetClaimInfos().Count == 0) { ClaimInfoManager.Create(list); } //return View(list); var list1 = ClaimInfoManager.Entitys().Include(p => p.AppRoles).ToList(); return(View(list1)); }