Beispiel #1
0
        public IActionResult Delete(int id)
        {
            // where bikeid = idD:\ProjectSucess\Views\Shared\
            TotalProduct totalProduct = db.TotalProducts.Find(id);

            db.TotalProducts.Remove(totalProduct);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Beispiel #2
0
        public async Task <IActionResult> Edit(TotalProduct totalProduct)
        {
            if (ModelState.IsValid)
            {
                db.Update(totalProduct);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(totalProduct));
        }
        public async Task <IViewComponentResult> InvokeAsync(int Id)
        {
            var product = await _context.Products.FindAsync(Id);

            var getall = HttpContext.Session.GetString("CartRequest");
            var total  = new TotalProduct();

            if (getall == null)
            {
                total.Total = 0;
            }
            else
            {
                var listproductofCart = JsonConvert.DeserializeObject <List <CartItem> >(getall);
                total.Total = listproductofCart.Count();
            }
            return(View(total));
        }
Beispiel #4
0
        public async Task <IActionResult> Create(TotalProduct bike)
        {
            if (ModelState.IsValid)   // it will check whether our form is valid or not
            {
                if (bike.ProductImage != null)
                {
                    string rootPath   = env.WebRootPath;                  // get the root directory i.e. /wwwroot/
                    string uniqueName = Guid.NewGuid().ToString();

                    string fileName   = uniqueName + bike.ProductImage.FileName; // file uploaded name
                    string uploadPath = rootPath + "/Images/" + fileName;        // creating upload path
                    bike.ImageName = fileName;                                   // assing file name to bike>imagename
                    using (var filestream = new FileStream(uploadPath, FileMode.Create))
                    {
                        await bike.ProductImage.CopyToAsync(filestream);
                    }
                }
                db.Add(bike);
                await db.SaveChangesAsync();

                return(RedirectToAction("pro"));
            }
            return(View(bike));
        }
Beispiel #5
0
        public static List <TotalProduct> GroupProducts(List <IStoreMap> storeMap, string query, double level = 0.8, double outputLevel = 0.4)
        {
            List <ProductProcessor> productProcessors = new List <ProductProcessor>();
            int productsCount = storeMap.Sum(u => u.ProductsCount);
            int count         = 0;

            for (int i = 0; i < storeMap.Count; i++)
            {
                for (int j = 0; j < storeMap[i].ProductsCount; j++)
                {
                    productProcessors.Add(new ProductProcessor
                                          (
                                              count,
                                              i,
                                              storeMap[i].Products[j]
                                          ));
                    count++;
                }
            }


            double[] vectorQuery = new double[productsCount];
            double[,] matrix = new double[productsCount, productsCount];

            for (int i = 0; i < productProcessors.Count; i++)
            {
                vectorQuery[i] = proximity(productProcessors[i].Product.Title, query);
                productProcessors[i].Priority = vectorQuery[i];
            }

            int startPoint = 1;

            for (int i = 0; i < productProcessors.Count; i++)
            {
                for (int j = startPoint; j < productProcessors.Count; j++)
                {
                    if (i != j)
                    {
                        matrix[i, j] = proximity(productProcessors[i].Product.Title, productProcessors[j].Product.Title);
                        if (matrix[i, j] < level)
                        {
                            matrix[i, j] = 0;
                        }
                        matrix[j, i] = matrix[i, j];
                    }
                }
                startPoint++;
            }

            bool[]             visited  = new bool[productsCount];
            List <List <int> > clusters = new List <List <int> >();


            while (true)
            {
                int unvisited = -1;
                for (int i = 0; i < visited.Length; i++)
                {
                    if (!visited[i])
                    {
                        unvisited = i;
                        break;
                    }
                }
                if (unvisited == -1)
                {
                    break;
                }
                List <int> cluster = new List <int>();
                DFS(unvisited, matrix, ref cluster, ref visited);
                clusters.Add(cluster);
            }

            List <TotalProduct> products = new List <TotalProduct>();

            foreach (var cluster in clusters)
            {
                // Продукты по кластеру!
                var items = productProcessors.Where(u => cluster.Contains(u.ProductId)).ToList();

                // Уникальные ид сайтов
                var sitesUniqueIds = items.Select(p => p.StoreId).Distinct().ToList();

                double maxValue        = 0;
                int    indexOfMaxValue = 0;
                for (int i = 0; i < items.Count; i++)
                {
                    double tempMax = vectorQuery[items[i].ProductId];
                    if (tempMax > maxValue)
                    {
                        maxValue        = tempMax;
                        indexOfMaxValue = i;
                    }
                }

                var productEtal = items[indexOfMaxValue].Product;

                List <TotalMarket> tms = new List <TotalMarket>();

                double prices         = 0;
                int    itemsRealCount = 0;
                for (int i = 0; i < sitesUniqueIds.Count(); i++)
                {
                    IOrderedEnumerable <Product> bestProductsFromStore = items.Where(a => a.StoreId == sitesUniqueIds[i] && a.Priority >= outputLevel)
                                                                         .Select(u => u.Product)
                                                                         .OrderByDescending(l => l.Popularity)
                                                                         .OrderByDescending(k => k.Rating);

                    if (bestProductsFromStore.Count() == 0)
                    {
                        bestProductsFromStore = items.Where(a => a.StoreId == sitesUniqueIds[i])
                                                .Select(u => u.Product)
                                                .OrderByDescending(l => l.Popularity)
                                                .OrderByDescending(k => k.Rating);
                    }

                    var bestProductFromStore = bestProductsFromStore.FirstOrDefault();

                    if (bestProductFromStore != null)
                    {
                        TotalMarket tm = new TotalMarket
                        {
                            Name        = storeMap[sitesUniqueIds[i]].Name,
                            Description = storeMap[sitesUniqueIds[i]].About,
                            Logo        = storeMap[sitesUniqueIds[i]].Logo,
                            Price       = bestProductFromStore.PriceValue,
                            Link        = bestProductFromStore.Link,
                        };
                        tms.Add(tm);
                        prices += bestProductFromStore.PriceValue;
                        itemsRealCount++;
                    }
                }

                double avgPrice = 0;
                if (itemsRealCount != 0)
                {
                    avgPrice = Math.Round((double)(prices / itemsRealCount), 2);
                }

                TotalProduct tp = new TotalProduct
                {
                    Markets      = tms,
                    Name         = productEtal.Title,
                    Logo         = productEtal.Image,
                    Rating       = productEtal.RatingValue,
                    Popularity   = productEtal.PopularityValue,
                    AveragePrice = avgPrice
                };
                products.Add(tp);
            }
            return(products);
        }