예제 #1
0
        public object GetSites()
        {
            var email = HttpContext.User.Claims.First().Value;
            var user  = _context.User.First(x => x.Email == email);
            var sites = _context.Site.Where(x => x.UserID == user.ID);
            List <SitePartial> sites2             = new List <SitePartial>();
            List <List <ComponentPartial> > pages = new List <List <ComponentPartial> >();

            foreach (var site in sites)
            {
                SitePartial sp = new SitePartial(site);
                sp.UserID = -99999;
                var components = _context.Component.Where(x => x.SiteID == site.ID);
                List <ComponentPartial> components2 = new List <ComponentPartial>();
                foreach (var component in components)
                {
                    ComponentPartial cp = new ComponentPartial(component);
                    cp.ComponentText = null;
                    components2.Add(cp);
                }
                pages.Add(components2);
                sites2.Add(sp);
            }
            return(new { Success = true, Sites = sites2, Pages = pages });
        }
예제 #2
0
        public object EditComponent([FromBody] ComponentPartial component)
        {
            var email        = HttpContext.User.Claims.First().Value;
            var user         = _context.User.First(x => x.Email == email);
            var oldComponent = _context.Component.First(x => x.ID == component.ID);
            var site         = _context.Site.First(x => x.ID == oldComponent.SiteID);

            if (user.ID == site.UserID)
            {
                if (component.Name != null)
                {
                    oldComponent.Name = component.Name;
                }
                if (component.ComponentText != null)
                {
                    oldComponent.ComponentText = component.ComponentText;
                }
                if (component.IsPage != null)
                {
                    oldComponent.IsPage = component.IsPage.Value;
                }
                if (component.IsPrefab != null)
                {
                    oldComponent.IsPrefab = component.IsPrefab.Value;
                }
                if (component.Screenshot != null)
                {
                    oldComponent.Screenshot = component.Screenshot;
                }
                if (component.AccessLevel != null)
                {
                    oldComponent.AccessLevel = component.AccessLevel.Value;
                }
                if (component.Description != null)
                {
                    oldComponent.Description = component.Description;
                }
                if (component.Path != null)
                {
                    oldComponent.Path = component.Path;
                }
                if (component.Resources != null)
                {
                    oldComponent.Resources = component.Resources;
                }
                if (component.Screenshot != null)
                {
                    oldComponent.Screenshot = component.Screenshot;
                }
                oldComponent.LastEdited   = DateTime.Now;
                oldComponent.LastEditedBy = user.ID;
                _context.Component.Update(oldComponent);
                _context.SaveChanges();
                component = new ComponentPartial(oldComponent);
                return(new { Success = true, Size = component.size });
            }
            else
            {
                return(NotFound(new { Success = false }));
            }
        }