public CategoryController(CategoryContext context, IOptionsSnapshot <CategorySettings> settings)
        {
            _categoryContext = context ?? throw new ArgumentNullException(nameof(context));

            _settings = settings.Value;
            ((DbContext)context).ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking;
        }
        // GET: Home
        public ActionResult Index(int page = 1)
        {
            ProductContext db = new ProductContext();

            List <SelectListItem> categoryName = new List <SelectListItem>();
            CategoryContext       cc           = new CategoryContext();

            categoryName.Add(new SelectListItem {
                Text = "--Select--", Value = ""
            });
            foreach (var a in cc.Categories.ToList())
            {
                categoryName.Add(new SelectListItem {
                    Text = a.CategoryName, Value = a.CategoryID.ToString()
                });
            }

            var productView = new ProductViewModel
            {
                productPerPage = 5,
                product        = db.Products.OrderBy(d => d.ProductID),
                CurrentPage    = page
            };

            productView.CategoryName = categoryName;
            //Add a Dummy Row.
            //products.Insert(0, new Product());
            return(View(productView));
        }
Beispiel #3
0
        public void ProcessRequest(HttpContext context)
        {
            String uname   = context.Request.QueryString["uname"].ToString();
            String fvtname = context.Request.QueryString["fvtid"].ToString();


            CategoryContext categoryContext = new CategoryContext();
            Favourite       favourite       = categoryContext.Favourites.Where(f => f.Name.ToString().Equals(fvtname)).FirstOrDefault();
            List <Essay>    essays          = favourite.Essays.ToList <Essay>();

            String html = "<div class='content-header'>" +
                          "<nav aria-label='breadcrumb'></nav><a><h1 class='page-title'>" +
                          favourite.Name.ToString() + "</h1></a></div><div class='row'>" +
                          "<table class='table table-hover'><caption></caption>" +
                          "<thead><tr>" +
                          "<th width = '10px'></th>" +
                          "<th width = '10px'></th>" +
                          "<th width='75%'></th></thead><tbody>";

            foreach (Essay essay in essays)
            {
                String link        = essay.Url.ToString();
                String title       = essay.Title.ToString();
                String description = essay.Description.ToString();

                html += ("<tr><td><a href='javascript:void(0)'><i class='fa fa-star'></i></a></td>" +
                         "<td></td>" +
                         "<td style=' overflow: hidden; white-space: nowrap; text-overflow: ellipsis '><a href='" + link + "'target='_blank'><b>" + title + "</b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; " + description + "</a></td></tr>");
            }

            html += "</tbody></table>";
            context.Response.ContentType = "text/plain";
            context.Response.Write(html);
        }
        public void ProcessRequest(HttpContext context)
        {
            CategoryContext categoryContext = new CategoryContext();
            String          str             = context.Request.QueryString["str"];
            String          str2            = context.Request.QueryString["uname"];
            String          type            = context.Request.QueryString["type"];

            if (type.Equals("cty"))
            {
                Category category = new Category
                {
                    //Id = categoryContext.Configs.ToList<Config>()[0].max_cty_id,
                    Name     = str,
                    UserName = str2
                };
                categoryContext.Categories.Add(category);
            }
            else if (type.Equals("fvt"))
            {
                Favourite favorite = new Favourite
                {
                    //Id = categoryContext.Configs.ToList<Config>()[0].max_cty_id,
                    Name     = str,
                    UserName = str2
                };
                categoryContext.Favourites.Add(favorite);
            }

            categoryContext.SaveChanges();
        }
        public static List <Category> GetCategories()
        {
            CategoryContext catContext = new CategoryContext();
            var             ls         = catContext.Categories.ToList();

            return(ls);
        }
        internal PostPropertiesForm(CommandManager commandManager, CategoryContext categoryContext)
        {
            this.commandManager = commandManager;
            InitializeComponent();

            this.Name = "PostPropertiesForm";

            Text             = Res.Get(StringId.PostProperties);
            AccessibleName   = Text;
            buttonClose.Text = Res.Get(StringId.CloseButtonNoMnemonic);

            this.labelPageOrder.Text       = Res.Get(StringId.PropertiesPageOrder);
            this.labelPageParent.Text      = Res.Get(StringId.PropertiesPageParent);
            this.labelCategories.Text      = Res.Get(StringId.PropertiesCategories);
            this.labelPublishDate.Text     = Res.Get(StringId.PropertiesPublishDate);
            this.labelSlug.Text            = Res.Get(StringId.PropertiesSlug);
            this.labelComments.Text        = Res.Get(StringId.PropertiesComments);
            this.labelPings.Text           = Res.Get(StringId.PropertiesPings);
            this.labelTags.Text            = Res.Get(StringId.PropertiesKeywords);
            this.labelAuthor.Text          = Res.Get(StringId.PropertiesAuthor);
            this.labelPassword.Text        = Res.Get(StringId.PropertiesPassword);
            this.labelTrackbacks.Text      = Res.Get(StringId.PropertiesTrackbacks);
            this.labelExcerpt.Text         = Res.Get(StringId.PropertiesExcerpt);
            this.textPassword.PasswordChar = Res.PasswordChar;

            ControlHelper.SetCueBanner(textTrackbacks, Res.Get(StringId.PropertiesCommaSeparated));

            SuppressAutoRtlFixup = true;

            comboComments.Items.AddRange(new[] {
                new CommentComboItem(BlogCommentPolicy.Unspecified),
                new CommentComboItem(BlogCommentPolicy.None),
                new CommentComboItem(BlogCommentPolicy.Open),
                new CommentComboItem(BlogCommentPolicy.Closed),
            });

            comboPings.Items.AddRange(new[] {
                new TrackbackComboItem(BlogTrackbackPolicy.Unspecified),
                new TrackbackComboItem(BlogTrackbackPolicy.Allow),
                new TrackbackComboItem(BlogTrackbackPolicy.Deny),
            });

            InitializePropertyFields();

            controller = new SharedPropertiesController(
                this, labelCategories, categoryDropDown, labelTags, textTags, labelPageOrder, textPageOrder,
                labelPageParent, comboPageParent, labelPublishDate, datePublishDate, fields, categoryContext);

            this.comboComments.SelectedIndexChanged += controller.MakeDirty;
            this.comboPings.SelectedIndexChanged    += controller.MakeDirty;
            this.textSlug.TextChanged       += controller.MakeDirty;
            this.textPassword.TextChanged   += controller.MakeDirty;
            this.textExcerpt.TextChanged    += controller.MakeDirty;
            this.textTrackbacks.TextChanged += controller.MakeDirty;

            SimpleTextEditorCommandHelper.UseNativeBehaviors(commandManager,
                                                             textExcerpt, textPageOrder, textPassword,
                                                             textSlug, textTags, textTrackbacks);
        }
Beispiel #7
0
        public void CreatesACategoryContext()
        {
            var mockCategoryRepository = new MockCategoryRepository();
            var mockCategoryMapper     = new MockCategoryMapper();
            var categoryContext        = new CategoryContext(mockCategoryRepository, mockCategoryMapper);

            Assert.NotNull(categoryContext);
        }
        public ActionResult Categories()
        {
            CategoryContext c = new CategoryContext();



            return(View(c.GetAll()));
        }
Beispiel #9
0
        // GET: Home
        public ActionResult Index()
        {
            CategoryContext db         = new CategoryContext();
            List <Category> categories = db.Categories.ToList();

            //Add a Dummy Row.
            categories.Insert(0, new Category());
            return(View(categories));
        }
        public ActionResult Edit(int Id)
        {
            NewsContext newsContext = new NewsContext();

            ViewData["news"] = newsContext.GetNewsById(Id);
            CategoryContext categoryContext = new CategoryContext();

            ViewData["ListCategories"] = categoryContext.GetAllCategories();
            return(View());
        }
Beispiel #11
0
        public JsonResult InsertCategory(Category category)
        {
            using (CategoryContext entities = new CategoryContext())
            {
                entities.Categories.Add(category);
                entities.SaveChanges();
            }

            return(Json(category));
        }
Beispiel #12
0
        public void ContextBuildsAViewModelWithNewCategory()
        {
            var mockCategoryRepository = new MockCategoryRepository();
            var mockCategoryMapper     = new MockCategoryMapper();
            var categoryContext        = new CategoryContext(mockCategoryRepository, mockCategoryMapper);

            var viewModel = categoryContext.BuildViewModel();

            Assert.NotNull(viewModel);
        }
Beispiel #13
0
        public SharedPropertiesController(IWin32Window parentFrame, Label labelCategory, CategoryDropDownControlM1 categoryDropDown, Label labelTags, AutoCompleteTextbox textTags,
                                          Label labelPageOrder, NumericTextBox textPageOrder, Label labelPageParent, PageParentComboBox comboPageParent, Label labelPublishDate, PublishDateTimePicker datePublishDate, List <PropertyField> fields,
                                          CategoryContext categoryContext)
        {
            this.parentFrame      = parentFrame;
            this.labelCategory    = labelCategory;
            this.categoryDropDown = categoryDropDown;
            this.labelPublishDate = labelPublishDate;
            this.datePublishDate  = datePublishDate;
            this.fields           = fields;
            this.labelTags        = labelTags;
            this.textTags         = textTags;
            this.labelPageOrder   = labelPageOrder;
            this.textPageOrder    = textPageOrder;
            this.labelPageParent  = labelPageParent;
            this.comboPageParent  = comboPageParent;

            this.categoryDropDown.AccessibleName = Res.Get(StringId.CategoryControlCategories).Replace("{0}", " ").Trim();
            this.datePublishDate.AccessibleName  = Res.Get(StringId.PropertiesPublishDate);

            textTags.TextChanged   += MakeDirty;
            textTags.ButtonClicked += (sender, args) =>
            {
                _targetBlog.RefreshKeywords();
                LoadTagValues();
            };

            comboPageParent.SelectedIndexChanged += MakeDirty;
            textPageOrder.TextChanged            += MakeDirty;

            datePublishDate.ValueChanged += MakeDirty;

            DATETIME_PICKER_PROMPT = "'" + Res.Get(StringId.PublishDatePrompt).Replace("'", "''") + "'";
            // HACK ALERT - WinLive 209226: For RTL languages, we need to reverse the string, so it displays in the right direction
            // when right aligned. We need this hack because we are essentially using the CustomFormat string to display
            // the cue text. The control assumes this to be a valid format string and does a blind reverse on RTL languages
            // to mirror the date formatting. Unfortunately we don't need that mirroring for the cue text.
            // We reverse only if either the system (control panel setting) or UI is RTL, not if both are RTL.
            bool isUIRightToLeft     = BidiHelper.IsRightToLeft;
            bool isSystemRightToLeft = System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.IsRightToLeft;

            if ((isUIRightToLeft && !isSystemRightToLeft) || (!isUIRightToLeft && isSystemRightToLeft))
            {
                // Reverse the string
                char[] charArray = DATETIME_PICKER_PROMPT.ToCharArray();
                Array.Reverse(charArray);
                DATETIME_PICKER_PROMPT = new string(charArray);
            }
            datePublishDate.CustomFormat = DATETIME_PICKER_PROMPT;

            categoryDropDown.Initialize(parentFrame, categoryContext);

            InitializeFields();
            InitializeSync();
        }
Beispiel #14
0
        public void ProcessRequest(HttpContext context)
        {
            CategoryContext categoryContext = new CategoryContext();


            String userName = context.Request.QueryString["uname"].ToString();
            String url      = context.Request.QueryString["url"].ToString();
            String type     = context.Request.QueryString["type"].ToString();

            if (type.Equals("rss"))
            {
                String   ctyname  = context.Request.QueryString["ctyname"].ToString();
                Category category = categoryContext.Categories.Where(c => c.Name.ToString().Equals(ctyname)).FirstOrDefault();


                var    reader = XmlReader.Create(url);
                var    feed   = SyndicationFeed.Load(reader);
                String title  = feed.Title.Text.ToString();

                Rss rss = new Rss
                {
                    Name     = title,
                    UserName = userName,
                    Url      = url
                };

                category.Rsses.Add(rss);
                categoryContext.SaveChanges();
            }
            else if (type.Equals("essay"))
            {
                String    fvtname   = context.Request.QueryString["fvtname"].ToString();
                Favourite favourite = categoryContext.Favourites.Where(f => (f.UserName.ToString().Equals(userName) && f.Name.ToString().Equals(fvtname))).FirstOrDefault();

                List <String> tad         = getWebTitleAndDescription(url);
                String        title       = tad[0];
                String        description = tad[1];


                Essay essay = new Essay
                {
                    Url         = url,
                    Title       = title,
                    Description = description
                };

                favourite.Essays.Add(essay);
                categoryContext.SaveChanges();
            }



            //context.Response.ContentType = "text/plain";
            //context.Response.Write("");
        }
Beispiel #15
0
        public CategoryController(CategoryContext context)
        {
            _context = context;

            if (_context.Category.Count() == 0)
            {
                _context.Category.Add(new Category {
                    Name = "Cat1"
                });
                _context.SaveChanges();
            }
        }
Beispiel #16
0
 public ActionResult DeleteCategory(int prodID)
 {
     using (CategoryContext entities = new CategoryContext())
     {
         Category product = (from c in entities.Categories
                             where c.CategoryID == prodID
                             select c).FirstOrDefault();
         entities.Categories.Remove(product);
         entities.SaveChanges();
     }
     return(new EmptyResult());
 }
        /// <summary>
        /// I denne klasse opstilles der funktioner til at tilføje data til min database,
        /// når mit projekt startes. Dette bliver typisk kaldt for at 'Seed' en database.
        /// Jeg valgte at oprette en SeedData klasse så at der er noget data at teste med,
        /// frem for at mine API er tomme, og skal fyldes manuelt.
        /// </summary>
        /// <param name="serviceProvider"></param>
        public static void AddCategories(IServiceProvider serviceProvider)
        {
            ///<summary>
            /// Her specificeres hvilken service og context som skal bruges.
            /// IServiceProvider bruges til at hente vores context, som her er Category,
            /// som er påkrævet for at jeg kan tilføje nye dataobjekter.
            ///</summary>
            using (var context = new CategoryContext(
                       serviceProvider.GetRequiredService <DbContextOptions <CategoryContext> >()))
            {
                /// <summary>
                /// Vi bruger denne 'if' statement for at tjekke om der er nogen data elementer
                /// gemt via. vores context. Hvis der er, bliver de returneret.
                /// </summary>
                if (context.Categories.Any())
                {
                    return;
                }

                /// <summary>
                /// Her tilføjer jeg nye data elementer gennem min context.
                /// 'AddRange' lader mig tilføje flere elementer ad gangen,
                /// og vil så holde på dem indtil vi har gemt dem til databasen.
                /// </summary>
                context.Categories.AddRange(
                    new Category
                {
                    Name        = "Beverages",
                    Description = "Liquid beverages in various packaging. Includes juices, soft drinks, etc."
                },
                    new Category
                {
                    Name        = "Salty Snacks",
                    Description = "Bagged salty snackfoods. Includes various chips, nuts, etc."
                },
                    new Category
                {
                    Name        = "Frozen Vegetables",
                    Description = "Bagged frozen vegetable. Must be kept cool until used."
                },
                    new Category
                {
                    Name        = "Sweets",
                    Description = "Sweet baked goods and candy."
                }
                    );
                /// <summary>
                /// Her gemmer vi vores ændringer, så at vores elementer
                /// nu vil bliver tilføjet til databasen.
                /// </summary>
                context.SaveChanges();
            }
        }
Beispiel #18
0
        public CategoryController(CategoryContext context)
        {
            _context = context;

            if (_context.GetCategories.Count() == 0)
            {
                _context.GetCategories.Add(new Category {
                    Name = "Beer"
                });
                _context.SaveChanges();
            }
        }
        public ShowAdvertisementViewModel getEditAdvertisementModelForUser(string user_id, string user_name, int advertisement_id)
        {
            this.user_id   = user_id;
            this.user_name = user_name;

            AdvertisementsContext adv_ctx = new AdvertisementsContext();
            CategoryContext       cat_ctx = new CategoryContext();

            advertisement = adv_ctx.Advertisements.Where(a => a.Id.Equals(advertisement_id)).First();
            category      = cat_ctx.Categories.Where(a => a.Id.Equals(advertisement.category)).First().name;

            return(this);
        }
Beispiel #20
0
        //Получить список товаров заданной категории
        public List <Product> GetProductsByCategory(string categoryName)
        {
            List <Product> products = new List <Product>();

            using (CategoryContext categoryDB = new CategoryContext())
            {
                using (ProductContext productDB = new ProductContext())
                {
                    int catID = 0;
                    catID    = categoryDB.Categories.Where(x => x.Name == categoryName).Select(c => c.Id).First();
                    products = productDB.Products.Where(x => x.CategoryId == catID).ToList();
                }
            }
            return(products);
        }
Beispiel #21
0
        public PostPropertiesBandControl(CommandManager commandManager)
        {
            SetStyle(ControlStyles.UserPaint, true);
            SetStyle(ControlStyles.DoubleBuffer, true);
            SetStyle(ControlStyles.AllPaintingInWmPaint, true);
            SetStyle(ControlStyles.ResizeRedraw, true);

            InitializeComponent();

            categoryContext = new CategoryContext();

            controller = new SharedPropertiesController(this, null, categoryDropDown,
                                                        null, textTags, labelPageOrder, textPageOrder, labelPageParent, comboPageParent, null,
                                                        datePublishDate, fields, categoryContext);

            SimpleTextEditorCommandHelper.UseNativeBehaviors(commandManager,
                                                             textTags, textPageOrder);

            postPropertiesForm = new PostPropertiesForm(commandManager, categoryContext);
            if (components == null)
            {
                components = new Container();
            }
            components.Add(postPropertiesForm);

            postPropertiesForm.Synchronize(controller);

            commandManager.Add(CommandId.PostProperties, PostProperties_Execute);
            commandManager.Add(CommandId.ShowCategoryPopup, ShowCategoryPopup_Execute);


            linkViewAll.KeyDown += (sender, args) =>
            {
                if (args.KeyValue == ' ')
                {
                    linkViewAll_LinkClicked(sender, new LinkLabelLinkClickedEventArgs(null));
                }
            };

            // WinLive 180287: We don't want to show or use mnemonics on labels in the post properties band because
            // they can steal focus from the canvas.
            linkViewAll.Text            = TextHelper.StripAmpersands(Res.Get(StringId.ViewAll));
            linkViewAll.UseMnemonic     = false;
            labelPageParent.Text        = TextHelper.StripAmpersands(Res.Get(StringId.PropertiesPageParent));
            labelPageParent.UseMnemonic = false;
            labelPageOrder.Text         = TextHelper.StripAmpersands(Res.Get(StringId.PropertiesPageOrder));
            labelPageOrder.UseMnemonic  = false;
        }
Beispiel #22
0
        public ActionResult Index()
        {
            VModel models = new VModel();

            using (var db = new PostContext())
            {
                models.postsList = db.Post.ToList();
            }

            using (var db = new CategoryContext())
            {
                models.categories = db.Category.ToList();
            }

            return(View(models));
        }
        public ActionResult index()
        {
            NewsContext              newsBL     = new NewsContext();
            CategoryContext          categoryBL = new CategoryContext();
            Tuple <List <News>, int> getDatas   = newsBL.GetNewsOfPage(-1, 1, this.pageSize);
            int NumPage = getDatas.Item2 / this.pageSize;
            int div     = getDatas.Item2 % this.pageSize;

            if (div > 0)
            {
                NumPage++;
            }
            ViewData["ListNews"]       = Tuple.Create(getDatas.Item1, NumPage);
            ViewData["ListCategories"] = categoryBL.GetAllCategories();
            return(View());
        }
        public CategoriesController(CategoryContext _context)
        {
            context = _context;

            if (context.Categories.Count() == 0)
            {
                context.Categories.Add(new Category
                {
                    Name = "Groceries"
                });
                context.Categories.Add(new Category
                {
                    Name = "Entertainment"
                });
                context.SaveChanges();
            }
        }
Beispiel #25
0
        public CategoryDbFixture()
        {
            var builder = new ConfigurationBuilder().AddJsonFile("appsettings.json");

            configuration = builder.Build();
            context       = new CategoryContext(configuration);
            context.Categories.DeleteMany(Builders <Category> .Filter.Empty);
            context.Categories.InsertMany(new List <Category>
            {
                new Category {
                    Id = 101, Name = "Sports", CreatedBy = "Mukesh", Description = "All about sports", CreationDate = DateTime.Now
                },
                new Category {
                    Id = 102, Name = "Politics", CreatedBy = "Mukesh", Description = "INDIAN politics", CreationDate = DateTime.Now
                }
            });
        }
Beispiel #26
0
        public ActionResult GetPageNewsOfCategory(int CategoryId = 13)
        {
            NewsContext     newsContext     = new NewsContext();
            CategoryContext categoryContext = new CategoryContext();
            var             dataSet         = newsContext.GetNewsOfPage(CategoryId, 1, this.numPage);
            int             NumPage         = dataSet.Item2 % this.numPage;

            if (NumPage > 0)
            {
                NumPage = dataSet.Item2 / this.numPage + 1;
            }
            Tuple <List <News>, int, int> dataReturn = Tuple.Create(dataSet.Item1, NumPage, CategoryId);

            ViewData["ListNews"]     = dataReturn;
            ViewData["ListCategory"] = categoryContext.GetAllCategories();
            return(View());
        }
Beispiel #27
0
        public ActionResult Index()
        {
            NewsContext newsContext = new NewsContext();
            var         data        = newsContext.GetNewsOfPage(-1, 1, this.numPage);
            int         div         = data.Item2 % this.numPage;
            int         numPage     = data.Item2 / this.numPage;

            if (div > 0)
            {
                numPage++;
            }
            ViewData["ListNews"] = Tuple.Create(data.Item1, numPage);
            CategoryContext categoryContext = new CategoryContext();

            ViewData["ListCategory"] = categoryContext.GetAllCategories();
            return(View());
        }
        public void ProcessRequest(HttpContext context)
        {
            String          html            = "";
            String          ctyname         = context.Request.QueryString["ctyname"].ToString();
            String          uname           = context.Request.QueryString["uname"].ToString();
            CategoryContext categoryContext = new CategoryContext();
            List <Category> categories      = categoryContext.Categories.ToList <Category>();
            var             category        = categories.Where(c => c.UserName.Equals(uname)).Where(c => c.Name.Equals(ctyname)).Where(c => c.Rsses != null).FirstOrDefault();

            foreach (Rss r in category.Rsses)
            {
                html += "<li><a href='javascript:void(0)'class='rss-a' id='rssid-" + r.RssId.ToString() + "'> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp " + r.Name.ToString() +
                        " </a></li >";
            }

            context.Response.ContentType = "text/plain";
            context.Response.Write(html);
        }
Beispiel #29
0
        public void ContextSavesANewCategory()
        {
            var category = new Category {
                Id = 4, Description = "This is new category"
            };
            var categoryViewModel = new CategoryViewModel {
                Id = 4, Description = "This is a new category"
            };
            var mockCategoryRepository = new MockCategoryRepository();
            var mockCategoryMapper     = new MockCategoryMapper().StubMapToReturn(category);
            var categoryContext        = new CategoryContext(mockCategoryRepository, mockCategoryMapper);

            categoryContext.Save(categoryViewModel);

            mockCategoryRepository.VerifyGetByCalledWith(categoryViewModel.Id);
            mockCategoryRepository.VerifyAddCalledWith(category);
            mockCategoryMapper.VerifyMapCalledWith(categoryViewModel);
        }
Beispiel #30
0
        public void ContextBuildsAViewModelWithEditedCategory()
        {
            var category = new Category {
                Id = 2, Description = "This is category 2"
            };
            var categoryViewModel = new CategoryViewModel {
                Id = 2, Description = "This is category 2"
            };
            var mockCategoryRepository = new MockCategoryRepository().StubGetByIdToReturn(category);
            var mockCategoryMapper     = new MockCategoryMapper().StubMapToReturn(categoryViewModel);
            var categoryContext        = new CategoryContext(mockCategoryRepository, mockCategoryMapper);

            var viewModel = categoryContext.BuildViewModel(category.Id);

            Assert.NotNull(viewModel);
            mockCategoryRepository.VerifyGetByCalledWith(category.Id);
            mockCategoryMapper.VerifyMapCalledWith(category);
        }