Exemplo n.º 1
0
        public void Gallery_Product_PassDataViewWithApiMock()
        {
            var webhost = new Mock <IWebHostEnvironment>();
            var product = new GetProductViewModel {
                Customer = "Test"
            };
            var GetAllProductvm = new GetAllProductViewModel {
                CountOnPage = 1, CurrentPage = 1, Products = new List <GetProductViewModel> {
                    product
                }
            };
            var api = new Mock <IGetProductApi>();

            api.Setup(c => c.GetAll(It.IsAny <GetAllProductViewModel>())).Returns(new GetAllProductViewModel {
                Products = new List <GetProductViewModel> {
                    product
                }
            });
            var mycontroller = new HomeController(api.Object, webhost.Object);

            var result = mycontroller.Gallery(new GetAllProductViewModel {
                Products = new List <GetProductViewModel> {
                    product
                }
            });

            var ViewResult     = Assert.IsType <ViewResult>(result);
            var myobjectresult = Assert.IsType <GetAllProductViewModel>(ViewResult.Model);

            Assert.True(myobjectresult.Products.Count > 0);
        }
Exemplo n.º 2
0
        private GetProductViewModel BuildProductViewModel(Product product)
        {
            List <string> galleryImages = new List <string>();

            var imagesUrls = db.Image.Where(img => img.ProductId == product.Id)
                             .Select(img => uploader.GetImageUrl(img.Id)).ToList();

            var productViewModel = new GetProductViewModel()
            {
                Id                = product.Id,
                Title             = product.Title,
                Description       = product.Description,
                Price             = product.Price,
                SkuCode           = product.SkuCode,
                Discount          = product.Discount,
                MainImageUrl      = uploader.GetImageUrl(product.MainImageId),
                GalleryImagesUrls = imagesUrls
            };

            var categories = db.Category.ToList();

            var currentCategory = categories.FirstOrDefault(category => category.Id == product.CategoryId);

            while (currentCategory != null)
            {
                productViewModel.CategoryList.Insert(0, currentCategory);
                currentCategory = categories.FirstOrDefault(category => category.Id == currentCategory.Parent_id);
            }

            return(productViewModel);
        }
Exemplo n.º 3
0
        public IActionResult Winkelpagina()
        {
            var model = new GetProductViewModel()
            {
                Product = _ProductLogic.GetAllProduct().ToList()
            };

            return(View(model));
        }
        public ActionResult Index(int?page)
        {
            AppDbContext         dbContext   = new AppDbContext();
            ListProductViewModel listProduct = new ListProductViewModel();

            listProduct.Brands = dbContext.getBrands.ToList();

            List <ProductModels>       products    = dbContext.getProducts.ToList();
            List <GetProductViewModel> getProducts = new List <GetProductViewModel>();

            /*Get products details*/
            foreach (var item in products)
            {
                ModelModels    model    = dbContext.getModels.SingleOrDefault(m => m.Id == item.ModelId);
                BrandModels    brand    = dbContext.getBrands.SingleOrDefault(b => b.BrandId == model.BrandId);
                CategoryModels category = dbContext.getCategories.SingleOrDefault(c => c.CategoryId == model.CategoryId);

                GetProductViewModel getProduct = new GetProductViewModel
                {
                    Id          = item.Id,
                    Name        = model.Name,
                    Brand       = brand.Brand,
                    Category    = category.Category,
                    Price       = item.Price,
                    Color       = item.Color,
                    Storage     = item.Storage,
                    Processor   = item.Processor,
                    Memory      = item.Memory,
                    Display     = item.Display,
                    Details     = item.Details,
                    CreatedBy   = item.CreatedBy,
                    CreatedDate = item.CreatedDate
                };
                getProduct.Photos = dbContext.getProductPhotos(item.Id).ToList();

                getProducts.Add(getProduct);
            }

            /*Search product and sort by date*/
            listProduct.Products = getProducts.OrderByDescending(p => p.CreatedDate).ToList().ToPagedList(page ?? 1, 20);


            /*Get the number of each product in a brand*/
            listProduct.EachProductsOfBrands = new List <int>();
            foreach (var brand in listProduct.Brands)
            {
                List <ProductModels> productsOfBrands = dbContext.getProductBrands(brand.BrandId).ToList();

                int numberOfBrand = productsOfBrands.Count;
                listProduct.EachProductsOfBrands.Add(numberOfBrand);
            }

            /*Create Index view with product details*/
            return(View(listProduct));
        }
Exemplo n.º 5
0
        /*
         * Get ProductViewModel for the required Product
         */
        public GetProductViewModel GetProductViewModel(Product product)
        {
            if (product == null)
            {
                return(null);
            }

            var productViewModel = new GetProductViewModel
            {
                Id    = product.Id,
                Name  = product.Name,
                Price = product.Price
            };

            return(productViewModel);
        }
Exemplo n.º 6
0
        public async Task <ActionResult <GetProductViewModel> > GetProduct(Guid id)
        {
            var product = await _context.Product
                          .Include(b => b.ProductCategories)
                          .Include(p => p.Picture)
                          .Include(p => p.Ratings)
                          .FirstOrDefaultAsync(p => p.ProductId == id);

            if (product == null)
            {
                return(NotFound());
            }

            var getProductViewModel = new GetProductViewModel(product);

            return(getProductViewModel);
        }
Exemplo n.º 7
0
        public async Task <ActionResult <ICollection <GetProductViewModel> > > GetProduct()
        {
            var products = await _context.Product
                           .Include(b => b.ProductCategories)
                           .Include(p => p.Picture)
                           .Include(p => p.Ratings)
                           .ToListAsync();

            ICollection <GetProductViewModel> getProductViewModels = new List <GetProductViewModel>();

            foreach (var product in products)
            {
                var productView = new GetProductViewModel(product);
                getProductViewModels.Add(productView);
            }

            return(Ok(getProductViewModels));
        }
Exemplo n.º 8
0
        public IActionResult AddProductToCart(GetProductViewModel model)
        {
            var product = db.Product.FirstOrDefault(p => p.Id == model.Id);

            if (product == null)
            {
                return(View("NotFound"));
            }

            var productViewModel = BuildProductViewModel(product);
            var category         = db.Category.First(c => c.Id == product.CategoryId);

            var cart = this.UserShoppingCart();

            cart.AddProduct(product, model.ProductCount, category.Title, uploader, priceCalculator);
            this.SaveCart(cart);

            return(View("GetProduct", productViewModel));
        }
Exemplo n.º 9
0
        public ActionResult Details(int id)
        {
            User user = GetCurrentUser();

            if (user == null)
            {
                return(RedirectToAction("Login", "Account"));
            }
            Product             product   = UnitOfWork.ProductRepo.FindById(id);
            GetProductViewModel viewModel = new GetProductViewModel
            {
                Id          = product.Id,
                Name        = product.Name,
                Description = product.Description,
                Price       = product.Price,
                Category    = product.Category.Name,
                OrdersCount = product.Orders.Count
            };

            return(View(viewModel));
        }
Exemplo n.º 10
0
        public void Gallery_Product_Create()
        {
            var urlapi = new UrlApi()
            {
                Url = "https://localhost:44397/api/v1/"
            };
            var client = new WebClient();
            var option = new Mock <IOptions <UrlApi> >();

            option.Setup(c => c.Value).Returns(urlapi);
            var getapi = new GetProductApi(client, option.Object);
            var model  = new GetProductViewModel
            {
                Category = new List <string> {
                    Faker.Developers.Designe, Faker.Developers.Developer, Faker.Developers.Host
                },
                Customer    = Faker.Lorem.Word(3),
                Description = Faker.Lorem.Word(50),
                EndDate     = DateTime.Now,
                StartDate   = DateTime.Now,
                Images      = new List <GetImageViewModel> {
                    new GetImageViewModel {
                        Name = "06.jpg", Path = "/images/gallery/Test/"
                    }
                },
                Services = new List <string> {
                    Faker.Lorem.Word(4), Faker.Lorem.Word(3), Faker.Lorem.Word(5)
                },
                SiteName = Faker.Lorem.Word(3),
                SiteUrl  = Faker.Persons.Email,
                Tags     = new List <string> {
                    Faker.Developers.Ecommerce, Faker.Developers.Domain, Faker.Developers.netCore
                }
            };

            //var GetJsonResult = JsonConvert.SerializeObject(model);
            var result = getapi.Create(model);

            Assert.Equal("Added", result);
        }
        public ActionResult FilterByPrice(int min, int max)
        {
            AppDbContext dbContext = new AppDbContext();
            List <GetProductViewModel> viewModels = new List <GetProductViewModel>();
            List <ProductModels>       products   = dbContext.getProductByPrice(min, max).OrderByDescending(p => p.CreatedDate).ToList();

            foreach (var product in products)
            {
                ModelModels    model    = dbContext.getModels.SingleOrDefault(m => m.Id == product.ModelId);
                BrandModels    brand    = dbContext.getBrands.SingleOrDefault(b => b.BrandId == product.BrandId);
                CategoryModels category = dbContext.getCategories.SingleOrDefault(c => c.CategoryId == product.CategoryId);

                GetProductViewModel getProduct = new GetProductViewModel
                {
                    Id          = product.Id,
                    Name        = model.Name,
                    Brand       = brand.Brand,
                    Category    = category.Category,
                    Price       = product.Price,
                    Color       = product.Color,
                    Storage     = product.Storage,
                    Processor   = product.Processor,
                    Memory      = product.Memory,
                    Display     = product.Display,
                    Details     = product.Details,
                    CreatedBy   = product.CreatedBy,
                    CreatedDate = product.CreatedDate
                };

                getProduct.Photos = dbContext.getProductPhotos(product.Id).ToList();



                viewModels.Add(getProduct);
            }

            return(Json(viewModels, JsonRequestBehavior.AllowGet));
        }
        public ActionResult Search(string search, int?page)
        {
            AppDbContext dbContext = new AppDbContext();

            List <ProductModels> products = dbContext.getProducts.ToList();

            List <GetProductViewModel> searchProducts = new List <GetProductViewModel>();


            foreach (var item in products)
            {
                ModelModels         model    = dbContext.getModels.SingleOrDefault(m => m.Id == item.ModelId);
                BrandModels         brand    = dbContext.getBrands.SingleOrDefault(b => b.BrandId == model.BrandId);
                CategoryModels      category = dbContext.getCategories.SingleOrDefault(c => c.CategoryId == model.CategoryId);
                List <ProductPhoto> photos   = dbContext.getProductPhotos(item.Id).ToList();

                GetProductViewModel searchProduct = new GetProductViewModel
                {
                    Id        = item.Id,
                    Name      = model.Name,
                    Brand     = brand.Brand,
                    Category  = category.Category,
                    Color     = item.Color,
                    Price     = item.Price,
                    Processor = item.Processor,
                    Memory    = item.Memory,
                    Storage   = item.Storage,
                    Display   = item.Display,
                    Details   = item.Details,
                    Photos    = photos
                };

                searchProducts.Add(searchProduct);
            }
            var result = searchProducts.Where(p => p.Name.StartsWith(search ?? "", StringComparison.OrdinalIgnoreCase)).ToList().ToPagedList(page ?? 1, 50);

            return(View(result));
        }
Exemplo n.º 13
0
        public async Task <ActionResult <GetProductViewModel> > PostProduct(PostProductViewModel model)
        {
            //Get Manufacturer
            var manufacturer = new Manufacturer()
            {
                ManufacturerId = Guid.NewGuid(),
                Email          = model.ManufacturerEmail,
                CatalogId      = model.ManufacturerCatalogId
            };

            //Create Picture
            var picture = new Picture
            {
                PictureId  = Guid.NewGuid(),
                ImageTitle = model.ImageTitle,
                ImageData  = model.ImageData
            };

            //GET Categories
            ICollection <Category> categories = new List <Category>();

            if (model.ProductCategoryIds != null)
            {
                foreach (var VARIABLE in model.ProductCategoryIds)
                {
                    var category = await _context.Category.FindAsync(VARIABLE);

                    if (category != null)
                    {
                        categories.Add(category);
                    }
                }
            }
            else
            {
                categories = null;
            }

            //Create Product
            var product = new Product()
            {
                ProductId         = Guid.NewGuid(),
                Name              = model.Name,
                Description       = model.Description,
                Price             = model.Price,
                Manufacturer      = manufacturer,
                InStock           = model.InStock,
                MinStock          = model.MinStock,
                Tax               = model.Tax,
                Picture           = picture,
                ProductCategories = categories,
                RatingCounter     = 0
            };

            //Add Product and save
            try
            {
                await _context.Product.AddAsync(product);

                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                throw;
            }

            var getProductView = new GetProductViewModel(product);

            return(CreatedAtAction("GetProduct", new { id = product.ProductId }, getProductView));
        }