public void SyncSpecAttOps(IDictionary <String, int> attSpecOp, List <int> specsToKeep, int catStockTypeId, int specAttId) { string sql = String.Format("SELECT nom,id_web, id FROM CAT_STCK WHERE TYPE = {0}", catStockTypeId, StockSyncer.JOIN_CLAUSE, StockSyncer.ALL_STOCKS_WHERE_CLAUSE); string sqlUpdateIdWeb = "UPDATE CAT_STCK SET ID_WEB = {0} WHERE ID = '{1}'"; List <string> catStocks = new List <string>(); SqlCommand sqlCommand = new SqlCommand(sql); try { DataTable dt = DBContextFactory.DBContext.Query(sqlCommand); foreach (DataRow dr in dt.Rows) { string scatVal = Convert.ToString(dr["nom"]).TrimEnd(); string scatId = Convert.ToString(dr["id"]).TrimEnd(); int scatIdWeb = Convert.ToInt32(dr["id_web"]); //Format to JSON JObject json = ParserJSon.ParseSCATToSpecificationAttributeOption(specAttId, scatVal); int specId = 0; if (!attSpecOp.Any(x => x.Value == scatIdWeb)) { //Send via POST (new ones) string result = WebService.Post(WebApiEntities.SPEC_ATT_OPT, json); JObject newValue = JObject.Parse(result); specId = (int)newValue["Id"]; //Update sqlUpdateIdWeb = String.Format(sqlUpdateIdWeb, specId, scatId); dbContext.NonQuery(sqlUpdateIdWeb); } else { //Exists; we keep the id specId = scatIdWeb; JObject nameUpdate = new JObject(); nameUpdate.Add("Name", scatVal); WebService.Patch(new UrlBuilder("SpecificationAttributeOption").Id(scatIdWeb).BuildQuery(), nameUpdate.ToString()); } //Store cat to keep specsToKeep.Add(specId); } } catch (Exception e) { Program.log(e); } }