Esempio n. 1
0
        public wsSQLResult DeleteTestDbItem(string TestDbItemID)
        {
            wsSQLResult result = new wsSQLResult();

            try
            {
                narfdaddy2DataContext dc   = new narfdaddy2DataContext();
                ListBuilder1          item = dc.ListBuilder1s.Where(s => s.numRow == Int32.Parse(TestDbItemID)).FirstOrDefault();
                if (item == null)
                {
                    // We couldn't find a [Customer] record with this ID.
                    result.WasSuccessful = -3;
                    result.Exception     = "Could not find a [ListBuilder1] record with ID: " + TestDbItemID.ToString();
                    return(result);
                }

                dc.ListBuilder1s.DeleteOnSubmit(item);
                dc.SubmitChanges();

                result.WasSuccessful = 1;
                result.Exception     = "";
                return(result);     // Success !
            }
            catch (Exception ex)
            {
                result.WasSuccessful = -1;
                result.Exception     = "An exception occurred: " + ex.Message;
                return(result);     // Failed.
            }
        }
Esempio n. 2
0
        public wsSQLResult DeleteCustomer(string customerID)
        {
            wsSQLResult result = new wsSQLResult();

            try
            {
                NorthwindDataContext dc   = new NorthwindDataContext();
                Customer             cust = dc.Customers.Where(s => s.CustomerID == customerID).FirstOrDefault();
                if (cust == null)
                {
                    // We couldn't find a [Customer] record with this ID.
                    result.WasSuccessful = -3;
                    result.Exception     = "Could not find a [Customer] record with ID: " + customerID.ToString();
                    return(result);
                }

                dc.Customers.DeleteOnSubmit(cust);
                dc.SubmitChanges();

                result.WasSuccessful = 1;
                result.Exception     = "";
                return(result);     // Success !
            }
            catch (Exception ex)
            {
                result.WasSuccessful = -1;
                result.Exception     = "An exception occurred: " + ex.Message;
                return(result);     // Failed.
            }
        }
Esempio n. 3
0
        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);
            }
        }
Esempio n. 4
0
        public wsSQLResult CreateTestDbItem(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();
                wsTestDbItem         item = jss.Deserialize <wsTestDbItem>(JSONdata);
                if (item == 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);
                }

                narfdaddy2DataContext dc          = new narfdaddy2DataContext();
                ListBuilder1          newCustomer = new ListBuilder1()
                {
                    sCat    = item.sCat,
                    sSubcat = item.sSubcat,
                    sDialog = item.sDialog
                };

                dc.ListBuilder1s.InsertOnSubmit(newCustomer);
                dc.SubmitChanges();

                result.WasSuccessful = 1;
                result.Exception     = "";
                return(result);
            }
            catch (Exception ex)
            {
                result.WasSuccessful = 0;
                result.Exception     = ex.Message;
                return(result);
            }
        }