コード例 #1
0
        public ActionResult _AjaxDelete(Settings item, [DataSourceRequest] DataSourceRequest request)
        {
            if (ModelState.IsValid)
            {
                if (_db.SettingsAll.Count() == 1)
                {
                    ModelState.AddModelError("", "Not deleted");
                    return(Json(new[] { item }.ToDataSourceResult(request, ModelState)));
                }
                _db.SettingsAll.Remove(_db.SettingsAll.First(r => r.ID == item.ID));

                //delete pages and elements
                foreach (AbstractPage item2 in _db.AbstractPages.Where(r => r.DomainID == item.ID).ToList())
                {
                    _db.Entry(item2).State = EntityState.Modified;
                }
                foreach (TextComponent item2 in _db.TextComponents.Where(r => r.DomainID == item.ID).ToList())
                {
                    _db.Entry(item2).State = EntityState.Modified;
                }
                foreach (Contact item2 in _db.Contacts.Where(r => r.DomainID == item.ID).ToList())
                {
                    _db.Entry(item2).State = EntityState.Modified;
                }
                foreach (Newsletter item2 in _db.Newsletters.Where(r => r.DomainID == item.ID).ToList())
                {
                    _db.Entry(item2).State = EntityState.Modified;
                }

                _db.SaveChanges();

                //delete folders
                System.IO.Directory.Delete(Server.MapPath("~/Content/UserFiles/" + item.ID), true);
                System.IO.Directory.Delete(Server.MapPath("~/App_Data/cache/images/" + item.ID), true);

                CleanCache.CleanOutputCache();
                CleanCache.CleanSettingsAllCache();
            }
            return(Json(new[] { item }.ToDataSourceResult(request, ModelState)));
        }
コード例 #2
0
        public ActionResult Create(Settings item, List <string> Roles)
        {
            if (ModelState.IsValid)
            {
                if (_db.SettingsAll.Count(r => r.Domain == item.Domain) > 0)
                {
                    ModelState.AddModelError("", "Domain + LanguageCode not unic. Please specify different Domain or LanguageCode");
                    return(View(item));
                }

                string Title = "";
                if (string.IsNullOrEmpty(item.Domain))
                {
                    Title = (_db.AbstractPages.Max(r => r.ID) + 1).ToString();
                }
                else
                {
                    Title = item.Domain;
                }

                DomainPage dp = new DomainPage();
                dp.Title           = Title;
                dp.ParentID        = 0;
                dp.DomainID        = 0;
                dp.SeoUrlName      = (_db.AbstractPages.Max(r => r.ID) + 1).ToString();
                dp.PermissionsView = SF.RolesListToString(new List <string>()
                {
                    "Admin", "Anonymous"
                });
                dp.PermissionsEdit = SF.RolesListToString(new List <string>()
                {
                    "Admin"
                });
                _db.DomainPages.Add(dp);
                _db.SaveChanges();

                List <string> DomainRoles = SF.GetRoleObjectsList().Where(r => r.IsSystem == true).Select(r => r.Title).ToList();
                if (Roles != null)
                {
                    DomainRoles.AddRange(Roles);
                }
                item.Roles        = SF.RolesListToString(DomainRoles);
                item.DomainPageID = dp.ID;
                if (string.IsNullOrEmpty(item.Domain))
                {
                    item.Domain = Title;
                }

                _db.SettingsAll.Add(item);
                _db.SaveChanges();

                dp.DomainID         = item.ID;
                _db.Entry(dp).State = EntityState.Modified;
                _db.SaveChanges();

                System.IO.Directory.CreateDirectory(Server.MapPath("~/Content/UserFiles/" + item.ID));
                System.IO.Directory.CreateDirectory(Server.MapPath("~/App_Data/cache/images/" + item.ID));

                CleanCache.CleanOutputCache();
                CleanCache.CleanSettingsAllCache();

                return(RedirectToAction("Index"));
            }
            return(View(item));
        }