Beispiel #1
0
        public ActionResult Create(Market model)
        {
            // Not exist
            var market = context.Markets
                .FirstOrDefault(x => x.Latitude == model.Latitude && x.Longitude == model.Longitude);
            if (market == null)
            {
                model.IsActive = true;
                context.Markets.Add(model);
                context.SaveChanges();
                TempData["create"] = "Success";
                return RedirectToAction("Index");
            }
            ModelState.AddModelError("", "Chợ này đã có trong hệ thống.");

            return View();
        }
Beispiel #2
0
 public RedirectToRouteResult Edit(Market model)
 {
     var market = context.Markets.FirstOrDefault(x => x.Id == model.Id);
     string message;
     if (market != null)
     {
         market.Name = model.Name;
         market.Address = model.Address;
         market.Latitude = model.Latitude;
         market.Longitude = model.Longitude;
         context.SaveChanges();
         message = "Success";
     }
     else
     {
         message = "Failed";
     }
     TempData["edit"] = message;
     return RedirectToAction("Index");
 }
Beispiel #3
0
        private int AddNewProduct(int countInsert, SellProductModel product, SmartBuyEntities db, string productNameFirst, Dictionary dupProductDictionary)
        {
            #region Comments
            // Check excell với Dictionary
            //List<SellProduct> newCorrectProduct = (List<SellProduct>)Session["CorrectProducts"];
            //List<SellProduct> sellProductCompare = db.SellProducts.ToList();
            //List<List<SellProduct>> results = new List<List<SellProduct>>();
            //for (int i = 0; i < newCorrectProduct.Count; i++)
            //{
            //    List<SellProduct> result = new List<SellProduct>();
            //    for (int j = i + 1; j < sellProductCompare.Count; j++)
            //    {
            //        // var sellProMarket = db.SellProducts.Where(m => m.Market.Equals(sellProductCompare[j].MarketId))
            //        if (newCorrectProduct[i].Market.Name == sellProductCompare[j].Market.Name)
            //        {
            //            var percentage =
            //                CompareStringHelper.CompareString(newCorrectProduct[i].Product.Name.Split(';').First(), sellProductCompare[j].Product.Name);
            //            if (percentage > 0.7 && percentage < 1)
            //            {
            //                // var productSimilarDB = db.Products.Where(p => p.Dictionaries.Equals(dictionaryCompare[j]));
            //                if (result.Count() == 0)
            //                {
            //                    result.Add(newCorrectProduct[i]);
            //                }
            //                result.Add(sellProductCompare[j]);
            //                newCorrectProduct.Remove(newCorrectProduct[i]);
            //            }
            //        }
            //    }
            //    if (result.Count() != 0)
            //    {
            //        i = i - 1;
            //        results.Add(result);
            //    }
            //}
            #endregion

            var market = new Market
            {
                Name = product.MarketName,
                IsActive = true,
            };
            var newMarket = db.Markets.Add(market); //add market

            var newProduct = new SmartB.UI.Models.EntityFramework.Product
            {
                Name = productNameFirst,
                IsActive = true,
            };
            var addedProduct = db.Products.Add(newProduct); // add product

            var sellProduct = new SmartB.UI.Models.EntityFramework.SellProduct
            {
                Market = newMarket,
                Product = addedProduct,
                SellPrice = product.Price,
                LastUpdatedTime = DateTime.Now
            };
            var addedSellProduct = db.SellProducts.Add(sellProduct); // add sellProduct
            db.SaveChanges(); // Save to database

            //add product Attribute
            PriceHelper helper = new PriceHelper();
            helper.CalculatePriceRange(addedProduct.Id);

            countInsert++;
            // add Product Dictionary
            var dictionaries = product.Name.Split(';').ToList();
            foreach (string dictionary in dictionaries)
            {
                if (dupProductDictionary == null && dictionary != "")
                {
                    var ProductDic = new SmartB.UI.Models.EntityFramework.Dictionary
                    {
                        Name = dictionary,
                        ProductId = addedProduct.Id
                    };
                    var addProductDic = db.Dictionaries.Add(ProductDic);
                }
            }
            db.SaveChanges(); // Save to database
            return countInsert;
        }
Beispiel #4
0
        private static int TrungTenSanPham(int countInsert, SellProductModel product, SmartBuyEntities db, Product dupProduct)
        {
            var dupProductAtt = db.ProductAttributes.Where(p => p.ProductId.Equals(dupProduct.Id)).FirstOrDefault();
            // Cập nhật giá Min, Max ProductAttribute
            PriceHelper helper = new PriceHelper();
            helper.CalculatePriceRange(dupProductAtt.Product.Id);
            var market = new Market
            {
                Name = product.MarketName,
                IsActive = true,
            };
            var newMarket = db.Markets.Add(market); //add market

            var sellProduct = new SmartB.UI.Models.EntityFramework.SellProduct
            {
                Market = newMarket,
                Product = dupProduct,
                SellPrice = product.Price,
                LastUpdatedTime = DateTime.Now
            };
            var addedSellProduct = db.SellProducts.Add(sellProduct); // Add SellProduct
            countInsert++;
            db.SaveChanges(); // Save to database
            return countInsert;
        }
Beispiel #5
0
        private static List<SellProductModel> TrungMarket(ref int countInsert, SellProductModel product, SmartBuyEntities db, string productNameFirst, Market dupMarket, Dictionary dupProductDictionary)
        {
            //Kiem tra productName voi dictionary
            List<SellProductModel> sellProducts = null;
            List<Product> listProduct = CheckProductNameWithDictionary(productNameFirst, db.Dictionaries);

            if (listProduct != null)
            {
                sellProducts = new List<SellProductModel>();
                foreach (var productId in listProduct)
                {
                    var existedSellProduct = db.SellProducts.FirstOrDefault(x => x.ProductId == productId.Id && x.MarketId == dupMarket.Id);
                    var existedSellProductModel = SellProductModel.MapToSellProductEntity(existedSellProduct);
                    sellProducts.Add(existedSellProductModel);
                }
                sellProducts.Add(product);
            }
            else
            {
                var newProduct = new SmartB.UI.Models.EntityFramework.Product // add Product
                {
                    Name = productNameFirst,
                    IsActive = true,
                };
                var addedProduct = db.Products.Add(newProduct);
                var sellProduct = new SmartB.UI.Models.EntityFramework.SellProduct //add SellProduct
                {
                    Market = dupMarket,
                    Product = addedProduct,
                    SellPrice = product.Price,
                    LastUpdatedTime = DateTime.Now
                };
                var addedSellProduct = db.SellProducts.Add(sellProduct);
                countInsert++;
                db.SaveChanges(); // Save to database
                //add new product Attribute

                var productAttribute = new SmartB.UI.Models.EntityFramework.ProductAttribute
                {
                    ProductId = addedProduct.Id,
                    MinPrice = product.Price,
                    MaxPrice = product.Price,
                    LastUpdatedTime = DateTime.Now,
                };
                var addedProductAtt = db.ProductAttributes.Add(productAttribute);
                db.SaveChanges(); // Save to database
                // add Product Dictionary
                var dictionaries = product.Name.Split(';').ToList();
                foreach (string dictionary in dictionaries)
                {
                    if (dupProductDictionary == null && dictionary != "")
                    {
                        var ProductDic = new SmartB.UI.Models.EntityFramework.Dictionary
                        {
                            Name = dictionary,
                            ProductId = addedProduct.Id
                        };
                        var addProductDic = db.Dictionaries.Add(ProductDic);
                    }
                }
                db.SaveChanges(); // Save to database
            }
            return sellProducts;
        }
Beispiel #6
0
 private static void TrungHoanToan(ref int countUpdate, ref int countInsert, SellProductModel product, SmartBuyEntities db, Market dupMarket, Product dupProduct)
 {
     var sellProduct = db.SellProducts.Where(s => s.ProductId == dupProduct.Id && s.MarketId == dupMarket.Id).FirstOrDefault();
     var sellProduct1 = new SmartB.UI.Models.EntityFramework.SellProduct //add SellProduct
     {
         Market = dupMarket,
         Product = dupProduct,
         SellPrice = product.Price,
         LastUpdatedTime = DateTime.Now
     };
     var addedSellProduct = db.SellProducts.Add(sellProduct1);
     db.SaveChanges(); // Save to database
     // Check sellProduct có trùng không??
     if (sellProduct == null)
     {
         countInsert++;
     }
     else
     {
         countUpdate++;
     }
     // Cập nhật giá Min, Max ProductAttribute
     PriceHelper helper = new PriceHelper();
     helper.CalculatePriceRange(dupProduct.Id);
 }
Beispiel #7
0
        public ActionResult SetActive(int id)
        {
            var market = context.Markets.FirstOrDefault(x => x.Id == id);
            bool statusFlag = false;
            if (ModelState.IsValid)
            {
                if (market.IsActive == true)
                {
                    market.IsActive = false;
                    statusFlag = false;
                }
                else
                {
                    market.IsActive = true;
                    statusFlag = true;
                }
                context.SaveChanges();
            }

            // Display the confirmation message
            var results = new Market
            {
                IsActive = statusFlag
            };

            return Json(results);
        }