Пример #1
0
        public async Task DeleteAsync(int pageAssociationId)
        {
            var pageAssociation = await _context.PageAssociations.SingleOrDefaultAsync(x => x.PageAssociationId == pageAssociationId);

            if (pageAssociation == null)
            {
                return;
            }

            if (pageAssociation.PageSection != null)
            {
                if (!await _context.PageAssociations.AnyAsync(x => x.PageSectionId == pageAssociation.PageSectionId))
                {
                    var pageSection = await _context.PageSections.SingleOrDefaultAsync(x => x.PageSectionId == pageAssociation.PageSectionId);

                    _context.PageSections.Remove(pageSection);
                }
            }
            else if (pageAssociation.PagePartial != null)
            {
                if (!_context.PageAssociations.Any(x => x.PagePartialId == pageAssociation.PagePartialId))
                {
                    var pagePartial = await _context.PagePartials.SingleOrDefaultAsync(x => x.PagePartialId == pageAssociation.PagePartialId);

                    _context.PagePartials.Remove(pagePartial);
                }
            }

            _context.PageAssociations.Remove(pageAssociation);

            await _context.SaveChangesAsync();
        }
Пример #2
0
        public async Task UpdateDetailsAsync(int userId, string emailAddress, string givenName, string familyName)
        {
            var user = await _context.Users.SingleOrDefaultAsync(x => x.UserId == userId);

            user.EmailAddress = emailAddress;
            user.GivenName    = givenName;
            user.FamilyName   = familyName;

            await _context.SaveChangesAsync();
        }
Пример #3
0
        public async Task <int> AddAsync(string roleName)
        {
            var newRole = new Role
            {
                RoleName = roleName
            };

            _context.Roles.Add(newRole);

            await _context.SaveChangesAsync();

            return(newRole.RoleId);
        }
Пример #4
0
        public async Task AddAsync(int postId, int imageId, PostImageType postImageType)
        {
            var postImage = new PostImage
            {
                PostId        = postId,
                PostImageType = postImageType,
                ImageId       = imageId
            };

            _context.PostImages.Add(postImage);

            await _context.SaveChangesAsync();
        }
Пример #5
0
        public async Task <int> AddAsync(string postCategoryName)
        {
            var newPostCategory = new PostCategory
            {
                PostCategoryName = postCategoryName
            };

            _context.PostCategories.Add(newPostCategory);

            await _context.SaveChangesAsync();

            return(newPostCategory.PostCategoryId);
        }
Пример #6
0
        public async Task <int> CreateAsync(string imageFilePath, ImageCategory imageCategory)
        {
            var image = new Image
            {
                ImagePath     = imageFilePath,
                ImageCategory = imageCategory
            };

            _context.Images.Add(image);

            await _context.SaveChangesAsync();

            return(image.ImageId);
        }
Пример #7
0
        public async Task <int> UpsertAsync(int themeId, string themeName, int titleFontId, int textFontId, int largeTitleFontSize, int mediumTitleFontSize, int smallTitleFontSize, int tinyTitleFontSize, int textStandardFontSize, string pageBackgroundColour, string menuBackgroundColour, string menuTextColour)
        {
            var existingTheme = await GetAsync(themeId);

            if (existingTheme == null)
            {
                var newTheme = new CustomTheme
                {
                    ThemeName            = themeName,
                    TitleFontId          = titleFontId,
                    TextFontId           = textFontId,
                    DateAdded            = DateTime.Now,
                    DateUpdated          = DateTime.Now,
                    TitleLargeFontSize   = largeTitleFontSize,
                    TitleMediumFontSize  = mediumTitleFontSize,
                    TitleSmallFontSize   = smallTitleFontSize,
                    TitleTinyFontSize    = tinyTitleFontSize,
                    TextStandardFontSize = textStandardFontSize,
                    PageBackgroundColour = pageBackgroundColour,
                    MenuBackgroundColour = menuBackgroundColour,
                    MenuTextColour       = menuTextColour,
                    IsDefault            = false,
                };

                _context.Themes.Add(newTheme);

                await _context.SaveChangesAsync();

                return(newTheme.ThemeId);
            }
            else
            {
                existingTheme.ThemeName            = themeName;
                existingTheme.TitleFontId          = titleFontId;
                existingTheme.TextFontId           = textFontId;
                existingTheme.DateUpdated          = DateTime.Now;
                existingTheme.TitleLargeFontSize   = largeTitleFontSize;
                existingTheme.TitleMediumFontSize  = mediumTitleFontSize;
                existingTheme.TitleSmallFontSize   = smallTitleFontSize;
                existingTheme.TitleTinyFontSize    = tinyTitleFontSize;
                existingTheme.TextStandardFontSize = textStandardFontSize;
                existingTheme.PageBackgroundColour = pageBackgroundColour;
                existingTheme.MenuBackgroundColour = menuBackgroundColour;
                existingTheme.MenuTextColour       = menuTextColour;

                await _context.SaveChangesAsync();

                return(existingTheme.ThemeId);
            }
        }
Пример #8
0
        public async Task <int> CreateAsync(int menuId, string linkText, string linkURL, string linkIcon)
        {
            var newMenuItem = new MenuItem
            {
                MenuId   = menuId,
                LinkText = linkText,
                LinkURL  = linkURL,
                LinkIcon = linkIcon
            };

            _context.MenuItems.Add(newMenuItem);

            await _context.SaveChangesAsync();

            return(newMenuItem.MenuItemId);
        }
Пример #9
0
        public async Task AddAsync(int pageId, string area, string controller, string action)
        {
            var page = await _context.Pages.SingleOrDefaultAsync(x => x.PageId == pageId);

            if (page == null)
            {
                return;
            }

            var orderPosition = 0;

            if (page.PageAssociations.Any())
            {
                orderPosition = page.PageAssociations.Max(x => x.PageAssociationOrder + 1);
            }

            var pageAssociation = new PageAssociation
            {
                PageId = page.PageId,
                PageAssociationOrder = orderPosition,
                PagePartial          = new PagePartial
                {
                    RouteArea       = area,
                    RouteController = controller,
                    RouteAction     = action
                }
            };

            _context.PageAssociations.Add(pageAssociation);

            await _context.SaveChangesAsync();
        }
Пример #10
0
        public async Task <int> CreateAsync(string copyName, string copyBody)
        {
            var newCopy = new CopyItem
            {
                CopyName    = copyName,
                CopyBody    = copyBody,
                DateAdded   = DateTime.Now,
                DateUpdated = DateTime.Now
            };

            _context.CopyItems.Add(newCopy);

            await _context.SaveChangesAsync();

            return(newCopy.CopyId);
        }
Пример #11
0
        public async Task <int> CreateAsync(string fontName, string fontType, string fontFilePath)
        {
            var newFont = new Font
            {
                FontName    = fontName,
                FontType    = fontType,
                FontPath    = fontFilePath,
                DateAdded   = DateTime.Now,
                DateUpdated = DateTime.Now
            };

            _context.Fonts.Add(newFont);

            await _context.SaveChangesAsync();

            return(newFont.FontId);
        }
Пример #12
0
        public async Task LogPageViewAsync(string area, string controller, string action, string referredUrl, string ipAddress, string userAgent, int?userId)
        {
            var newAnalyticPageView = new AnalyticPageView
            {
                Area        = area ?? "",
                Controller  = controller,
                Action      = action,
                ReferredUrl = referredUrl,
                IPAddress   = ipAddress,
                UserAgent   = userAgent,
                UserId      = userId ?? 0,
                DateAdded   = DateTime.Now
            };

            _context.AnalyticPageViews.Add(newAnalyticPageView);

            await _context.SaveChangesAsync();
        }
Пример #13
0
        public async Task <int> AddAsync(string pageName, string area, string controller, string action)
        {
            var newPage = new Page
            {
                PageName       = pageName,
                PageArea       = area,
                PageController = controller,
                PageAction     = action,
                DateAdded      = DateTime.Now,
                DateUpdated    = DateTime.Now
            };

            _context.Pages.Add(newPage);

            await _context.SaveChangesAsync();

            return(newPage.PageId);
        }
Пример #14
0
        public async Task EditAsync(string settingName, string settingValue)
        {
            var setting = await _context.Settings.FirstOrDefaultAsync(x => x.SettingName == settingName);

            if (setting == null)
            {
                return;
            }

            setting.SettingValue = settingValue;

            await _context.SaveChangesAsync();
        }
Пример #15
0
        public async Task <int> CreateAsync(string postTitle, int postCategoryId, int postAuthorUserId, string postDescription, string postBody)
        {
            var post = new Post
            {
                PostTitle        = postTitle,
                PostCategoryId   = postCategoryId,
                PostAuthorUserId = postAuthorUserId,
                PostDescription  = postDescription,
                PostBody         = postBody,
                DateAdded        = DateTime.Now,
                DateUpdated      = DateTime.Now
            };

            _context.Posts.Add(post);

            await _context.SaveChangesAsync();

            return(post.PostId);
        }
Пример #16
0
        public async Task AddAsync(int userId, int postId, string commentBody)
        {
            var comment = new PostComment
            {
                UserId      = userId,
                PostId      = postId,
                CommentBody = commentBody,
                DateAdded   = DateTime.Now
            };

            _context.PostComments.Add(comment);

            await _context.SaveChangesAsync();
        }
Пример #17
0
        public async Task <string> AddAsync(string emailAddress, UserTokenType userTokenType)
        {
            var user = await _userService.GetAsync(emailAddress);

            if (user == null)
            {
                return(string.Empty);
            }

            var userToken = new UserToken
            {
                UserId        = user.UserId,
                Token         = Guid.NewGuid().ToString(),
                UserTokenType = userTokenType,
                DateAdded     = DateTime.Now
            };

            _context.UserTokens.Add(userToken);

            await _context.SaveChangesAsync();

            return(userToken.Token);
        }
Пример #18
0
        public async Task <int?> RegisterAsync(string emailAddress, string password, string givenName, string familyName)
        {
            if (await _context.Users.AnyAsync(x => x.EmailAddress.Equals(emailAddress, StringComparison.OrdinalIgnoreCase)))
            {
                return(-1);
            }

            var userAccount = new User
            {
                EmailAddress    = emailAddress,
                Password        = GenerateSecurePassword(password),
                GivenName       = givenName,
                FamilyName      = familyName,
                AvatarImagePath = "/Areas/Admin/Content/Images/profile-image-male.png",
                DateAdded       = DateTime.Now,
                DateUpdated     = DateTime.Now
            };

            _context.Users.Add(userAccount);

            await _context.SaveChangesAsync();

            return(userAccount.UserId);
        }
Пример #19
0
        public async Task AddAsync(int pageSectionId, string containerElementId, string elementBody)
        {
            var pageSection = await _context.PageSections.SingleOrDefaultAsync(x => x.PageSectionId == pageSectionId);

            if (pageSection == null)
            {
                return;
            }

            var document = new Document(pageSection.PageSectionBody);

            document.AddElement(containerElementId, elementBody);

            pageSection.PageSectionBody = document.OuterHtml;

            await _context.SaveChangesAsync();
        }
Пример #20
0
        public async Task <PageAssociation> AddAsync(int pageId, int pageSectionTypeId, string componentStamp)
        {
            var page = await _context.Pages.SingleOrDefaultAsync(x => x.PageId == pageId);

            if (page == null)
            {
                return(null);
            }

            var sectionType = await _context.PageSectionTypes.SingleOrDefaultAsync(x => x.PageSectionTypeId == pageSectionTypeId);

            if (sectionType == null)
            {
                return(null);
            }

            var sectionPosition = 1;

            if (page.PageAssociations.Any())
            {
                sectionPosition = page.PageAssociations.Max(x => x.PageAssociationOrder) + 1;
            }

            var newPageAssociation = new PageAssociation
            {
                PageId      = pageId,
                PageSection = new PageSection
                {
                    PageSectionBody = sectionType.PageSectionTypeBody,
                },
                PageAssociationOrder = sectionPosition
            };

            _context.PageAssociations.Add(newPageAssociation);

            await _context.SaveChangesAsync();

            newPageAssociation.PageSection.PageSectionBody = Document.ReplaceTokens(newPageAssociation.PageSection.PageSectionBody, newPageAssociation.PageSection.PageSectionId, componentStamp);

            await _context.SaveChangesAsync();

            return(newPageAssociation);
        }