コード例 #1
0
        public IActionResult CreateCategory(Category category, string description)
        {
            //TODO: authorize, validate...
            using (var db = CMSContextFactory.Create(Settings.MySqlConnectionString))
            {
                //TODO: encapsulate in Category Model
                var customFields = this.Request.Form["CustomFields"].ToString();

                //check if it's the default custom fields, discard
                var parsedCustomFields = JsonConvert.DeserializeObject <List <CustomField> >(customFields);
                if (parsedCustomFields.Count == 0 || parsedCustomFields[0].Name.Length == 0)
                {
                    category.CustomFields = null;
                }
                else
                {
                    category.CustomFields = customFields;
                }

                db.Add(category);

                Category_Language category_language = new Category_Language()
                {
                    LanguageId = 1, Category = category, Description = description
                };
                db.Add(category_language);


                db.SaveChanges();
            }
            return(Redirect("/backend/categories"));
        }
コード例 #2
0
        public IActionResult EditCategory(Category category, Category_Language categroyLanguage, int categoryId, int category_languageId, int languageId, string customFields)
        {
            using (var db = CMSContextFactory.Create(Settings.MySqlConnectionString))
            {
                category.Id               = categoryId;
                categroyLanguage.Id       = category_languageId;
                categroyLanguage.Category = category;

                //check if default custom fields provided then discard
                var parsedCustomFields = JsonConvert.DeserializeObject <List <CustomField> >(customFields);
                if (parsedCustomFields.Count == 0 || parsedCustomFields[0].Name.Length == 0)
                {
                    category.CustomFields = null;
                }
                else
                {
                    category.CustomFields = customFields;
                }

                db.Entry(category).State         = EntityState.Modified;
                db.Entry(categroyLanguage).State = EntityState.Modified;
                db.SaveChanges();

                return(Redirect("/backend/categories"));
            }
        }
コード例 #3
0
 public IActionResult AddCategory(Category_Language category_language)
 {
     //TODO: authorize, validate...
     using (var db = CMSContextFactory.Create(Settings.MySqlConnectionString))
     {
         db.Add(category_language);
         db.SaveChanges();
     }
     return(Redirect("/backend/categories"));
 }
コード例 #4
0
        public void Bootstrap(string sqlString)
        {
            createRoles(sqlString);
            createSuperUser(sqlString);


            //find or create pattern
            using (var db = CMSContextFactory.Create(sqlString))
            {
                //add language if not exist
                var lang = db.Language.SingleOrDefault(laganguage => laganguage.Name == "English");
                if (lang == null)
                {
                    lang             = new Language();
                    lang.Name        = "English";
                    lang.Id          = 1;
                    lang.orientation = "ltr";
                    db.Add(lang);
                }

                lang = db.Language.SingleOrDefault(laganguage => laganguage.Name == "Arabic");
                if (lang == null)
                {
                    lang             = new Language();
                    lang.Name        = "Arabic";
                    lang.Id          = 2;
                    lang.orientation = "rtl";
                    db.Add(lang);
                }

                //init category
                var mainCategory = db.Categories.SingleOrDefault(cat => cat.Id == 1);
                if (mainCategory == null)
                {
                    mainCategory = new Category()
                    {
                        Id   = 1,
                        Role = db.Roles.SingleOrDefault(role => role.Name.Equals("Public"))
                    };
                    db.Add(mainCategory);
                    Category_Language category_language = new Category_Language()
                    {
                        Id          = 1,
                        Description = "Main Category",
                        LanguageId  = 1,
                        CategoryId  = 1
                    };
                    db.Add(category_language);

                    category_language = new Category_Language()
                    {
                        Id          = 2,
                        Description = "الرئيسية",
                        LanguageId  = 2,
                        CategoryId  = 1
                    };
                    db.Add(category_language);
                }

                //init menu
                var mainMenu = db.Menus.SingleOrDefault(menu => menu.Id == 1);
                if (mainMenu == null)
                {
                    mainMenu = new Menu()
                    {
                        Id         = 1,
                        CategoryId = 1, // main category
                        //Description = "Main Menu - Displayed at header"
                    };
                    db.Add(mainMenu);
                    Menu_Language mainMenu_Language = new Menu_Language()
                    {
                        Id          = 1,
                        LanguageId  = 1,
                        MenuId      = 1,
                        Description = "Main Menu - Displayed at header"
                    };
                    db.Add(mainMenu_Language);

                    mainMenu_Language = new Menu_Language()
                    {
                        Id          = 2,
                        LanguageId  = 2,
                        MenuId      = 1,
                        Description = "اللائحة الرئيسية"
                    };
                    db.Add(mainMenu_Language);
                }

                db.SaveChanges();
            }
        }