Beispiel #1
0
        public async Task <IHttpActionResult> PutPageNodes(int id, PageNodes pageNodes)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != pageNodes.Id)
            {
                return(BadRequest());
            }

            db.Entry(pageNodes).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PageNodesExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Beispiel #2
0
        private BaseNode ProcessNode(XElement element)
        {
            string name = element.Name.ToString();

            switch (name)
            {
            case "content":
            case "example":
            case "tag":
            case "caption":
            case "type":
            case "name":
            case "keywords":
                return(null);

            case "styles":
                StyleNode = element;
                return(null);

            case "parameter":
                element = XmlCompliantConverter.ParseNameValueToElement(element);
                return(null);
            }
            element = XmlCompliantConverter.ParseNameValueToElement(element);
            var children = new List <BaseNode>();

            foreach (var e in element.Elements())
            {
                var n = ProcessNode(e);
                if (n != null)
                {
                    children.Add(n);
                }
            }
            BaseNode node = BaseNode.GetNode(element);

            if (!string.IsNullOrEmpty(node.Key)) // it's a page
            {
                node.Children = children;
                PageNodes.Add(node);
            }

            if (node.Keywords != null)
            {
                foreach (var s in node.Keywords)
                {
                    if (!Constants.Contains(s))
                    {
                        Constants.Add(s);
                    }
                }
            }

            return(node);
        }
Beispiel #3
0
        public async Task <IHttpActionResult> GetPageNodes(int id)
        {
            PageNodes pageNodes = await db.PageNodes.FindAsync(id);

            if (pageNodes == null)
            {
                return(NotFound());
            }

            return(Ok(pageNodes));
        }
Beispiel #4
0
        public async Task <IHttpActionResult> PostPageNodes(PageNodes pageNodes)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.PageNodes.Add(pageNodes);
            await db.SaveChangesAsync();

            return(CreatedAtRoute("DefaultApi", new { id = pageNodes.Id }, pageNodes));
        }
Beispiel #5
0
        public async Task <IHttpActionResult> DeletePageNodes(int id)
        {
            PageNodes pageNodes = await db.PageNodes.FindAsync(id);

            if (pageNodes == null)
            {
                return(NotFound());
            }

            db.PageNodes.Remove(pageNodes);
            await db.SaveChangesAsync();

            return(Ok(pageNodes));
        }
Beispiel #6
0
        public override int SaveChanges()
        {
            // Need to manually delete all PageNodes that have no ParentSectionNode, otherwise they'll be orphaned.
            var orphanedPageNodes = ChangeTracker.Entries().Where(e => (e.State == EntityState.Modified) &&
                                                                  e.Entity is PageNode &&
                                                                  e.Reference("ParentSectionNode").CurrentValue == null);

            foreach (var dbEntityEntry in orphanedPageNodes)
            {
                PageNodes.Remove(dbEntityEntry.Entity as PageNode);
            }

            var orphanedProperties = ChangeTracker.Entries().Where(e => (e.State == EntityState.Modified) &&
                                                                   e.Entity is PageProperty &&
                                                                   e.Reference("ParentPageNode").CurrentValue == null);

            foreach (var dbEntityEntry in orphanedProperties)
            {
                Properties.Remove(dbEntityEntry.Entity as PageProperty);
            }

            return(base.SaveChanges());
        }