public ActionResult DeleteConfirmed(int id)
        {
            DocCategory doccategory = db.DocCategories.Find(id);

            db.DocCategories.Remove(doccategory);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
 public ActionResult Edit([Bind(Include = "id,CatName,date")] DocCategory doccategory)
 {
     if (ModelState.IsValid)
     {
         db.Entry(doccategory).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(doccategory));
 }
        public ActionResult Create([Bind(Include = "id,CatName,date")] DocCategory doccategory)
        {
            if (ModelState.IsValid)
            {
                doccategory.date = DateTime.Now;

                db.DocCategories.Add(doccategory);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(doccategory));
        }
        // GET: /Doctorcategory/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            DocCategory doccategory = db.DocCategories.Find(id);

            if (doccategory == null)
            {
                return(HttpNotFound());
            }
            return(View(doccategory));
        }
Exemplo n.º 5
0
        private DocBase CreateModel()
        {
            // Find assembly
            var a = Assembly.GetExecutingAssembly().GetReferencedAssemblies().FirstOrDefault(a => a.Name == _options.Value.PluginName);

            if (a == null)
            {
                throw new FileNotFoundException("Unable to load assembly for reflection.");
            }

            var model = new DocBase {
                Title    = "MSFS 2020 TouchPortal Plugin",
                Overview = "This plugin will provide a two way interface between Touch Portal and Microsoft Flight Simulator 2020 through SimConnect."
            };

            var assembly     = Assembly.Load(a);
            var assemblyList = assembly.GetTypes().ToList();

            // Get all classes with the TouchPortalCategory
            var classList = assemblyList.Where(t => t.CustomAttributes.Any(att => att.AttributeType == typeof(TouchPortalCategoryAttribute))).OrderBy(o => o.Name).ToList();

            // Loop through categories
            classList.ForEach(cat => {
                var catAttr = (TouchPortalCategoryAttribute)Attribute.GetCustomAttribute(cat, typeof(TouchPortalCategoryAttribute));
                var newCat  = new DocCategory {
                    Name = catAttr.Name
                };

                // Loop through Actions
                var actions = cat.GetMembers().Where(t => t.CustomAttributes.Any(att => att.AttributeType == typeof(TouchPortalActionAttribute))).ToList();
                actions.ForEach(act => {
                    var actionAttribute = (TouchPortalActionAttribute)Attribute.GetCustomAttribute(act, typeof(TouchPortalActionAttribute));
                    var newAct          = new DocAction {
                        Name        = actionAttribute.Name,
                        Description = actionAttribute.Description,
                        Type        = actionAttribute.Type,
                        Format      = actionAttribute.Format
                    };

                    // Loop through Action Data
                    var choiceAttributes = act.GetCustomAttributes <TouchPortalActionChoiceAttribute>()?.ToList();

                    if (choiceAttributes?.Count > 0)
                    {
                        for (int i = 0; i < choiceAttributes.Count; i++)
                        {
                            var data = new DocActionData {
                                Type         = "choice",
                                DefaultValue = choiceAttributes[i].DefaultValue,
                                Values       = string.Join(",", choiceAttributes[i].ChoiceValues)
                            };
                            newAct.Data.Add(data);
                        }
                    }

                    newCat.Actions.Add(newAct);
                });

                newCat.Actions = newCat.Actions.OrderBy(c => c.Name).ToList();

                // Loop through States
                var states = cat.GetFields().Where(m => m.CustomAttributes.Any(att => att.AttributeType == typeof(TouchPortalState))).ToList();
                states.ForEach(state => {
                    var stateAttribute = state.GetCustomAttribute <TouchPortalStateAttribute>();

                    if (stateAttribute != null)
                    {
                        var newState = new DocState {
                            Id           = $"{_options.Value.PluginName}.{catAttr.Id}.State.{stateAttribute.Id}",
                            Type         = stateAttribute.Type,
                            Description  = stateAttribute.Description,
                            DefaultValue = stateAttribute.Default
                        };

                        newCat.States.Add(newState);
                    }
                });

                newCat.States = newCat.States.OrderBy(c => c.Description).ToList();

                // Loop through Events

                model.Categories.Add(newCat);
            });

            model.Categories = model.Categories.OrderBy(c => c.Name).ToList();

            return(model);
        }