public void ProcessRequest(HttpContext context)
        {
            var id = Guid.Parse(context.Request["treeItemId"]);

            using (var db = new OrganizerEntities())
            {
                var item = db.TreeItems.Find(id);
                CustomMembershipProvider.ValidateAccessToTreeItem_ReturnActiveAuthEntity(item, db, true);
                if (item.ParentId == null)
                {
                    throw new Exception("Can't delete root node");
                }

                var children = new List <TreeItem>();
                GetTreeItems.GetChildTreeItemsReadonlyHtml(id, db, children, false, true, null, true);
                for (int i = children.Count - 1; i >= 0; i--) // need to delete in this order to avoid FK errors
                {
                    db.TreeItems.Remove(children[i]);
                    db.SaveChanges();
                }

                var previousSibling = db.TreeItems.FirstOrDefault(x => x.NextSiblingId == id);
                if (previousSibling != null)
                {
                    previousSibling.NextSiblingId = item.NextSiblingId;
                    db.SaveChanges();
                }

                db.TreeItems.Remove(item);
                db.SaveChanges();
            }

            context.Response.ContentType = "text/plain";
            context.Response.Write("OK");
        }
Esempio n. 2
0
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/xml";
            var thisTreeItemId = Guid.Parse(context.Request["thisTreeItemId"]);

            using (var db = new OrganizerEntities())
            {
                var thisTreeItem = db.TreeItems.Find(thisTreeItemId);
                CustomMembershipProvider.ValidateAccessToTreeItem_ReturnActiveAuthEntity(thisTreeItem, db, true);
                var thisTreeItemChildren = new List <TreeItem>();
                GetTreeItems.GetChildTreeItemsReadonlyHtml(thisTreeItemId, db, thisTreeItemChildren);
                var newItem = new TreeItem
                {
                    CreatedUtc      = DateTime.UtcNow,
                    Id              = Guid.NewGuid(),
                    LastModifiedUtc = DateTime.UtcNow,
                    ParentId        = thisTreeItem.Id,
                    NextSiblingId   = thisTreeItemChildren.Count != 0 ? (Guid?)thisTreeItemChildren[0].Id : null,
                    AutoLoadNestedChildrenIfNotRoot = true
                };
                db.TreeItems.Add(newItem);
                db.SaveChanges();

                context.Response.Write(ServerSideProcedures.DataObjectToXml(newItem));
            }
        }
Esempio n. 3
0
        public void ProcessRequest(HttpContext context)
        {
            var  moveType = context.Request["moveType"];
            var  from     = Guid.Parse(context.Request["from"]);
            var  toStr    = context.Request["to"];
            Guid?to;

            if (!String.IsNullOrEmpty(toStr))
            {
                to = Guid.Parse(toStr);
            }
            else
            {
                to = null;
            }
            using (var db = new OrganizerEntities())
            {
                var fromItem = db.TreeItems.Find(from);
                CustomMembershipProvider.ValidateAccessToTreeItem_ReturnActiveAuthEntity(fromItem, db, true);
                TreeItem toItem = null;
                if (to.HasValue)
                {
                    toItem = db.TreeItems.Find(to);
                    CustomMembershipProvider.ValidateAccessToTreeItem_ReturnActiveAuthEntity(toItem, db, true);
                }

                switch (moveType)
                {
                case "top":
                {
                    var children = new List <TreeItem>();
                    GetTreeItems.GetChildTreeItemsReadonlyHtml(fromItem.ParentId.Value, db, children, false, false);
                    var firstChild = children.FirstOrDefault();

                    var previousSibling = db.TreeItems.FirstOrDefault(x => x.NextSiblingId == from);
                    if (previousSibling != null)
                    {
                        previousSibling.NextSiblingId = fromItem.NextSiblingId;
                        db.SaveChanges();
                    }

                    fromItem.NextSiblingId = firstChild.Id;
                    db.SaveChanges();
                }
                break;

                case "bottom":
                {
                    var children = new List <TreeItem>();
                    GetTreeItems.GetChildTreeItemsReadonlyHtml(fromItem.ParentId.Value, db, children, false, false);
                    var lastChild = children.LastOrDefault();

                    var previousSibling = db.TreeItems.FirstOrDefault(x => x.NextSiblingId == from);
                    if (previousSibling != null)
                    {
                        previousSibling.NextSiblingId = fromItem.NextSiblingId;
                        db.SaveChanges();
                    }

                    if (lastChild != null)
                    {
                        lastChild.NextSiblingId = fromItem.Id;
                    }
                    fromItem.NextSiblingId = null;
                    db.SaveChanges();
                }
                break;

                case "children":
                {
                    var children = new List <TreeItem>();
                    GetTreeItems.GetChildTreeItemsReadonlyHtml(to.Value, db, children, false, false);
                    var lastChild = children.LastOrDefault();

                    var previousSibling = db.TreeItems.FirstOrDefault(x => x.NextSiblingId == from);
                    if (previousSibling != null)
                    {
                        previousSibling.NextSiblingId = fromItem.NextSiblingId;
                        db.SaveChanges();
                    }
                    fromItem.ParentId      = toItem.Id;
                    fromItem.NextSiblingId = null;
                    if (lastChild != null)
                    {
                        lastChild.NextSiblingId = fromItem.Id;
                    }
                    db.SaveChanges();
                }
                break;

                case "siblings":
                {
                    var previousSibling = db.TreeItems.FirstOrDefault(x => x.NextSiblingId == from);
                    if (previousSibling != null)
                    {
                        previousSibling.NextSiblingId = fromItem.NextSiblingId;
                        db.SaveChanges();
                    }

                    fromItem.ParentId      = toItem.ParentId;
                    fromItem.NextSiblingId = toItem.NextSiblingId;
                    toItem.NextSiblingId   = fromItem.Id;

                    db.SaveChanges();
                }
                break;

                default: throw new ArgumentException("invalid moveType: " + moveType);
                }

                db.SaveChanges();
            }

            context.Response.ContentType = "text/plain";
            context.Response.Write("OK");
        }