public static SellProductModel MapToSellProductEntity(SellProduct sellProduct) { SellProductModel model = new SellProductModel(); model.Id = sellProduct.Id; model.MarketName = sellProduct.Market.Name; model.Name = sellProduct.Product.Name; model.Price = (int)sellProduct.SellPrice; return model; }
public List<SellProductModel> ReadDataError(string path, out string errorName, out string errorMarket, out string errorPrice, out int errorCount) { OleDbConnection oledbConn = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + ";Extended Properties='Excel 12.0;HDR=YES;IMEX=1;';"); errorName = ""; errorMarket = ""; errorPrice = ""; errorCount = 0; try { oledbConn.Open(); OleDbCommand cmd = new OleDbCommand(); //CHua' data tren RAM DataSet ds = new DataSet(); cmd.Connection = oledbConn; cmd.CommandType = CommandType.Text; // cmd.CommandText = "SELECT [Tên Sản Phẩm],[Tên Chợ],[Giá] FROM [Sheet1$]"; cmd.CommandText = "SELECT * FROM [sheet1$B2:D2000]"; OleDbDataAdapter oleda = new OleDbDataAdapter(cmd); oleda.Fill(ds, "SellProduct"); DataTableCollection tables = ds.Tables; errorName = ""; errorMarket = ""; errorPrice = ""; List<SellProductModel> sellProductErrorCollection = new List<SellProductModel>(); for (int i = 0; i < tables.Count; i++) { DataTable table = tables[i]; foreach (DataRow row in table.Rows) { bool error = false; SellProductModel sellProductError = new SellProductModel(); sellProductError.RowNumber = table.Rows.IndexOf(row) + 3; sellProductError.Name = row.ItemArray[0].ToString(); sellProductError.MarketName = row.ItemArray[1].ToString(); var dupProduct = sellProductErrorCollection.Where(p => p.Name.Equals(sellProductError.Name) && p.MarketName.Equals(sellProductError.MarketName)).FirstOrDefault(); //if (dupProduct != null) //{ // int price = 0; // double doublePrice; // Double.TryParse(row.ItemArray[2].ToString(), out doublePrice); // price = (int)Math.Round(doublePrice, 0); // sellProductError.Price = price; // if (sellProductError.Price < 1 || sellProductError.Price > 10000) // { // dupProduct.Price = dupProduct.Price; // } //} //else //{ if (sellProductError.Name.Length < 5 || sellProductError.Name.Length > 100) { InvalidNumberException invalidNumberException = new InvalidNumberException("Tên sản phẩm phải từ 5 đến 100 ký tự"); errorName = invalidNumberException.Message; error = true; errorCount++; } if (sellProductError.MarketName.Length < 5 || sellProductError.MarketName.Length > 100) { InvalidNumberException invalidNumberException = new InvalidNumberException("Tên chợ phải từ 5 đến 100 ký tự"); errorMarket = invalidNumberException.Message; error = true; errorCount++; } try { int price = 0; double doublePrice; Double.TryParse(row.ItemArray[2].ToString(), out doublePrice); price = (int)Math.Round(doublePrice, 0); sellProductError.Price = price; if (sellProductError.Price < 1 || sellProductError.Price > 10000) { InvalidNumberException invalidNumberException = new InvalidNumberException("Giá phải từ 1 đến 10000"); errorPrice = invalidNumberException.Message; error = true; errorCount++; } } catch (ArgumentNullException argumentNullException) { throw argumentNullException; } catch (FormatException formatException) { throw formatException; } catch (OverflowException overflowException) { throw overflowException; } finally { if (error) { sellProductErrorCollection.Add(sellProductError); } } //} } } //Compare items in Excel List<string> results = new List<string>(); for (int i = 0; i < sellProductErrorCollection.Count - 1; i++) { var result = sellProductErrorCollection[i].Name; for (int j = i + 1; j < sellProductErrorCollection.Count; j++) { var percentage = CompareStringHelper.CompareString(sellProductErrorCollection[i].Name, sellProductErrorCollection[j].Name); if (percentage > 0.7 && percentage < 1) { result += ";" + sellProductErrorCollection[j].Name; } } if (result != sellProductErrorCollection[i].Name) { results.Add(result); } } return sellProductErrorCollection; } catch (System.InvalidOperationException exception) { throw exception; } catch (System.Data.OleDb.OleDbException exception2) { throw exception2; } return null; }
public List<SellProductModel> ReadData(string path, out string errorName, out string errorMarket, out string errorPrice, out int errorCount) { OleDbConnection oledbConn = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + ";Extended Properties='Excel 12.0;HDR=YES;IMEX=1;';"); errorName = ""; errorMarket = ""; errorPrice = ""; errorCount = 0; try { oledbConn.Open(); OleDbCommand cmd = new OleDbCommand(); //CHua' data tren RAM DataSet ds = new DataSet(); cmd.Connection = oledbConn; cmd.CommandType = CommandType.Text; cmd.CommandText = "SELECT * FROM [sheet1$B2:D2000]"; OleDbDataAdapter oleda = new OleDbDataAdapter(cmd); oleda.Fill(ds, "SellProduct"); DataTableCollection tables = ds.Tables; List<SellProductModel> sellProductCollection = new List<SellProductModel>(); for (int i = 0; i < tables.Count; i++) { DataTable table = tables[i]; foreach (DataRow row in table.Rows) { SellProductModel sellProduct = new SellProductModel(); // SellProductModel sellProductError = new SellProductModel(); sellProduct.RowNumber = Int32.Parse(row.ItemArray[0].ToString()) +2; sellProduct.Name = row.ItemArray[1].ToString(); sellProduct.MarketName = row.ItemArray[2].ToString(); var dupProduct = sellProductCollection.Where(p => p.Name.Equals(sellProduct.Name) && p.MarketName.Equals(sellProduct.MarketName)).FirstOrDefault(); if (dupProduct != null) { var price = 0; // Int32.TryParse(row.ItemArray[3].ToString(), out price); double doublePrice; Double.TryParse(row.ItemArray[2].ToString(), out doublePrice); price = (int)Math.Round(doublePrice, 0); sellProduct.Price = price; if (sellProduct.Price < 1 || sellProduct.Price > 10000) { InvalidNumberException invalidNumberException = new InvalidNumberException("Giá phải từ 1 đến 10000"); errorPrice = invalidNumberException.Message; errorCount++; } } if (sellProduct.Name.Length < 5 || sellProduct.Name.Length > 100) { InvalidNumberException invalidNumberException = new InvalidNumberException("Tên sản phẩm phải từ 5 đến 100 ký tự"); errorName = invalidNumberException.Message; errorCount++; } if (sellProduct.MarketName.Length < 5 || sellProduct.MarketName.Length > 100) { InvalidNumberException invalidNumberException = new InvalidNumberException("Tên chợ phải từ 5 đến 100 ký tự"); errorMarket = invalidNumberException.Message; errorCount++; } try { var price = 0; // Int32.TryParse(row.ItemArray[3].ToString(), out price); double doublePrice; Double.TryParse(row.ItemArray[2].ToString(), out doublePrice); price = (int)Math.Round(doublePrice, 0); sellProduct.Price = price; if (sellProduct.Price < 1 || sellProduct.Price > 10000) { InvalidNumberException invalidNumberException = new InvalidNumberException("Giá phải từ 1 đến 10000"); errorPrice = invalidNumberException.Message; errorCount++; } } catch (ArgumentNullException argumentNullException) { throw argumentNullException; } catch (FormatException formatException) { throw formatException; } catch (OverflowException overflowException) { throw overflowException; } finally { sellProductCollection.Add(sellProduct); } } return sellProductCollection; } } catch (System.InvalidOperationException exception) { throw exception; } catch (System.Data.OleDb.OleDbException exception2) { throw exception2; } return null; }
//List error public List<SellProductModel> ReadDataCorrect(string path) { OleDbConnection oledbConn = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + ";Extended Properties='Excel 12.0;HDR=YES;IMEX=1;';"); try { oledbConn.Open(); OleDbCommand cmd = new OleDbCommand(); //CHua' data tren RAM DataSet ds = new DataSet(); cmd.Connection = oledbConn; cmd.CommandType = CommandType.Text; // cmd.CommandText = "SELECT [Tên Sản Phẩm],[Tên Chợ],[Giá] FROM [Sheet1$]"; cmd.CommandText = "SELECT * FROM [sheet1$B2:D2000]"; OleDbDataAdapter oleda = new OleDbDataAdapter(cmd); oleda.Fill(ds, "SellProduct"); DataTableCollection tables = ds.Tables; List<SellProductModel> sellProductCorrectCollection = new List<SellProductModel>(); List<SellProductModel> dupSellProductCorrectCollection = new List<SellProductModel>(); for (int i = 0; i < tables.Count; i++) { DataTable table = tables[i]; foreach (DataRow row in table.Rows) { bool error = false; SellProductModel sellProductCorrect = new SellProductModel(); sellProductCorrect.Name = row.ItemArray[0].ToString(); sellProductCorrect.MarketName = row.ItemArray[1].ToString(); //Check trung du lieu // var dupProduct = sellProductCorrectCollection.Where(p => p.Name.Equals(sellProductCorrect.Name) && p.MarketName.Equals(sellProductCorrect.MarketName)).FirstOrDefault(); if (dupProduct != null) { int price = 0; double doublePrice; Double.TryParse(row.ItemArray[2].ToString(), out doublePrice); price = (int)Math.Round(doublePrice, 0); sellProductCorrect.Price = price; if (sellProductCorrect.Price < 1 || sellProductCorrect.Price > 10000) { error = true; } else { dupProduct.Price = sellProductCorrect.Price; } } else { if (sellProductCorrect.Name.Length < 5 || sellProductCorrect.Name.Length > 100) { error = true; } if (sellProductCorrect.MarketName.Length < 5 || sellProductCorrect.MarketName.Length > 100) { error = true; } try { int price = 0; double doublePrice; Double.TryParse(row.ItemArray[2].ToString(), out doublePrice); price = (int)Math.Round(doublePrice, 0); sellProductCorrect.Price = price; if (sellProductCorrect.Price < 1 || sellProductCorrect.Price > 10000) { error = true; } } catch (ArgumentNullException argumentNullException) { throw argumentNullException; } catch (FormatException formatException) { throw formatException; } catch (OverflowException overflowException) { throw overflowException; } finally { if (error == false) { sellProductCorrect.Id = sellProductCorrectCollection.Count(); sellProductCorrectCollection.Add(sellProductCorrect); } } } } } return sellProductCorrectCollection; } catch (System.InvalidOperationException exception) { throw exception; } catch (System.Data.OleDb.OleDbException exception2) { throw exception2; } return null; }
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; }
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; }
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; }
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); }
public JsonResult UpdateSession(string ProductId, string ProductName, string ProductMarketName, int ProductPrice) { Result result = new Result(); if (Session["CorrectProducts"] != null) // Khi chưa so sánh với DB { var correctProducts = (List<SellProductModel>)Session["CorrectProducts"]; var largerId = correctProducts.OrderByDescending(p => p.Id).FirstOrDefault(); SellProductModel model = new SellProductModel(); model.Name = ProductName; model.MarketName = ProductMarketName; model.Price = ProductPrice; model.Id = largerId.Id + 1; correctProducts.Add(model); Session["CorrectProducts"] = correctProducts; var dupCorrectProducts = (List<List<SellProductModel>>)Session["duplicateProducts"]; string[] productNames = ProductName.Split(';'); for (int h = 0; h < productNames.Count(); h++) { var status = false; if (productNames[h].ToString() != "") { for (int i = 0; i < dupCorrectProducts.Count; i++) { if (status == true) { break; } for (int j = 0; j < dupCorrectProducts[i].Count; j++) { var nameDupProduct = dupCorrectProducts[i][j].Name; if (productNames[h].ToString() == nameDupProduct.ToString()) { dupCorrectProducts[i].Remove(dupCorrectProducts[i][j]); status = true; break; } Session["duplicateProducts"] = dupCorrectProducts; } if (dupCorrectProducts[i].Count == 0) { dupCorrectProducts.Remove(dupCorrectProducts[i]); } } } } result.id = largerId.Id + 1; result.correctProductName = ProductName; result.correctMarketName = ProductMarketName; result.correctProductPrice = ProductPrice; } else // So sánh với DB { List<SellProductModel> correctProductsCollection = new List<SellProductModel>(); SellProductModel model = new SellProductModel(); model.Name = ProductName; model.MarketName = ProductMarketName; model.Price = ProductPrice; model.Id = 0; correctProductsCollection.Add(model); Session["CorrectProducts"] = correctProductsCollection; var dupCorrectProducts = (List<List<SellProductModel>>)Session["duplicateProducts"]; string[] productNames = ProductName.Split(';'); for (int h = 0; h < productNames.Count(); h++) { var status = false; if (productNames[h].ToString() != "") { for (int i = 0; i < dupCorrectProducts.Count; i++) { if (status == true) { break; } for (int j = 0; j < dupCorrectProducts[i].Count; j++) { var nameDupProduct = dupCorrectProducts[i][j].Name; if (productNames[h].ToString() == nameDupProduct.ToString()) { dupCorrectProducts[i].Remove(dupCorrectProducts[i][j]); //if (dupCorrectProducts[i].Count == 0) //{ // dupCorrectProducts.Remove(dupCorrectProducts[i]); //} status = true; break; } Session["duplicateProducts"] = dupCorrectProducts; } if (dupCorrectProducts[i].Count == 0) { dupCorrectProducts.Remove(dupCorrectProducts[i]); } } } } result.id = 0; result.correctProductName = ProductName; result.correctMarketName = ProductMarketName; result.correctProductPrice = ProductPrice; } return Json(result); }
public JsonResult SaveProductError(string ProductId, string ProductName, string ProductMarketName, int ProductPrice) { Result result = new Result(); List<string> error = new List<string>(); var status = ""; int tableId = 0; var nameDupProduct = ""; int tableCorrectId = 0; var correctProductName = ""; var correctMarketName = ""; int correctProductPrice = 0; int count = 0; if (ProductName.Length < 5 || ProductName.Length > 100) { error.Add("Tên sản phẩm phải từ 5 đến 100 ký tự"); } if (ProductMarketName.Length < 5 || ProductMarketName.Length > 100) { error.Add("Tên chợ phải từ 5 đến 100 ký tự"); } if (ProductPrice < 1 || ProductPrice > 10000) { error.Add("Giá phải từ 1 đến 10000"); } if (error.Count == 0) { var correctProducts = (List<SellProductModel>)Session["CorrectProducts"]; var dupCorrectProducts = (List<List<SellProductModel>>)Session["duplicateProducts"]; var compareResult = false; // Compare with duplicate Products for (int i = 0; i < dupCorrectProducts.Count; i++) { if (compareResult == true) { tableId = i; status = "Duplicate Products List"; break; } for (int j = 0; j < dupCorrectProducts[i].Count; j++) { if (ProductMarketName == dupCorrectProducts[i][j].MarketName) { var percentage = CompareStringHelper.CompareString(ProductName.Split(';').First(), dupCorrectProducts[i][j].Name.Split(';').First()); if (percentage == 1) { error.Add("Sản phẩm bị trùng."); nameDupProduct = dupCorrectProducts[i][j].Name; result.updatedPrice = ProductPrice; compareResult = true; break; } else if (percentage > 0.7 && percentage < 1) { var largerId = correctProducts.OrderByDescending(p => p.Id).FirstOrDefault(); int newId = largerId.Id + 1; SellProductModel model = new SellProductModel(); model.Name = ProductName; model.MarketName = ProductMarketName; model.Price = ProductPrice; model.Id = newId; dupCorrectProducts[i].Add(model); Session["duplicateProducts"] = dupCorrectProducts; result.id = newId; nameDupProduct = dupCorrectProducts[i][j].Name; compareResult = true; break; } } } } // Compare with Correct Products if (compareResult == false) { var compareCorrectResult = false; if (compareCorrectResult == false) { for (int k = 0; k < correctProducts.Count; k++) { List<SellProductModel> resultCompareError = new List<SellProductModel>(); if (ProductMarketName == correctProducts[k].MarketName) { var percentage = CompareStringHelper.CompareString(ProductName.Split(';').First(), correctProducts[k].Name.Split(';').First()); if (percentage > 0.7 && percentage < 1) { var largerId = correctProducts.OrderByDescending(p => p.Id).FirstOrDefault(); int newId = largerId.Id + 1; SellProductModel model = new SellProductModel(); model.Name = ProductName; model.MarketName = ProductMarketName; model.Price = ProductPrice; model.Id = newId; resultCompareError.Add(model); resultCompareError.Add(correctProducts[k]); result.id = newId; compareCorrectResult = true; } } if (compareCorrectResult == true) { tableCorrectId = k; correctProductName = correctProducts[k].Name; correctMarketName = correctProducts[k].MarketName; correctProductPrice = correctProducts[k].Price; nameDupProduct = correctProducts[k].Name; correctProducts.Remove(correctProducts[k]); // Remove product in Correct Products dupCorrectProducts.Add(resultCompareError); Session["duplicateProducts"] = dupCorrectProducts; count = dupCorrectProducts.Count; status = "Correct Products List"; break; } } } if (compareCorrectResult == false) { // So sánh với Correct Products xem có bị trùng không for (int l = 0; l < correctProducts.Count; l++) { if (ProductMarketName == correctProducts[l].MarketName) { var percentage = CompareStringHelper.CompareString(ProductName.Split(';').First(), correctProducts[l].Name.Split(';').First()); if (percentage == 1) { error.Add("Sản phẩm đã có."); nameDupProduct = correctProducts[l].Name; result.updatedPrice = ProductPrice; compareCorrectResult = true; break; } } } if (compareCorrectResult == false) { var largerId = correctProducts.OrderByDescending(p => p.Id).FirstOrDefault(); int newId = largerId.Id + 1; SellProductModel model = new SellProductModel(); model.Name = ProductName; model.MarketName = ProductMarketName; model.Price = ProductPrice; model.Id = newId; correctProducts.Add(model); Session["CorrectProducts"] = correctProducts; result.id = newId; } } } } result.status = status; result.tableId = tableId; result.nameDupProduct = nameDupProduct; result.tableCorrectId = tableCorrectId; result.correctProductName = correctProductName; result.correctMarketName = correctMarketName; result.correctProductPrice = correctProductPrice; result.count = count; result.error = error; return Json(result); }
public JsonResult MergeProduct(string ProductId, string ProductName, string ProductMarketName, int ProductPrice) { var correctProducts = (List<SellProductModel>)Session["CorrectProducts"]; var largerId = correctProducts.OrderByDescending(p => p.Id).FirstOrDefault(); if (largerId == null) { largerId.Id = 0; } int newId = largerId.Id + 1; SellProductModel model = new SellProductModel(); model.Name = ProductName; model.MarketName = ProductMarketName; model.Price = ProductPrice; model.Id = largerId.Id + 1; correctProducts.Add(model); Session["CorrectProducts"] = correctProducts; return Json(newId); }