public ActionResult Delete(int id, string Title)
        {
            if (CheckPermissions(id) == false)
            {
                return(Redirect("~/Account/LogOn?returnUrl=/Admin"));
            }

            if (id == 0)
            {
                RedirectToAction("View", new { id = id });
            }
            if (id == 1)
            {
                throw new NotImplementedException("Can't delete root page");
            }

            AbstractPage ap     = _db.AbstractPages.FirstOrDefault(r => r.DomainID == AdminCurrentSettingsRepository.ID && r.ID == id);
            int          parent = ap.ParentID;

            ap.OnDelete();
            DeleteChildPages(ap);
            _db.Entry(ap).State = EntityState.Deleted;
            _db.SaveChanges();

            ap.OnDeleted();

            CleanCache.CleanCacheAfterPageEdit();

            return(RedirectToAction("View", new { id = parent }));
        }
        public ActionResult Create(Banner item)
        {
            if (ModelState.IsValid)
            {
                _db.Banners.Add(item);
                _db.SaveChanges();

                CleanCache.CleanCacheAfterPageEdit();

                return(RedirectToAction("Index"));
            }
            return(View(item));
        }
        public ActionResult _TreeCopy(int item, int destinationitem)
        {
            if (CheckPermissions(item) == false || CheckPermissions(destinationitem) == false)
            {
                return(Content(LocalizationHelpers.GetLocalResource("~/Areas/Admin/Views/Shared/_TreeView.cshtml", "ErrorPermitions")));
            }

            AbstractPage ItemPage            = _db.AbstractPages.FirstOrDefault(r => r.DomainID == AdminCurrentSettingsRepository.ID && r.ID == item);
            AbstractPage DestinationItemPage = _db.AbstractPages.FirstOrDefault(r => r.DomainID == AdminCurrentSettingsRepository.ID && r.ID == destinationitem);

            if (ItemPage.ParentID == 0 || ItemPage.RouteUrl == "d")
            {
                return(Content(LocalizationHelpers.GetLocalResource("~/Areas/Admin/Views/Shared/_TreeView.cshtml", "ErrorDomain")));
            }

            Type t = ItemPage.GetType();

            if (GetChildClasses(destinationitem).Contains(t))
            {
                AbstractPage ap = ItemPage;

                AbstractPage Parent = _db.AbstractPages.FirstOrDefault(r => r.ID == destinationitem);
                ap.ParentID        = Parent.ID;
                ap.DomainID        = Parent.DomainID;
                ap.PermissionsEdit = Parent.PermissionsEdit;
                ap.PermissionsView = Parent.PermissionsView;

                Session["TreeCopy"] = true;

                if (ap.RouteUrl != "l")
                {
                    ap.LanguageCode = Parent.LanguageCode;
                }

                ap.Title      = ap.Title + "-Copy";
                ap.SeoUrlName = (_db.AbstractPages.Max(r => r.ID) + 1).ToString();

                if (_db.AbstractPages.Count(r => r.DomainID == ap.DomainID && r.SeoUrlName == ap.SeoUrlName) != 0)
                {
                    return(Content(LocalizationHelpers.GetLocalResource("~/Areas/Admin/Views/Shared/_TreeView.cshtml", "ErrorTitle")));
                }
                ap.CreateTime = DateTime.Now;
                if (_db.AbstractPages.Where(r => r.ParentID == ap.ParentID && r.DomainID == ap.DomainID).Count() == 0)
                {
                    ap.Order = 1;
                }
                else
                {
                    ap.Order = _db.AbstractPages.Where(r => r.ParentID == ap.ParentID && r.DomainID == ap.DomainID).Max(r => r.Order) + 1;
                }
                ap.OnCreate();
                _db.AbstractPages.Add(ap);

                try
                {
                    _db.SaveChanges();
                }
                catch (DataException error)
                {
                    return(Content(LocalizationHelpers.GetLocalResource("~/Areas/Admin/Views/Shared/_TreeView.cshtml", "ErrorGeneral") + error.Message));
                }

                AbstractPage CopyItem = _db.AbstractPages.FirstOrDefault(r => r.DomainID == AdminCurrentSettingsRepository.ID && r.ID == item);
                foreach (AbstractPage item2 in _db.AbstractPages.Where(r => r.ParentID == CopyItem.ID).ToList())
                {
                    CopyPage(ap, item2, 5);
                }

                CleanCache.CleanCacheAfterPageEdit();

                return(Content("true"));
            }
            else
            {
                return(Content(LocalizationHelpers.GetLocalResource("~/Areas/Admin/Views/Shared/_TreeView.cshtml", "ErrorParent")));
            }
        }
        public ActionResult _TreeDrop(int item, int destinationitem, string position)
        {
            if (CheckPermissions(item) == false || CheckPermissions(destinationitem) == false)
            {
                return(Content("false"));
            }

            AbstractPage ItemPage            = _db.AbstractPages.FirstOrDefault(r => r.DomainID == AdminCurrentSettingsRepository.ID && r.ID == item);
            AbstractPage DestinationItemPage = _db.AbstractPages.FirstOrDefault(r => r.DomainID == AdminCurrentSettingsRepository.ID && r.ID == destinationitem);

            if (ItemPage.ParentID == 0 || ItemPage.RouteUrl == "d")
            {
                return(Content("false"));
            }

            if (position == "over")
            {
                Type t = ItemPage.GetType();
                if (GetChildClasses(destinationitem).Contains(t))
                {
                    AbstractPage Parent = _db.AbstractPages.FirstOrDefault(r => r.ID == destinationitem);
                    ItemPage.ParentID = Parent.ID;
                    ItemPage.DomainID = Parent.DomainID;
                    if (ItemPage.RouteUrl != "l")
                    {
                        ItemPage.LanguageCode = Parent.LanguageCode;
                    }

                    _db.Entry(ItemPage).State = EntityState.Modified;
                    _db.SaveChanges();

                    CleanCache.CleanCacheAfterPageEdit();

                    return(Content("true"));
                }
                else
                {
                    return(Content("false"));
                }
            }
            else if (position == "before")
            {
                if (DestinationItemPage.ID == 1)
                {
                    return(Content("false"));
                }
                if (GetChildClasses((int)DestinationItemPage.ParentID).Contains(ItemPage.GetType()))
                {
                    ItemPage.ParentID         = DestinationItemPage.ParentID;
                    ItemPage.Order            = DestinationItemPage.Order;
                    _db.Entry(ItemPage).State = EntityState.Modified;

                    foreach (AbstractPage item2 in _db.AbstractPages.Where(r => r.DomainID == AdminCurrentSettingsRepository.ID && r.ParentID == (int)DestinationItemPage.ParentID && r.Order >= DestinationItemPage.Order && r.ID != (int)ItemPage.ID))
                    {
                        item2.Order            = item2.Order + 1;
                        _db.Entry(item2).State = EntityState.Modified;
                    }

                    _db.SaveChanges();

                    CleanCache.CleanCacheAfterPageEdit();

                    return(Content("true"));
                }
                else
                {
                    return(Content("false"));
                }
            }
            else if (position == "after")
            {
                if (DestinationItemPage.ID == 1)
                {
                    return(Content("false"));
                }
                if (GetChildClasses((int)DestinationItemPage.ParentID).Contains(ItemPage.GetType()))
                {
                    foreach (AbstractPage item2 in _db.AbstractPages.Where(r => r.DomainID == AdminCurrentSettingsRepository.ID && r.ParentID == (int)DestinationItemPage.ParentID && r.Order >= DestinationItemPage.Order && r.ID != (int)DestinationItemPage.ID))
                    {
                        item2.Order            = item2.Order + 2;
                        _db.Entry(item2).State = EntityState.Modified;
                    }

                    ItemPage.ParentID         = DestinationItemPage.ParentID;
                    ItemPage.Order            = DestinationItemPage.Order + 1;
                    _db.Entry(ItemPage).State = EntityState.Modified;

                    _db.SaveChanges();

                    CleanCache.CleanCacheAfterPageEdit();

                    return(Content("true"));
                }
                else
                {
                    return(Content("false"));
                }
            }

            return(Content("false"));
        }
        public ActionResult Edit(AbstractPage ap, int id, bool?red)
        {
            if (ModelState.IsValid)
            {
                if (CheckPermissions(id) == false)
                {
                    return(Redirect("~/Account/LogOn?returnUrl=/Admin"));
                }

                if (ap.SeoUrlName == null || ap.SeoUrlName == "")
                {
                    ap.SeoUrlName = Uco.Infrastructure.SF.CleanUrl(ap.Title);
                }
                else
                {
                    ap.SeoUrlName = Uco.Infrastructure.SF.CleanUrl(ap.SeoUrlName);
                }

                AbstractPage Parent = _db.AbstractPages.FirstOrDefault(r => r.ID == ap.ParentID);
                if (Parent == null)
                {
                    ap.ParentID = 0;
                    ap.DomainID = AdminCurrentSettingsRepository.ID;
                    if (ap.RouteUrl != "l")
                    {
                        ap.LanguageCode = CurrentSettings.LanguageCode;
                    }
                }
                else
                {
                    ap.ParentID = Parent.ID;
                    ap.DomainID = Parent.DomainID;
                    if (ap.RouteUrl != "l")
                    {
                        ap.LanguageCode = Parent.LanguageCode;
                    }
                }

                if (_db.AbstractPages.Count(r => r.DomainID == AdminCurrentSettingsRepository.ID && r.ID != ap.ID && r.RouteUrl == ap.RouteUrl && r.SeoUrlName == ap.SeoUrlName) != 0)
                {
                    ModelState.AddModelError("SeoUrlName", "Title not unic. Please specify Url Name different from title");
                    return(View(ap));
                }
                ap.ChangeTime = DateTime.Now;
                ap.OnEdit();

                _db.Entry(ap).State = EntityState.Modified;

                try
                {
                    _db.SaveChanges();
                }
                catch (DataException error)
                {
                    ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists, see your system administrator. Error:" + error.Message + ". Data:" + error.Data);
                    return(View(ap));
                }

                ap.OnEdited();

                CleanCache.CleanCacheAfterPageEdit();

                if (red != null && red == true)
                {
                    Response.Redirect(ap.Url);
                }
                else
                {
                    return(RedirectToAction("View", new { id = ap.ID }));
                }
            }
            return(View(ap));
        }
        public ActionResult Create(AbstractPage ap, int id)
        {
            if (ModelState.IsValid)
            {
                if (CheckPermissions(id) == false)
                {
                    return(Redirect("~/Account/LogOn?returnUrl=/Admin"));
                }

                AbstractPage Parent = _db.AbstractPages.FirstOrDefault(r => r.ID == id);
                if (Parent == null)
                {
                    ap.ParentID = 0;
                    ap.DomainID = CurrentSettings.ID;
                    if (ap.RouteUrl != "l")
                    {
                        ap.LanguageCode = CurrentSettings.LanguageCode;
                    }
                }
                else
                {
                    ap.ParentID = Parent.ID;
                    ap.DomainID = Parent.DomainID;
                    if (ap.RouteUrl != "l")
                    {
                        ap.LanguageCode = Parent.LanguageCode;
                    }
                }

                if (ap.SeoUrlName == null || ap.SeoUrlName == "")
                {
                    ap.SeoUrlName = Uco.Infrastructure.SF.CleanUrl(ap.Title);
                }
                else
                {
                    ap.SeoUrlName = Uco.Infrastructure.SF.CleanUrl(ap.SeoUrlName);
                }

                if (_db.AbstractPages.Count(r => r.DomainID == ap.DomainID && r.SeoUrlName == ap.SeoUrlName) != 0)
                {
                    ModelState.AddModelError("SeoUrlName", "Title not unic. Please specify Url Name different from title");
                    return(View(ap));
                }
                ap.CreateTime = DateTime.Now;
                if (_db.AbstractPages.Where(r => r.ParentID == ap.ParentID && r.DomainID == ap.DomainID).Count() == 0)
                {
                    ap.Order = 1;
                }
                else
                {
                    ap.Order = _db.AbstractPages.Where(r => r.ParentID == ap.ParentID && r.DomainID == ap.DomainID).Max(r => r.Order) + 1;
                }
                ap.OnCreate();
                _db.AbstractPages.Add(ap);

                try
                {
                    _db.SaveChanges();
                }
                catch (DataException error)
                {
                    //Log the error (add a variable name after DataException)
                    ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists, see your system administrator. Error:" + error.Message + ". Data:" + error.Data);
                    View(ap);
                }

                ap.OnCreated();

                CleanCache.CleanCacheAfterPageEdit();

                return(RedirectToAction("View", new { id = ap.ID }));
            }
            return(View(ap));
        }