示例#1
0
        public UnitOfWork(NicheShackContext context)
        {
            this.context = context;

            // Generic Repositories
            Categories         = new SearchableRepository <Category>(context);
            Niches             = new SearchableRepository <Niche>(context);
            Filters            = new SearchableRepository <Filter>(context);
            FilterOptions      = new SearchableRepository <FilterOption>(context);
            LeadPages          = new Repository <LeadPage>(context);
            LeadPageEmails     = new Repository <LeadPageEmail>(context);
            ProductEmails      = new Repository <ProductEmail>(context);
            Vendors            = new SearchableRepository <Vendor>(context);
            Pages              = new SearchableRepository <Page> (context);
            Emails             = new SearchableRepository <Email>(context);
            Media              = new SearchableRepository <Media>(context);
            Keywords           = new SearchableRepository <Keyword>(context);
            Notifications      = new Repository <Notification>(context);
            ProductFilters     = new Repository <ProductFilter>(context);
            ProductPricePoints = new Repository <ProductPricePoint>(context);
            PriceIndices       = new Repository <PriceIndex>(context);
            ProductContent     = new Repository <ProductContent>(context);
            ProductMedia       = new Repository <ProductMedia>(context);
            ProductKeywords    = new Repository <ProductKeyword>(context);
            NotificationText   = new Repository <NotificationText>(context);
            Subgroups          = new SearchableRepository <Subgroup>(context);
            SubgroupProducts   = new Repository <SubgroupProduct>(context);
            ProductReviews     = new Repository <ProductReview>(context);
            PageReferenceItems = new Repository <PageReferenceItem>(context);

            // Custom Repositories
            Products = new ProductRepository(context);
        }
示例#2
0
        private async Task CreateRows(IEnumerable <Row> rows, HtmlNode parent, NicheShackContext context)
        {
            foreach (Row row in rows)
            {
                // Create the row
                HtmlNode tr = await row.Create(parent, context);

                foreach (Column column in row.Columns)
                {
                    // Create the column
                    HtmlNode td = await column.Create(tr, context);


                    // Create the widget
                    Widget   widget     = GetWidget(column.WidgetData.WidgetType, column.WidgetData);
                    HtmlNode widgetNode = await widget.Create(td, context);

                    if (column.WidgetData.WidgetType == WidgetType.Container)
                    {
                        ContainerWidget container = (ContainerWidget)column.WidgetData;

                        if (container.Rows != null && container.Rows.Count() > 0)
                        {
                            await CreateRows(container.Rows, widgetNode, context);
                        }
                    }
                }
            }
        }
示例#3
0
        public UnitOfWork(NicheShackContext context)
        {
            this.context = context;

            Categories     = new CategoryRepository(context);
            ProductReviews = new ProductReviewRepository(context);
            Lists          = new ListRepository(context);
            ProductOrders  = new ProductOrderRepository(context);

            // Generic repositories
            Products             = new Repository <Product>(context);
            ProductMedia         = new Repository <ProductMedia>(context);
            ProductContent       = new Repository <ProductContent>(context);
            PricePoints          = new Repository <ProductPricePoint>(context);
            RefreshTokens        = new Repository <RefreshToken>(context);
            Collaborators        = new Repository <ListCollaborator>(context);
            Customers            = new Repository <Customer>(context);
            ListProducts         = new Repository <ListProduct>(context);
            Media                = new Repository <Media>(context);
            Notifications        = new Repository <Notification>(context);
            NotificationText     = new Repository <NotificationText>(context);
            Pages                = new Repository <Page>(context);
            OrderProducts        = new Repository <OrderProduct>(context);
            ProductKeywords      = new Repository <ProductKeyword>(context);
            Keywords             = new Repository <Keyword>(context);
            KeywordSearchVolumes = new Repository <KeywordSearchVolume>(context);
            ProductFilters       = new Repository <ProductFilter>(context);
            Niches               = new Repository <Niche>(context);
            PageReferenceItems   = new Repository <PageReferenceItem>(context);
        }
 public override async Task SetData(NicheShackContext context, QueryParams queryParams)
 {
     if (Background != null && Background.Image != null)
     {
         await Background.Image.SetData(context);
     }
 }
 public EmailWorkerService(IServiceScopeFactory serviceScopeFactory, EmailService emailService, IConfiguration configuration)
 {
     scope              = serviceScopeFactory.CreateScope();
     context            = scope.ServiceProvider.GetRequiredService <NicheShackContext>();
     this.emailService  = emailService;
     this.configuration = configuration;
 }
示例#6
0
 // ..................................................................................Init....................................................................
 public async Task Init(NicheShackContext context)
 {
     SetFilters();
     await SetFilteredProducts(context);
     await SetKeywords(context);
     await UpdateQueries(Queries, context);
 }
        private async Task SetData(IEnumerable <Row> rows, NicheShackContext context, QueryParams queryParams)
        {
            foreach (Row row in rows)
            {
                if (row.Background != null && row.Background.Image != null)
                {
                    await row.Background.Image.SetData(context);
                }

                foreach (Column column in row.Columns)
                {
                    if (column.Background != null && column.Background.Image != null)
                    {
                        await column.Background.Image.SetData(context);
                    }


                    // Create the widget
                    Widget widget = page.GetWidget(column.WidgetData.WidgetType, column.WidgetData);


                    await widget.SetData(context, queryParams);

                    if (column.WidgetData.WidgetType == WidgetType.Container)
                    {
                        ContainerWidget container = (ContainerWidget)column.WidgetData;

                        if (container.Rows != null && container.Rows.Count() > 0)
                        {
                            await SetData(container.Rows, context, queryParams);
                        }
                    }
                }
            }
        }
        // .........................................................................Get Recipient Ids.....................................................................
        private async Task <List <string> > GetRecipientIds(NicheShackContext context, EmailType emailType, string listId, string customerId)
        {
            Expression <Func <ListCollaborator, bool> > predicate = null;

            switch (emailType)
            {
            case EmailType.NewCollaborator:
                predicate = x => x.Customer.EmailPrefNewCollaborator == true;
                break;

            case EmailType.RemovedListItem:
                predicate = x => x.Customer.EmailPrefRemovedListItem == true;
                break;

            case EmailType.AddedListItem:
                predicate = x => x.Customer.EmailPrefAddedListItem == true;
                break;

            case EmailType.ListNameChange:
                predicate = x => x.Customer.EmailPrefListNameChange == true;
                break;
            }

            return(await context.ListCollaborators
                   .AsNoTracking()
                   .Where(x => x.ListId == listId && x.CustomerId != customerId && !x.IsRemoved)
                   .Where(predicate)
                   .Select(x => x.CustomerId)
                   .ToListAsync());
        }
示例#9
0
        public async override Task <HtmlNode> Create(HtmlNode column, NicheShackContext context)
        {
            // Call the base
            HtmlNode textWidget = await base.Create(column, context);

            // Select the td node
            HtmlNode td = textWidget.SelectSingleNode("tr/td");

            // Height
            if (Height > 0)
            {
                td.SetAttributeValue("height", Height.ToString());
                td.SetAttributeValue("style", "height: " + Height + "px;");
            }

            // Apply the styles
            td.SetAttributeValue("style", "font-family: Arial, Helvetica, sans-serif;font-size: 14px;color: #000000;line-height: normal;");
            if (Background != null)
            {
                await Background.SetStyle(td, context);
            }
            if (Padding != null)
            {
                Padding.SetStyle(td);
            }

            // Assign the content
            td.InnerHtml = HtmlContent;

            return(textWidget);
        }
示例#10
0
        public async override Task <HtmlNode> Create(HtmlNode column, NicheShackContext context)
        {
            // Call the base
            HtmlNode widget = await base.Create(column, context);


            // Td
            HtmlNode td = widget.SelectSingleNode("tr/td");


            td.SetAttributeValue("style", "border-bottom: " + Border.Width + "px " + Border.Style + " " + Border.Color + ";");
            if (Shadow != null)
            {
                Shadow.SetStyle(td);
            }


            HtmlNode blankRow    = widget.InsertBefore(HtmlNode.CreateNode("<tr>"), widget.SelectSingleNode("tr"));
            HtmlNode blankColumn = blankRow.AppendChild(HtmlNode.CreateNode("<td>"));

            blankColumn.SetAttributeValue("height", "10");


            blankRow    = widget.AppendChild(HtmlNode.CreateNode("<tr>"));
            blankColumn = blankRow.AppendChild(HtmlNode.CreateNode("<td>"));
            blankColumn.SetAttributeValue("height", "10");


            return(widget);
        }
        private async Task <string> GetStarsImage(int rating, NicheShackContext context)
        {
            string imageName = null;

            switch (rating)
            {
            case 1:
                imageName = "One Star";
                break;

            case 2:
                imageName = "Two Stars";
                break;

            case 3:
                imageName = "Three Stars";
                break;

            case 4:
                imageName = "Four Stars";
                break;

            case 5:
                imageName = "Five Stars";
                break;
            }


            return(await context.Media
                   .AsNoTracking()
                   .Where(x => x.Name == imageName)
                   .Select(x => x.Url)
                   .SingleAsync());
        }
示例#12
0
        public override async Task SetData(NicheShackContext context, QueryParams queryParams)
        {
            await Image.SetData(context);

            if (Link != null)
            {
                await Link.SetData(context);
            }
        }
        public async Task SetData(NicheShackContext context)
        {
            await Image.SetData(context);

            if (Link != null)
            {
                await Link.SetData(context);
            }
        }
示例#14
0
        public async Task <HtmlNode> Create(HtmlNode table, NicheShackContext context)
        {
            // Insert a row for spacing
            if (Top > 0)
            {
                HtmlNode blankRow    = table.AppendChild(HtmlNode.CreateNode("<tr>"));
                HtmlNode blankColumn = blankRow.AppendChild(HtmlNode.CreateNode("<td>"));
                blankColumn.SetAttributeValue("height", Top.ToString());
            }

            // Create the row
            HtmlNode row = table.AppendChild(HtmlNode.CreateNode("<tr>"));

            // Set the styles
            if (Background != null)
            {
                await Background.SetStyle(row, context);
            }
            if (Border != null)
            {
                Border.SetStyle(row);
            }
            if (Corners != null)
            {
                Corners.SetStyle(row);
            }
            if (Shadow != null)
            {
                Shadow.SetStyle(row);
            }
            if (Padding != null)
            {
                Padding.SetStyle(row);
            }

            string valign;

            switch (VerticalAlignment)
            {
            case "center":
                valign = "middle";
                break;

            case "flex-end":
                valign = "bottom";
                break;

            default:
                valign = "top";
                break;
            }

            row.SetAttributeValue("valign", valign);

            return(row);
        }
 public async override Task SetData(NicheShackContext context, QueryParams queryParams)
 {
     if (Banners != null)
     {
         foreach (LinkableImage banner in Banners)
         {
             await banner.SetData(context);
         }
     }
 }
示例#16
0
 public UnitOfWork(NicheShackContext context)
 {
     this.context   = context;
     Repository     = new Repository(context);
     Categories     = new CategoryRepository(context);
     Products       = new ProductRepository(context);
     Orders         = new OrderRepository(context);
     Lists          = new ListRepository(context);
     ProductReviews = new ProductReviewRepository(context);
 }
示例#17
0
        public async override Task <HtmlNode> Create(HtmlNode column, NicheShackContext context)
        {
            // Call the base
            HtmlNode widget = await base.Create(column, context);

            // Td
            HtmlNode td = widget.SelectSingleNode("tr/td");


            // Image
            HtmlNode img = HtmlNode.CreateNode("<img>");

            if (Width > 0)
            {
                img.SetAttributeValue("style", "width: " + Width + "px;");
            }


            // Set the styles
            if (Border != null)
            {
                Border.SetStyle(img);
            }
            if (Corners != null)
            {
                Corners.SetStyle(img);
            }
            if (Shadow != null)
            {
                Shadow.SetStyle(img);
            }


            await Image.SetStyle(img, context);

            if (Link != null && Link.Url != null)
            {
                // Anchor
                HtmlNode anchorNode = HtmlNode.CreateNode("<a>");
                Link.SetStyle(anchorNode);

                anchorNode.AppendChild(img);

                td.AppendChild(anchorNode);
                return(anchorNode);
            }
            else
            {
                td.AppendChild(img);
                return(img);
            }
        }
        // .........................................................................Setup Removed Collaborator.....................................................................
        private async Task SetupRemovedCollaborator(NicheShackContext context, object state)
        {
            EmailSetupParams emailSetupParams = (EmailSetupParams)state;

            // Get the customer id
            string customerId = await context.ListCollaborators
                                .AsNoTracking()
                                .Where(x => x.Id == emailSetupParams.CollaboratorId && x.Customer.EmailPrefRemovedCollaborator == true)
                                .Select(x => x.CustomerId)
                                .SingleOrDefaultAsync();


            if (customerId == null)
            {
                return;
            }


            // Get the recipient
            var recipient = await context.Customers
                            .AsNoTracking()
                            .Where(x => x.Id == customerId)
                            .Select(x => new
            {
                firstName = x.FirstName,
                lastName  = x.LastName,
                email     = x.Email
            }).SingleAsync();



            // Get the list
            string list = await context.Lists
                          .AsNoTracking()
                          .Where(x => x.Id == emailSetupParams.ListId1)
                          .Select(x => x.Name).SingleAsync();



            // Add email to queue
            emailService.AddToQueue(EmailType.RemovedCollaborator, "Removed from list", new Recipient
            {
                Email     = recipient.email,
                FirstName = recipient.firstName,
                LastName  = recipient.lastName
            }, new EmailProperties
            {
                Host = emailSetupParams.Host,
                Var1 = list
            });
        }
示例#19
0
        // ..................................................................................Update Queries....................................................................
        async Task UpdateQueries(IEnumerable <Query> queries, NicheShackContext context)
        {
            if (queries != null && queries.Count() > 0)
            {
                foreach (Query query in queries)
                {
                    // Auto
                    if (query.QueryType == QueryType.Auto && query.IntValue == 2)
                    {
                        query.IntValues = await context.Products
                                          .AsNoTracking()
                                          .Where(x => x.Id == ProductId)
                                          .Select(x => x.NicheId).ToListAsync();
                    }

                    // Product Subgroup
                    else if (query.QueryType == QueryType.ProductSubgroup)
                    {
                        query.IntValues = await context.SubgroupProducts
                                          .AsNoTracking()
                                          .Where(x => x.SubgroupId == query.IntValue)
                                          .Select(x => x.ProductId).ToListAsync();
                    }

                    // Product Keywords
                    else if (query.QueryType == QueryType.ProductKeywords)
                    {
                        List <int> keywordIds = await context.ProductKeywords
                                                .AsNoTracking()
                                                .Where(x => query.StringValues.Contains(x.Keyword.Name))
                                                .Select(x => x.Keyword.Id).Distinct()
                                                .ToListAsync();


                        query.IntValues = await context.ProductKeywords
                                          .Where(x => keywordIds.Contains(x.KeywordId))
                                          .Select(x => x.ProductId)
                                          .ToListAsync();
                    }

                    // Subquery
                    else if (query.QueryType == QueryType.SubQuery)
                    {
                        await UpdateQueries(query.SubQueries, context);
                    }
                }
            }
        }
示例#20
0
        public override async Task SetData(NicheShackContext context, QueryParams queryParams)
        {
            List <ItemData> itemData = null;


            if (ShopType == ShopType.Category)
            {
                itemData = await context.Categories
                           .AsNoTracking()
                           .Where(x => Items.Select(z => z.Id).ToList().Contains(x.Id))
                           .Select(x => new ItemData
                {
                    Id      = x.Id,
                    Name    = x.Name,
                    ImageId = (int)x.ImageId
                })
                           .ToListAsync();
            }
            else
            {
                itemData = await context.Niches
                           .AsNoTracking()
                           .Where(x => Items.Select(z => z.Id).ToList().Contains(x.Id))
                           .Select(x => new ItemData
                {
                    Id      = x.Id,
                    Name    = x.Name,
                    ImageId = (int)x.ImageId
                })
                           .ToListAsync();
            }


            foreach (ShopItem item in Items)
            {
                ItemData data = itemData.Where(x => x.Id == item.Id).Single();
                item.Name    = data.Name;
                item.Icon    = new Image();
                item.Icon.Id = data.ImageId;
                await item.Icon.SetData(context);

                if (item.Link != null)
                {
                    await item.Link.SetData(context);
                }
            }
        }
示例#21
0
        public async Task SetData(NicheShackContext context)
        {
            if (SelectedOption != LinkOption.Page && SelectedOption != LinkOption.Product)
            {
                return;
            }

            if (SelectedOption == LinkOption.Page)
            {
                var page = await context.Pages
                           .AsNoTracking()
                           .Where(x => x.Id == Id)
                           .Select(x => new
                {
                    x.Name,
                    x.DisplayType,
                    x.UrlName,
                    x.UrlId
                })
                           .SingleOrDefaultAsync();

                if (page != null)
                {
                    OptionValue = page.Name;
                    Url         = GetPageDisplay((PageDisplayType)page.DisplayType) + page.UrlName + "/" + page.UrlId;
                }
            }
            else if (SelectedOption == LinkOption.Product)
            {
                var product = await context.Products
                              .AsNoTracking()
                              .Where(x => x.Id == Id)
                              .Select(x => new
                {
                    x.Name,
                    x.UrlName,
                    x.UrlId
                })
                              .SingleOrDefaultAsync();

                if (product != null)
                {
                    OptionValue = product.Name;
                    Url         = product.UrlName + "/" + product.UrlId;
                }
            }
        }
        // .........................................................................Setup Added List Item Email.....................................................................
        private async Task SetupAddedListItemEmail(NicheShackContext context, object state)
        {
            EmailSetupParams emailSetupParams = (EmailSetupParams)state;

            List <string> recipientIds = await GetRecipientIds(context, EmailType.AddedListItem, emailSetupParams.ListId1, emailSetupParams.CustomerId);

            EmailParams emailParams = await GetEmailParams(context, emailSetupParams.CustomerId, emailSetupParams.ListId1, emailSetupParams.Host, recipientIds, emailSetupParams.ProductId);

            if (emailParams == null)
            {
                return;
            }


            // Add emails to the queue
            SubmitAddedListItemEmailsToQueue(emailParams);
        }
示例#23
0
        public async Task SetData(NicheShackContext context)
        {
            Image image = await context.Media
                          .AsNoTracking()
                          .Where(x => x.Id == Id)
                          .Select(x => new Image
            {
                Name = x.Name,
                Url  = x.Url
            })
                          .SingleOrDefaultAsync();

            // If this image exists
            if (image != null)
            {
                Name = image.Name;
                Url  = image.Url;
            }
        }
示例#24
0
        public async override Task SetData(NicheShackContext context, QueryParams queryParams)
        {
            if (Queries != null)
            {
                queryParams.Queries = Queries;
            }

            if (queryParams.Queries != null || queryParams.Search != null)
            {
                queryParams.Limit       = 40;
                queryParams.UsesFilters = true;
                if (queryParams.Page == 0)
                {
                    queryParams.Page = 1;
                }
                QueryService queryService = new QueryService(context);
                GridData = await queryService.GetGridData(queryParams);
            }
        }
示例#25
0
        public virtual async Task <HtmlNode> Create(HtmlNode column, NicheShackContext context)
        {
            // Create the table
            HtmlNode table = await Table.Create(column, new TableOptions
            {
                Width = Width,
                HorizontalAlignment = HorizontalAlignment,
                CreateRow           = true
            }, context);


            HtmlNode td = table.SelectSingleNode("tr/td");

            td.SetAttributeValue("valign", "top");

            column.AppendChild(new HtmlDocument().CreateComment(Table.MicrosoftIf + "</td></tr></table>" + Table.MicrosoftEndIf));

            return(table);
        }
示例#26
0
        public UnitOfWork(NicheShackContext context)
        {
            this.context = context;

            Categories     = new CategoryRepository(context);
            Products       = new ProductRepository(context);
            ProductReviews = new ProductReviewRepository(context);
            Lists          = new ListRepository(context);
            ProductOrders  = new ProductOrderRepository(context);

            // Generic repositories
            Media          = new Repository <ProductMedia>(context);
            ProductContent = new Repository <ProductContent>(context);
            PricePoints    = new Repository <ProductPricePoint>(context);
            RefreshTokens  = new Repository <RefreshToken>(context);
            Collaborators  = new Repository <ListCollaborator>(context);
            Customers      = new Repository <Customer>(context);
            ListProducts   = new Repository <ListProduct>(context);
        }
        // .........................................................................Setup Email.....................................................................
        private async Task SetupEmail(NicheShackContext context, object state)
        {
            EmailSetupParams emailSetupParams = (EmailSetupParams)state;

            Recipient recipient = await context.Customers
                                  .AsNoTracking()
                                  .Where(x => x.Id == emailSetupParams.CustomerId && x.EmailPrefReview == true)
                                  .Select(x => new Recipient
            {
                FirstName = x.FirstName,
                LastName  = x.LastName,
                Email     = x.Email
            })
                                  .SingleOrDefaultAsync();

            if (recipient == null)
            {
                return;
            }


            ProductData product = await context.Products
                                  .AsNoTracking()
                                  .Where(x => x.Id == emailSetupParams.ProductId)
                                  .Select(x => new ProductData
            {
                Name  = x.Name,
                Image = x.Media.Url,
                Url   = emailSetupParams.Host + "/" + x.UrlName + "/" + x.UrlId
            }).SingleAsync();



            emailService.AddToQueue(EmailType.Review, "Thank you for reviewing " + product.Name + " on Niche Shack", recipient, new EmailProperties
            {
                Host    = emailSetupParams.Host,
                Product = product,
                Stars   = await GetStarsImage(emailSetupParams.ProductRating, context),
                Var1    = emailSetupParams.Title,
                Var2    = emailSetupParams.Text
            });
        }
示例#28
0
        public async Task SetData(NicheShackContext context)
        {
            Video video = await context.Media
                          .AsNoTracking()
                          .Where(x => x.Id == Id)
                          .Select(x => new Video
            {
                Thumbnail = x.Thumbnail,
                Url       = x.Url
            })
                          .SingleOrDefaultAsync();


            // If this video exists
            if (video != null)
            {
                Thumbnail = video.Thumbnail;
                Url       = video.Url;
            }
        }
示例#29
0
        public async Task SetStyle(HtmlNode node, NicheShackContext context)
        {
            await SetData(context);


            if (Name == "Product Placeholder")
            {
                Name = "{productName}";
                Url  = "{productImage}";
            }
            else if (Name == "Stars Placeholder")
            {
                Name = "Product Rating";
                Url  = "{stars}";
            }

            node.SetAttributeValue("src", "{host}/images/" + Url);
            node.SetAttributeValue("title", Name);
            node.SetAttributeValue("alt", Name);
        }
示例#30
0
        private async Task SetKeywords(NicheShackContext context)
        {
            if (Search == null || Search == string.Empty)
            {
                return;
            }

            int keywordId = await context.Keywords
                            .AsNoTracking()
                            .Where(x => x.Name == Search)
                            .Select(x => x.Id)
                            .SingleOrDefaultAsync();

            if (keywordId > 0)
            {
                KeywordProductIds = await context.ProductKeywords
                                    .AsNoTracking()
                                    .Where(x => x.KeywordId == keywordId)
                                    .Select(x => x.ProductId)
                                    .ToListAsync();
            }
        }