// POST: api/GgcmsCategories public IHttpActionResult Add(GgcmsPowers info) { var result = Dbctx.GgcmsPowers.Add(info); Dbctx.SaveChanges(); ClearCache(); return(Ok(result)); }
// PUT: api/GgcmsCategories/5 public IHttpActionResult Edit(GgcmsPowers info) { if (Dbctx.GgcmsPowers.Where(x => x.Id == info.Id).Count() == 0) { return(BadRequest("信息不存在")); } //Dbctx.GgcmsPowers.Attach(info); //Dbctx.Entry(info).Property("goods_name").IsModified = true; var ent = Dbctx.Entry(info); ent.State = EntityState.Modified; Dbctx.SaveChanges(); ClearCache(); return(Ok(info)); }
private void adminPowers() { int order = 1; //Get the executing assembly var assembly = Assembly.GetExecutingAssembly(); //Get all classes that inherit from the Controller class that are public and not abstract //Replace Controller with ApiController for Web Api var types = assembly.GetTypes() .Where(t => t.IsSubclassOf(typeof(ApiController)) && t.IsPublic && !t.IsAbstract); foreach (var type in types) { if (type.BaseType.Name != "ApiBaseController") { continue; } //Get the Controller Name minus the word Controller string controllerName = type.Name .Substring(0, type.Name.IndexOf("Controller", System.StringComparison.InvariantCulture)); //Get all Methods within the inherited class var methods = type.GetMethods() .Where(x => x.IsPublic && x.DeclaringType.Equals(type)); foreach (var m in methods) { var power = new GgcmsPowers() { Path = controllerName + "/" + m.Name, PowerName = m.Name, OrderId = order++, PowerType = 0, }; foreach (var attr in m.CustomAttributes) { if (attr.AttributeType.Name == "DisplayNameAttribute" && attr.ConstructorArguments.Count > 0) { power.PowerName = attr.ConstructorArguments[0].Value.ToString(); } } Dbctx.GgcmsPowers.Add(power); } } Dbctx.SaveChanges(); }
// DELETE: api/GgcmsCategories/5 public IHttpActionResult Delete(int id) { GgcmsPowers oldinfo = Dbctx.GgcmsPowers.Find(id); if (oldinfo == null) { return(BadRequest("信息不存在")); } //List<int> idlist = GetDeleteIds(oldinfo.ticket_key); //var query = Dbctx.ticket_information.Where(x => idlist.Contains(x.id)); Dbctx.GgcmsPowers.Remove(oldinfo); Dbctx.SaveChanges(); ClearCache(); return(Ok(oldinfo)); }