Ejemplo n.º 1
0
        private void SearchButton_Click(object sender, EventArgs e)
        {
            string keyWord = KeywordTextBox.Text;

            CheckIfAtLeastOneWebsiteIsSelected();

            // Using Selenium to get products from e-commerece webiste.
            IGettingProductsFromWebsite gettingProductsBySelenium = new GettingProductsBySelenium();
            IEFProductRepository        productRepository         = new EFProductRepository();
            var listingProducts = new ListingProductsInteractor(gettingProductsBySelenium, productRepository);
            List <ProductDetails> searchResult;
            // -----------------------------------------------------------

            // Looping through existed websites to fetch products from.
            bool IsDataFetched = false;

            foreach (Control item in groupBox1.Controls)
            {
                if (item is CheckBox && ((CheckBox)item).Checked)
                {
                    searchResult = listingProducts.ListProducts(keyWord, ((CheckBox)item).Tag.ToString());
                    listingProducts.SaveSearchResultToDB(searchResult);
                    IsDataFetched = true;
                }
            }
            // ------------------------------------------------------

            // After fetching and saving the data, refresh the grid and filter it.
            if (IsDataFetched)
            {
                refreshGrid();
                filterTextBox1.Text = keyWord;
            }
        }
        public void TestAddingAndRemovingProduct()
        {
            IProductCategoryRepository productCategoryRepository = new EFProductCategoryRepository(context);
            var pizzaCategory = productCategoryRepository.ProductCategoryRepository.First(pc => pc.Name == "Pizza");

            IProductRepository productRepository = new EFProductRepository(context);
            var product = new Product
            {
                Allergens = new List <Allergen>
                {
                    new Allergen {
                        Description = "Opis alergenu", Title = "JakisAlergen"
                    }
                },
                Description     = "OpisOpisOpisOpis",
                BasePrice       = 29.99m,
                PrepareTime     = TimeSpan.FromMinutes(30),
                ProductCategory = pizzaCategory,
                Title           = "Wiejska"
            };

            productRepository.AddNewProduct(product);

            Assert.IsTrue(productRepository.ProductRepository.Any(p => p.Title == "Wiejska"), "Added product not in the database");
            Assert.IsTrue(context.Allergens.Any(al => al.Title == "JakisAlergen"), "Added allergen not in the database");

            productRepository.RemoveProduct(product);
            Assert.IsFalse(productRepository.ProductRepository.Any(p => p.Title == "Wiejska"), "Removed product still in the database");
            Assert.IsTrue(context.Allergens.Any(al => al.Title == "JakisAlergen"), "Allergen not in database");
        }
Ejemplo n.º 3
0
        public Product GetProduct(int id)
        {
            EFProductRepository repo = new EFProductRepository();
            var prod = repo.Products.Where(x => x.ProductID == id).SingleOrDefault();

            return prod != null ? prod : null;
        }
        /// <summary>
        /// Registers the type mappings with the Unity container.
        /// </summary>
        /// <param name="container">The unity container to configure.</param>
        /// <remarks>
        /// There is no need to register concrete types such as controllers or
        /// API controllers (unless you want to change the defaults), as Unity
        /// allows resolving a concrete type even if it was not previously
        /// registered.
        /// </remarks>
        public static void RegisterTypes(IUnityContainer container)
        {
            // NOTE: To load from web.config uncomment the line below.
            // Make sure to add a Unity.Configuration to the using statements.
            // container.LoadConfiguration();

            EFProductRepository newRepo = new EFProductRepository();

            // Register your type's mappings here.
            #region mock construct
            //var mock = new Mock<IProductRepository>();
            //mock.Setup(m => m.Products).Returns(GetProductsList());
            //container.RegisterInstance<IProductRepository>(mock.Object); //note this repository object is shared by all browser sessions.
            #endregion

            //use Hangfire somewhere??.
            container.RegisterInstance <IProductRepository>(newRepo); //note this is a singleton shared by all controllers, and by all borwser requests.

            #region container examples
            //container.RegisterType<IOrderProcessor, EmailOrderProcessor>(new InjectionConstructor(emailSettings));

            //container.RegisterType<IEmail, Email>(new InjectionFactory(c => new Email("To Name","*****@*****.**")));
            //var email = container.Resolve<IEmail>();
            //container.RegisterType<OperationEntity>("email", new ContainerControlledLifetimeManager(), new InjectionConstructor(email));

            //container.RegisterType<IEmail, Email>(new ContainerControlledLifetimeManager(), new InjectionFactory(c => new Email("To Name","*****@*****.**")));
            //var opEntity = container.Resolve<OperationEntity>();

            //container.RegisterType<IEmail, Email>(new ContainerControlledLifetimeManager());

            //    container.RegisterType<IDemo, Demo>(new ContainerControlledLifetimeManager());
            //    var demoA = container.Resolve<IDemo>();
            //    var demoB = container.Resolve<IDemo>();
            #endregion
        }
Ejemplo n.º 5
0
 public EFUnitOfWork()
 {
     _dBContest            = new AppDBContext();
     ProductRepository     = new EFProductRepository(_dBContest);
     ProductTypeRepository = new EFProductTypeRepository(_dBContest);
     StoreRepository       = new EFStoreRepository(_dBContest);
     BookingRepository     = new EFBookingRepository(_dBContest);
 }
        public void Editing_Product_Exist()
        {
            //arrange
            //var products = new Product[]
            //{
            //    new Product {Id = 1 , Name = "P1"},
            //    new Product {Id = 2 , Name = "P2"},
            //    new Product {Id = 3 , Name = "P3"},
            //}.AsQueryable<Product>();
            //var productsMock = new Mock<DbSet<Product>>();
            //productsMock.Setup(x => x.AddRange(products));
            //var options = new Mock<DbContextOptions<AppDbContext>>();


            //var appContextMock = new Mock<AppDbContext>(options.Object) ;
            //appContextMock.Setup(x => x.Set<Product>()).Returns(productsMock.Object);


            //appContextMock.Setup(x => x.Products).Returns(productsMock.Object);
            //var eFProductRepository = new EFProductRepository(appContextMock.Object);

            //eFProductRepository.SaveProduct(new Product { Id = 1, Name = "zmienione" });
            //var result = eFProductRepository.Products.FirstOrDefault(m => m.Id == 1);
            //Assert.Equal("zmienione", result.Name);


            var builder = new DbContextOptionsBuilder <AppDbContext>().UseInMemoryDatabase(databaseName: "C:/USERS/DYMION/SOURCE/REPOS/SPORT STORE/SPORT STORE.TEST/TESTSDATABASE.MDF").Options;

            using (var context = new AppDbContext(builder))
            {
                var ef       = new EFProductRepository(context);
                var products = new Product[]
                {
                    new Product {
                        Id = 1, Name = "P1"
                    },
                    new Product {
                        Id = 2, Name = "P2"
                    },
                    new Product {
                        Id = 3, Name = "P3"
                    },
                }.AsQueryable <Product>();

                context.Products.AddRange(products);
                context.SaveChanges();
                ef.SaveProduct(new Product {
                    Id = 1, Name = "zmienione"
                });
                var result = ef.Products.FirstOrDefault(m => m.Id == 1);
                Assert.Equal("zmienione", result.Name);
            }
            //var mock = MockDbSetup.MockAppDbContext();
            //var ef = new EFProductRepository(mock.Object);
            //ef.SaveProduct(new Product { Id = 1, Name = "zmienione" });
            //var result = ef.Products.FirstOrDefault(m => m.Id == 1);
            //Assert.Equal("zmienione", result.Name);
        }
        // GET: Nav
        public PartialViewResult Menu(string category = null)
        {
            ViewBag.SelectedCategory = category;
            IProductRepository   repository = new EFProductRepository();
            IEnumerable <string> categories = repository.Products.Select(p => p.Category)
                                              .Distinct().OrderBy(x => x);

            return(PartialView(categories));
        }
Ejemplo n.º 8
0
        // GET api/<controller>
        public IEnumerable <Product> Get()
        {
            IProductRepository repository = new EFProductRepository();

            IEnumerable <Product> prodNames = repository.Products;

            //IEnumerable<string> prodNames = repository.Products.Select(p => p.Name).ToList();
            return(prodNames);
        }
        public void TestChangingProduct()
        {
            IProductRepository repository = new EFProductRepository(context);
            var product = repository.ProductRepository.First(pr => pr.Title == "Cheese Burger");

            product.BasePrice = 50m;
            repository.ChangeProduct(product, product);

            Assert.IsTrue(repository.ProductRepository.Any(pr => pr.Title == "Cheese Burger" && pr.BasePrice == 50m));
        }
Ejemplo n.º 10
0
        // GET: Reviews/Create
        public IActionResult Create(int?productId)
        {
            ViewBag.ProductId = productId;
            EFProductRepository db = new EFProductRepository();

            ViewBag.product = db.Products
                              .Include(p => p.Reviews)
                              .FirstOrDefault(p => p.ProductId == productId);
            //ViewData["ProductId"] = new SelectList(_context.Product, "ProductId", "ProductId");
            return(View());
        }
        public void SaveProductTest()
        {
            // Arrange - create a repository
            EFProductRepository target = new EFProductRepository();

            // Act - change the category of the first product
            Product prod = target.Products.First();

            prod.Category = "Test";
            target.SaveProduct(prod);
        }
Ejemplo n.º 12
0
        public RedirectToRouteResult RemoveCart(Cart cart, int ProductId, String returnUrl)
        {
            EFProductRepository repository = new EFProductRepository();
            Product             product    = repository.Products.FirstOrDefault(p => p.ProductId == ProductId);

            if (product != null)
            {
                cart.Remove(product);
            }
            return(RedirectToAction("Index", new { returnUrl }));
        }
Ejemplo n.º 13
0
        public void Configuration(IAppBuilder app)
        {
            IProductRepository repo = new EFProductRepository();

            // new ProductController(repo).List(null, "Sort", 1);

            //Category deletedCategory = repo.DeleteCategory(10);
            // настраиваем контекст и менеджер
            app.CreatePerOwinContext <ApplicationDbContext>(ApplicationDbContext.Create);
            app.CreatePerOwinContext <ApplicationUserManager>(ApplicationUserManager.Create);
            app.CreatePerOwinContext <ApplicationSignInManager>(ApplicationSignInManager.Create);
            app.UseCookieAuthentication(new CookieAuthenticationOptions
            {
                AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
                LoginPath          = new PathString("/Account/Login"),
            });
        }
Ejemplo n.º 14
0
        // GET api/<controller>/5
        public HttpResponseMessage Get(int id)
        {
            EFProductRepository repo = new EFProductRepository();

            var prod = repo.Products.SingleOrDefault(p => p.ProductID == id);

            HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK);
            Stream strm = new MemoryStream(prod.ImageData);

            response.Content = new StreamContent(strm);
            response.Content.Headers.ContentType                 = new System.Net.Http.Headers.MediaTypeHeaderValue("application/octet-stream");
            response.Content.Headers.ContentDisposition          = new System.Net.Http.Headers.ContentDispositionHeaderValue("attachment");
            response.Content.Headers.ContentDisposition.FileName = "hyundai.apk";

            repo = null;

            return(response);
        }
        public RepositoriesTest()
        {
            _productRepository = new EFProductRepository(
                _context
                );

            _productCategoryRepository = new EFProductCategoryRepository(
                _context
                );

            _productUserRepository = new EFProductUserRepository(
                _context
                );

            _userRepository = new EFUserRepository(
                _context
                );
        }
Ejemplo n.º 16
0
        public void Add(Product product)
        {
            EFProductRepository repo = new EFProductRepository();

            if (product == null)
                throw new HttpResponseException(System.Net.HttpStatusCode.BadRequest);

            try
            {
                repo.Save(product);
            }
            catch
            {
                throw;
            }
            finally
            {
                repo = null;
            }
        }
Ejemplo n.º 17
0
        public ViewResult Checkout(Cart cart, ShippingDetails shippingDetails)
        {
            StringBuilder       builder   = new StringBuilder();
            Order               order     = new Order();
            EFProductRepository eFProduct = new EFProductRepository();

            if (cart.Lines.Count() == 0)
            {
                ModelState.AddModelError("", "Вибачте, кошик пустий");
            }

            if (ModelState.IsValid)
            {
                orderProcessor.SaveOrder(cart, shippingDetails, order);

                using (UserContext db = new UserContext())
                {
                    builder.AppendLine("На сайті зроблено замовлення!");
                    foreach (var lines in cart.Lines)
                    {
                        builder.AppendLine($"-  {lines.Product.ProductName} - {lines.Quantity} шт.");
                    }
                    builder.AppendLine($"http://{HttpContext.Request.Url.Authority}/Admin/Purchases");
                    string message = builder.ToString();
                    foreach (var user in db.Users)
                    {
                        if (user.ChatId != 0)
                        {
                            BotStart.bot.SendMessage(message, user.ChatId);
                        }
                    }
                }
                cart.Clear();
                return(View("Completed"));
            }
            else
            {
                return(View(new ShippingDetails()));
            }
        }
Ejemplo n.º 18
0
        // GET: Product
        public ViewResult List(string category, int page)
        {
            int PageSize = 2;
            IProductRepository   repository = new EFProductRepository();
            ProductPageViewModel model      = new ProductPageViewModel
            {
                products = (repository.Products
                            .Where(p => category == (String)null || p.Category == category)
                            .OrderBy(p => p.ProductId)
                            .Skip((page - 1) * PageSize)
                            .Take(PageSize)
                            ),
                info = new PagingInfo
                {
                    CurrentPage  = page,
                    TotalItems   = repository.Products.Where(p => p.Category == null || p.Category == category).Count(),
                    ItemsPerPage = PageSize,
                },
                currentCategory = category
            };

            return(View(model));
        }
Ejemplo n.º 19
0
 public RestApiController(AppDbContext ctx)
 {
     this.EFPR = new EFProductRepository(ctx);
 }
Ejemplo n.º 20
0
 public ProductRepositoryTests()
 {
     this.context = TestHelper.GetInMemoryContext();
     this.repo    = new EFProductRepository(context, new TestSeedHelper());
 }
Ejemplo n.º 21
0
 public NavController(EFProductRepository repositorypram)
 {
     this.repository = repositorypram;
 }
Ejemplo n.º 22
0
 public CartController(EFProductRepository repo, IOrderProcessor proc)
 {
     repository     = repo;
     orderProcessor = proc;
 }
Ejemplo n.º 23
0
 public NavController(EFProductRepository repo)
 {
     repository = repo;
 }
Ejemplo n.º 24
0
 public ProductController(EFProductRepository productRepository)
 {
     this.repository = productRepository;
 }
Ejemplo n.º 25
0
 public ApiController(AppDbContext context)
 {
     _EFProductRepository = new EFProductRepository(context);
 }
Ejemplo n.º 26
0
 public AdminController(EFProductRepository repositoryPram)
 {
     this.repository = repositoryPram;
 }
Ejemplo n.º 27
0
 public APIController(AppDbContext ctx)
 {
     this.repo = new EFProductRepository(ctx);
 }
Ejemplo n.º 28
0
 public AdminController(EFProductRepository repo)
 {
     repository = repo;
 }