public List <WSCustomer> GetAllCustomers() { using (NorthwindDataContext daa = new NorthwindDataContext()) { Thread.Sleep(4000); var c = from x in daa.Customers select new WSCustomer { CustomerID = x.CustomerID, ContactName = x.ContactName, CompanyName = x.CompanyName }; return(c.ToList()); } }
public wsSQLResult CreateCustomer(Stream JSONdataStream) { wsSQLResult result = new wsSQLResult(); try { // Read in our Stream into a string... StreamReader reader = new StreamReader(JSONdataStream); string JSONdata = reader.ReadToEnd(); // ..then convert the string into a single "wsCustomer" record. JavaScriptSerializer jss = new JavaScriptSerializer(); wsCustomer cust = jss.Deserialize <wsCustomer>(JSONdata); if (cust == null) { // Error: Couldn't deserialize our JSON string into a "wsCustomer" object. result.WasSuccessful = 0; result.Exception = "Unable to deserialize the JSON data."; return(result); } NorthwindDataContext dc = new NorthwindDataContext(); Customer newCustomer = new Customer() { CustomerID = cust.CustomerID, CompanyName = cust.CompanyName, City = cust.City }; dc.Customers.InsertOnSubmit(newCustomer); dc.SubmitChanges(); result.WasSuccessful = 1; result.Exception = ""; return(result); } catch (Exception ex) { result.WasSuccessful = 0; result.Exception = ex.Message; return(result); } }
public int UpdateOrderAddress(Stream JSONdataStream) { try { // Read in our Stream into a string... StreamReader reader = new StreamReader(JSONdataStream); string JSONdata = reader.ReadToEnd(); // ..then convert the string into a single "wsOrder" record. JavaScriptSerializer jss = new JavaScriptSerializer(); wsOrder order = jss.Deserialize <wsOrder>(JSONdata); if (order == null) { // Error: Couldn't deserialize our JSON string into a "wsOrder" object. return(-2); } NorthwindDataContext dc = new NorthwindDataContext(); Order currentOrder = dc.Orders.Where(o => o.OrderID == order.OrderID).FirstOrDefault(); if (currentOrder == null) { // Couldn't find an [Order] record with this ID return(-3); } // Update our SQL Server [Order] record, with our new Shipping Details (send from whatever // app is calling this web service) currentOrder.ShipName = order.ShipName; currentOrder.ShipAddress = order.ShipAddress; currentOrder.ShipCity = order.ShipCity; dc.SubmitChanges(); return(0); // Success ! } catch (Exception) { return(-1); } }