public JsonResult ts_ship_stock(string[] asset) { string message = ""; //format the tsg sku to the ss format // channel = channel.Replace("TSG_", "HW-"); for (int i = 0; i < asset.Length; i++) { try { string temp_asset = asset[i]; var db = new db_a094d4_icdbEntities1(); var update_asset = db.ts_stock.Where(s => s.ictag == temp_asset).First(); update_asset.status = "Shipped"; db.SaveChanges(); message += "<p style='color:green'>" + asset[i] + " Sucessfully Marked as Shipped</p>"; } catch (Exception e) { message += "<p style='color:red'>" + asset[i] + e.InnerException.InnerException.Message + "</p>"; } } db.Dispose(); return(Json(message, JsonRequestBehavior.AllowGet)); }
public JsonResult get_asset_data(int asset) { var db = new db_a094d4_icdbEntities1(); var rediscovery = (from t in db.rediscovery where t.ictag == asset select t).FirstOrDefault(); var discovery = (from t in db.discovery where t.ictag == asset select t).FirstOrDefault(); var img = (from t in db.production_log where t.ictags == asset.ToString() select t).FirstOrDefault(); return(Json(new { discovery = discovery, rediscovery = rediscovery, img = img }, JsonRequestBehavior.AllowGet)); }
public bool update_rma(string rma_num, string finding) { bool sucessful = false; string userName; string password; userName = "******"; password = "******"; //use default binding and address from app.config // string securityToken = "xxxxxxxxxxxxxxx"; LoginResult currentLoginResult = null; SforceService sfdcBinding = null; var edit_case = (from t in db.rma where t.rma_number == rma_num select t).FirstOrDefault(); using (var db = new db_a094d4_icdbEntities1()) { db.Database.ExecuteSqlCommand("Update rma set production_finding = '" + finding + "' where rma_number ='" + rma_num + "'"); } sfdcBinding = new SforceService(); currentLoginResult = sfdcBinding.login(userName, password); sfdcBinding.Url = currentLoginResult.serverUrl; sfdcBinding.SessionHeaderValue = new SessionHeader(); sfdcBinding.SessionHeaderValue.sessionId = currentLoginResult.sessionId; var update_case = new Case(); update_case.Reviewed_by_Production__c = true; update_case.Reviewed_by_Production__cSpecified = true; update_case.Id = edit_case.id; update_case.Production_Findings__c = finding; SaveResult[] saveResults = sfdcBinding.update(new sObject[] { update_case }); string result = ""; if (saveResults[0].success) { sucessful = true; result = "The update of Lead ID " + saveResults[0].id + " was succesful"; } else { sucessful = false; result = "There was an error updating the Lead. The error returned was " + saveResults[0].errors[0].message; } return(sucessful); }
public JsonResult search_json(string item) { List <shipstation_log> result; using (var db = new db_a094d4_icdbEntities1()) { result = db.shipstation_log.SqlQuery("SELECT * FROM `db_a094d4_icdb`.`shipstation_log` WHERE LOWER(CONVERT(`row_id` USING utf8mb4)) LIKE '%" + item + "%' OR LOWER(CONVERT(`shipment_date` USING utf8mb4)) LIKE '%" + item + "%' OR LOWER(CONVERT(`order_id` USING utf8mb4)) LIKE '%" + item + "%' OR LOWER(CONVERT(`order_num` USING utf8mb4)) LIKE '%" + item + "%' OR LOWER(CONVERT(`item_name` USING utf8mb4)) LIKE '%" + item + "%' OR LOWER(CONVERT(`item_qty` USING utf8mb4)) LIKE '%" + item + "%' OR LOWER(CONVERT(`item_url` USING utf8mb4)) LIKE '%" + item + "%' OR LOWER(CONVERT(`custom_field_1` USING utf8mb4)) LIKE '%" + item + "%' OR LOWER(CONVERT(`custom_field_2` USING utf8mb4)) LIKE '%" + item + "%' OR LOWER(CONVERT(`custom_field_3` USING utf8mb4)) LIKE '%" + item + "%' OR LOWER(CONVERT(`status` USING utf8mb4)) LIKE '%" + item + "%' ;").ToList(); } return(Json(result, JsonRequestBehavior.AllowGet)); }
//add ts stock from production public JsonResult ts_add_stock(string[] asset) { string message = ""; string current_asset = ""; //format the tsg sku to the ss format // channel = channel.Replace("TSG_", "HW-"); for (int i = 0; i < asset.Length; i++) { string temp_asset = asset[i]; var db = new db_a094d4_icdbEntities1(); var exisit = (from t in db.ts_stock where t.ictag == temp_asset select t).FirstOrDefault(); if (exisit == null) { int int_asset = int.Parse(temp_asset); var channel = (from t in db.rediscovery where t.ictag == int_asset select t.pallet).FirstOrDefault(); if (!channel.Contains("TSG_")) { message += "<p style='color:red'>" + asset[i] + " has a non-TechSoup SKU</p>"; continue; } channel = channel.Replace("TSG_", "HW-"); ts_stock ts = new ts_stock(); ts.ictag = temp_asset; current_asset = temp_asset; ts.sku = channel; ts.status = "Ready_for_Shipping"; db.ts_stock.Add(ts); db.SaveChanges(); message += "<p style='color:green'>" + asset[i] + " Sucessfully Added to " + channel + "</p>"; } else { message += "<p style='color:red'>" + asset[i] + " Failed to Import (possible duplicate entry)</p>"; } } db.Dispose(); return(Json(message, JsonRequestBehavior.AllowGet)); }
public JsonResult delete_pallet(string pallet) { pallet item_to_delete; string message = ""; using (var remove = new db_a094d4_icdbEntities1()) { remove.Database.ExecuteSqlCommand( "Delete from pallet where pallet_name = '" + pallet + "'"); } message = pallet + " Has Been Deleted"; return(Json(message, JsonRequestBehavior.AllowGet)); }
// GET: /Manage/palletmanager // [HttpPost] public ActionResult createPallet() { db_a094d4_icdbEntities1 db = new db_a094d4_icdbEntities1(); var data = (from p in db.pallet_master select new Models.inventoryManageViewModel { pallet = p.pallet_id, }); SelectList list = new SelectList(data, "pallet", "pallet"); ViewBag.Roles = list; ViewBag.data = data; //Loop through the forms for (int i = 0; i <= Request.Form.Count; i++) { var ictags = Request.Form["ictag[" + i + "]"]; var pallet_name = Request.Form["pallet_name[" + i + "]"]; var note = Request.Form["note[" + i + "]"]; if ((ictags != null) && (pallet_name != null)) { db.pallet.Add(new pallet { ictags = int.Parse(ictags), pallet_name = pallet_name, note = note }); db.SaveChanges(); } } return(View()); }
//add new database entry for discover data public ActionResult insert_asset(int asset, string brand, string model, string refrub, string download, string cpu_brand, string cpu_type, string cpu_speed, string ram, string hdd, string serial) { var cpu = cpu_brand + " " + cpu_type + " " + cpu_speed; var xml = mrm_xml(asset.ToString(), brand, model, hdd, ram, serial, cpu); var db = new db_a094d4_icdbEntities1(); var exisit = (from t in db.discovery where t.ictag == asset select t).ToList(); if (exisit.Count == 0) { using (db as db_a094d4_icdbEntities1) { var new_entry = new discovery(); new_entry.brand = brand; new_entry.cpu = cpu; new_entry.hdd = hdd; new_entry.ictag = asset; new_entry.location = null; new_entry.model = model; new_entry.optical_drive = null; new_entry.ram = ram; new_entry.serial = serial; new_entry.time = DateTime.Now; db.discovery.Add(new_entry); db.SaveChanges(); TempData["message"] = "Data Imported"; } if (refrub == "on") { using (var db2 = new db_a094d4_icdbEntities1()) { var new_entry = new rediscovery(); new_entry.brand = brand; new_entry.cpu = cpu; new_entry.hdd = hdd; new_entry.ictag = asset; new_entry.location = null; new_entry.model = model; new_entry.optical_drive = null; new_entry.ram = ram; new_entry.serial = serial; new_entry.time = DateTime.Now; db2.rediscovery.Add(new_entry); db2.SaveChanges(); TempData["message"] = "Discovery and Rediscovery Data Imported"; } } if (download == "on") { System.IO.MemoryStream stream = new System.IO.MemoryStream(); XmlTextWriter writer = new XmlTextWriter(stream, System.Text.Encoding.UTF8); xml.WriteTo(writer); writer.Flush(); Response.Clear(); byte[] byteArray = stream.ToArray(); Response.AppendHeader("Content-Disposition", "attachment; filename=" + asset.ToString() + ".xml"); Response.AppendHeader("Content-Length", byteArray.Length.ToString()); Response.ContentType = "application/octet-stream"; Response.BinaryWrite(byteArray); writer.Close(); Response.End(); } } else { TempData["message"] = "an error has occurred"; } return(View()); }
//get year to date report public JsonResult get_yTd_report(string start, string end) { using (var db = new db_a094d4_icdbEntities1()) { int avg_return = 0; int avg_alltime = 0; int avg_year = 0; int avg_year_counter = 0; int avg_month = 0; int avg_month_counter = 0; DateTime date_start; DateTime date_end; if (start == null && end == null) { date_start = new DateTime(2015, 1, 1); date_end = DateTime.Now.Date; } else { date_start = DateTime.Parse(start); date_end = DateTime.Parse(end); } var alltime_C2DDK_result = (from t in db.retail_report where t.name.Contains("MARDKC2D") && t.type == "sale" && (t.date_sold >= date_start && t.date_sold <= date_end) select t).Count(); var alltime_i3DK_result = (from t in db.retail_report where t.name.Contains("MARDKi3") && t.type == "sale" && (t.date_sold >= date_start && t.date_sold <= date_end) select t).Count(); var alltime_i5DK_result = (from t in db.retail_report where t.name.Contains("MARDKi5") && t.type == "sale" && (t.date_sold >= date_start && t.date_sold <= date_end) select t).Count(); var alltime_i7DK_result = (from t in db.retail_report where t.name.Contains("MARDKi7") && t.type == "sale" && (t.date_sold >= date_start && t.date_sold <= date_end) select t).Count(); var alltime_C2DLP_result = (from t in db.retail_report where t.name.Contains("MARLPC2D") && t.type == "sale" && (t.date_sold >= date_start && t.date_sold <= date_end) select t).Count(); var alltime_i3LP_result = (from t in db.retail_report where t.name.Contains("MARLPi3") && t.type == "sale" && (t.date_sold >= date_start && t.date_sold <= date_end) select t).Count(); var alltime_i5LP_result = (from t in db.retail_report where t.name.Contains("MARLPi5") && t.type == "sale" && (t.date_sold >= date_start && t.date_sold <= date_end) select t).Count(); var alltime_i7LP_result = (from t in db.retail_report where t.name.Contains("MARLPi7") && t.type == "sale" && (t.date_sold >= date_start && t.date_sold <= date_end) select t).Count(); var alltime_mbp_result = (from t in db.retail_report where t.name.Contains("MBP105-109") && t.type == "sale" && (t.date_sold >= date_start && t.date_sold <= date_end) select t).Count(); var alltime_mb_result = (from t in db.retail_report where t.name.Contains("MB105-109") && t.type == "sale" && (t.date_sold >= date_start && t.date_sold <= date_end) select t).Count(); var alltime_idk_result = (from t in db.retail_report where t.name.Contains("IDK105-109") && t.type == "sale" && (t.date_sold >= date_start && t.date_sold <= date_end) select t).Count(); var alltime_oem_c2ddk_result = (from t in db.retail_report where t.name.Contains("OEMDKC2D") && t.type == "sale" && (t.date_sold >= date_start && t.date_sold <= date_end) select t).Count(); var alltime_oem_i3DK_result = (from t in db.retail_report where t.name.Contains("OEMDKi3") && t.type == "sale" && (t.date_sold >= date_start && t.date_sold <= date_end) select t).Count(); var alltime_oem_i5DK_result = (from t in db.retail_report where t.name.Contains("OEMDKi5") && t.type == "sale" && (t.date_sold >= date_start && t.date_sold <= date_end) select t).Count(); var alltime_oem_i7DK_result = (from t in db.retail_report where t.name.Contains("OEMDKi7") && t.type == "sale" && (t.date_sold >= date_start && t.date_sold <= date_end) select t).Count(); var alltime_oem_C2DLP_result = (from t in db.retail_report where t.name.Contains("OEMLPC2D") && t.type == "sale" && (t.date_sold >= date_start && t.date_sold <= date_end) select t).Count(); var alltime_oem_i3LP_result = (from t in db.retail_report where t.name.Contains("OEMLPi3") && t.type == "sale" && (t.date_sold >= date_start && t.date_sold <= date_end) select t).Count(); var alltime_oem_i5LP_result = (from t in db.retail_report where t.name.Contains("OEMLPi5") && t.type == "sale" && (t.date_sold >= date_start && t.date_sold <= date_end) select t).Count(); var alltime_oem_i7LP_result = (from t in db.retail_report where t.name.Contains("OEMLPi7") && t.type == "sale" && (t.date_sold >= date_start && t.date_sold <= date_end) select t).Count(); var result = db.Database.SqlQuery <date_result>("SELECT DISTINCT(date(date_sold)) as date ,count( * ) AS count FROM retail_report where type = 'sale' GROUP BY date_sold ORDER BY date_sold ASC ").ToArray(); var return_result = db.Database.SqlQuery <date_result>("SELECT DISTINCT(date(date_sold)) as date ,count( * ) AS count FROM retail_report where type = 'return' GROUP BY date_sold ORDER BY date_sold ASC ").ToArray(); var month = db.Database.SqlQuery <date_result>("SELECT DISTINCT(date(date_sold)) as date ,count( * ) AS count FROM retail_report where type = 'sale' AND YEAR(date_sold) = YEAR(NOW()) AND MONTH(date_sold) = MONTH(NOW()) GROUP BY date_sold ORDER BY date_sold ASC ").ToArray(); var year = db.Database.SqlQuery <date_result>("SELECT DISTINCT(date(date_sold)) as date ,count( * ) AS count FROM retail_report where type = 'sale' AND YEAR(date_sold) = YEAR(NOW()) GROUP BY date_sold ORDER BY date_sold ASC ").ToArray(); // var result2 = db.Database.SqlQuery<string>("SELECT DISTINCT(date(date_sold)) as date FROM retail_report where type = 'sale' GROUP BY date_sold ORDER BY date_sold ASC ").ToArray(); foreach (var item in month) { DateTime dt = Convert.ToDateTime(item.date); item.date = dt.ToString("yyyy-MM-dd"); } foreach (var item in return_result) { DateTime dt = Convert.ToDateTime(item.date); item.date = dt.ToString("yyyy-MM-dd"); avg_return += int.Parse(item.count); } foreach (var item in year) { DateTime dt = Convert.ToDateTime(item.date); item.date = dt.ToString("yyyy-MM-dd"); } foreach (var item in result) { DateTime dt = Convert.ToDateTime(item.date); item.date = dt.ToString("yyyy-MM-dd"); var test_year = DateTime.Now.Year.ToString(); var test_month = DateTime.Now.ToString("MM"); avg_alltime += int.Parse(item.count); if (item.date.Contains(DateTime.Now.Year.ToString())) { avg_year += int.Parse(item.count); avg_year_counter++; } if (item.date.Contains(test_year + "-" + test_month)) { avg_month += int.Parse(item.count); avg_month_counter++; } } avg_month = (avg_month / avg_month_counter); avg_alltime = (avg_alltime / result.Length); avg_year = (avg_year / avg_year_counter); avg_return = (avg_return / return_result.Length); return(Json(new { oem_C2Dlp_all = alltime_oem_C2DLP_result, oem_i3lp_all = alltime_oem_i3LP_result, oem_i5lp_all = alltime_oem_i5LP_result, oem_i7lp_all = alltime_oem_i7LP_result, oem_C2DDK_all = alltime_oem_c2ddk_result, oem_i3dk_all = alltime_oem_i3DK_result, oem_i5dk_all = alltime_oem_i5DK_result, oem_i7dk_all = alltime_oem_i7DK_result, C2Dlp_all = alltime_C2DLP_result, i3lp_all = alltime_i3LP_result, i5lp_all = alltime_i5LP_result, i7lp_all = alltime_i7LP_result, C2DDK_all = alltime_C2DDK_result, i3dk_all = alltime_i3DK_result, i5dk_all = alltime_i5DK_result, i7dk_all = alltime_i7DK_result, return_result = return_result, avg_return = avg_return, alltime_result = result, month_result = month, year_result = year, avg_month = avg_month, avg_alltime = avg_alltime, avg_year = avg_year, alltime_mbp = alltime_mbp_result, alltime_mb = alltime_mb_result, alltime_idk = alltime_idk_result }, JsonRequestBehavior.AllowGet)); } }
public async Task <ActionResult> get_shipment(string id) { db_a094d4_icdbEntities1 db = new db_a094d4_icdbEntities1(); var baseAddress = new Uri("https://ssapi.shipstation.com/"); if (id == "interconnection123") { try { using (var httpClient = new HttpClient { BaseAddress = baseAddress }) { //Debug.Write(jj); httpClient.DefaultRequestHeaders.TryAddWithoutValidation("authorization", "Basic ZmU3YzE2MGMyZjE0NDc1ZDljNWQ0ZWI2ZmMzYmRhOWU6YzRiM2RhMjlkZWZlNDgyOWJlZmRlYTExNmU1N2Q5ZTY="); // var DateStart = new DateTime(2016, 12, 13); var DateStart = DateTime.Today; var DateEnd = DateTime.Today.AddDays(+1); // var DateEnd = new DateTime(2016, 12, 30); using (var response = await httpClient.GetAsync("shipments?includeShipmentItems=true&shipDateStart=" + DateStart + "&shipDateEnd=" + DateEnd)) { if (response.IsSuccessStatusCode != true) { return(View(ViewBag.message = response.RequestMessage)); } string responseData = await response.Content.ReadAsStringAsync(); var result = JsonConvert.DeserializeObject <ss_order.ss_shipment_detail.Rootobject>(responseData); var total_page = result.pages; for (int i = 0; i < result.shipments.Length; i++) { if (result.shipments[i].shipmentItems != null) { var order_id = result.shipments[i].orderId; await get_order_detail(order_id); } } } } db.Dispose(); using (var db2 = new db_a094d4_icdbEntities1()) { db2.Database.ExecuteSqlCommand( "insert into process_run_time (process) values ('ShipStation')"); } } catch (System.Data.Entity.Validation.DbEntityValidationException dbEx) { Exception raise = dbEx; foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { string message = string.Format("{0}:{1}", validationErrors.Entry.Entity.ToString(), validationError.ErrorMessage); // raise a new exception nesting // the current instance as InnerException raise = new InvalidOperationException(message, raise); } } throw raise; } ViewBag.message = "Completed"; return(View()); } else { ViewBag.message = "Invalid ID"; return(View()); } }
public async Task get_order_detail(int orderID) { var bb = 0; Thread.Sleep(1700); //try { var baseAddress = new Uri("https://ssapi.shipstation.com/"); db_a094d4_icdbEntities1 db = new db_a094d4_icdbEntities1(); using (var httpClient = new HttpClient { BaseAddress = baseAddress }) { httpClient.DefaultRequestHeaders.TryAddWithoutValidation("authorization", "Basic ZmU3YzE2MGMyZjE0NDc1ZDljNWQ0ZWI2ZmMzYmRhOWU6YzRiM2RhMjlkZWZlNDgyOWJlZmRlYTExNmU1N2Q5ZTY="); using (var response = await httpClient.GetAsync("orders/" + orderID + "")) { string responseData = await response.Content.ReadAsStringAsync(); var result = JsonConvert.DeserializeObject <Models.ShipStation_orderID.Rootobject>(responseData); for (int i = 0; i < result.items.Length; i++) { var write_table = new shipstation_log(); if (result.advancedOptions.customField1 == null) { result.advancedOptions.customField1 = ""; } if (result.advancedOptions.customField2 == null) { result.advancedOptions.customField2 = ""; } if (result.advancedOptions.customField3 == null) { result.advancedOptions.customField3 = ""; } write_table.sku = result.items[i].sku; write_table.store_id = result.advancedOptions.storeId; write_table.item_name = result.items[i].name; write_table.item_qty = result.items[i].quantity; write_table.item_url = result.items[i].imageUrl; write_table.custom_field_1 = result.advancedOptions.customField1.ToString(); write_table.custom_field_2 = result.advancedOptions.customField2.ToString(); write_table.custom_field_3 = result.advancedOptions.customField3.ToString(); write_table.order_id = orderID; write_table.order_num = result.orderNumber; write_table.status = result.orderStatus; if (result.shipDate == null) { write_table.shipment_date = null; } else { write_table.shipment_date = DateTime.Parse(result.shipDate); } db.shipstation_log.Add(write_table); db.SaveChanges(); Debug.WriteLine(bb++); count_item(write_table); } } } //} //catch (System.Data.Entity.Validation.DbEntityValidationException dbEx) //{ // Exception raise = dbEx; // foreach (var validationErrors in dbEx.EntityValidationErrors) // { // foreach (var validationError in validationErrors.ValidationErrors) // { // string message = string.Format("{0}:{1}", // validationErrors.Entry.Entity.ToString(), // validationError.ErrorMessage); // // raise a new exception nesting // // the current instance as InnerException // raise = new InvalidOperationException(message, raise); // } // } // throw raise; //} }
public ActionResult main() { using (var db = new db_a094d4_icdbEntities1()) { // var result = (from t in db.shipstation_log where t.store_id == 12171 && t.shipment_date.Contains("2016-01") select t).ToList(); //distinct customer field 2 list // var q = result.GroupBy(x => x.custom_field_2).Select(group => group.First()).ToList() ; //iterate that list // for (int i =0;i < q.Count; i++) { //break the fields to indiv item //add number of item to SKU //switch (q[i].sku) { // case "HW-48678": // hw48678 += count_item(q[i].custom_field_2,int.Parse(q[i].item_qty.ToString())); // break; // case "HW-48680": // hw48680 += count_item(q[i].custom_field_2,int.Parse(q[i].item_qty.ToString())); // break; // case "HW-48986": // hw48986 += count_item(q[i].custom_field_2,int.Parse(q[i].item_qty.ToString())); // break; // case "HW-48993": // hw48993 += count_item(q[i].custom_field_2,int.Parse(q[i].item_qty.ToString())); // break; // case "HW-48997": // hw48997 += count_item(q[i].custom_field_2,int.Parse(q[i].item_qty.ToString())); // break; // case "HW-49000": // hw49000 += count_item(q[i].custom_field_2,int.Parse(q[i].item_qty.ToString())); // break; // case "HW-49001": // hw49001 += count_item(q[i].custom_field_2,int.Parse(q[i].item_qty.ToString())); // break; // case "HW-49110": // hw49110 += count_item(q[i].custom_field_2,int.Parse(q[i].item_qty.ToString())); // break; // case "HW-49193": // hw49193 += count_item(q[i].custom_field_2,int.Parse(q[i].item_qty.ToString())); // break; // case "HW-49195": // hw49195 += count_item(q[i].custom_field_2,int.Parse(q[i].item_qty.ToString())); // break; // case "HW-49347": // hw49347 += count_item(q[i].custom_field_2,int.Parse(q[i].item_qty.ToString())); // break; // case "HW-49812": // hw49812 += count_item(q[i].custom_field_2,int.Parse(q[i].item_qty.ToString())); // break; // case "HW-49734": // hw49734 += count_item(q[i].custom_field_2,int.Parse(q[i].item_qty.ToString())); // break; // case "HW-49704": // hw49704 += count_item(q[i].custom_field_2,int.Parse(q[i].item_qty.ToString())); // break; // case "HW-49654": // hw49654 += count_item(q[i].custom_field_2,int.Parse(q[i].item_qty.ToString())); // break; // case "HW-49652": // hw49652 += count_item(q[i].custom_field_2,int.Parse(q[i].item_qty.ToString())); // break; // case "HW-49649": // hw49649 += count_item(q[i].custom_field_2,int.Parse(q[i].item_qty.ToString())); // break; // case "HW-49557": // hw49557 += count_item(q[i].custom_field_2,int.Parse(q[i].item_qty.ToString())); // break; // case "HW-49555": // hw49555 += count_item(q[i].custom_field_2,int.Parse(q[i].item_qty.ToString())); // break; //} } } return(View()); }
//process the item in custom fields public void count_item(shipstation_log entry) { try { var write_table = new ship_log(); if (string.IsNullOrEmpty(entry.custom_field_2)) { } else { try { string[] lines = entry.custom_field_2.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None); lines = lines.Where(x => !string.IsNullOrEmpty(x)).ToArray(); foreach (var item in lines) { using (db_a094d4_icdbEntities1 db = new db_a094d4_icdbEntities1()) { var exisit = (from t in db.ship_log where t.ictag == item select t).SingleOrDefault(); if (exisit == null) { write_table.ictag = item; write_table.order_id = entry.order_id; write_table.order_num = entry.order_num; write_table.shipdate = entry.shipment_date; write_table.sku = entry.sku; write_table.status = entry.status; write_table.store_id = entry.store_id; db.ship_log.Add(write_table); db.SaveChanges(); } var update = db.ts_stock.Where(s => s.ictag == item).FirstOrDefault(); if (update != null) { update.status = "Shipped"; update.update_time = DateTime.Now; using (var dbCtx = new db_a094d4_icdbEntities1()) { //Mark entity as modified dbCtx.Entry(update).State = System.Data.Entity.EntityState.Modified; //call SaveChanges dbCtx.SaveChanges(); } } } } } catch { entry.custom_field_2 = ""; } } } catch (System.Data.Entity.Validation.DbEntityValidationException dbEx) { Exception raise = dbEx; foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { string message = string.Format("{0}:{1}", validationErrors.Entry.Entity.ToString(), validationError.ErrorMessage); // raise a new exception nesting // the current instance as InnerException raise = new InvalidOperationException(message, raise); } } throw raise; } }