Esempio n. 1
0
        public wsSQLResult CreateAccount(Stream JSONdataStream)
        {
            wsSQLResult result = new wsSQLResult();

            try
            {
                StreamReader reader   = new StreamReader(JSONdataStream);
                string       JSONdata = reader.ReadToEnd();

                JavaScriptSerializer jss = new JavaScriptSerializer();

                wsAccount acc = jss.Deserialize <wsAccount>(JSONdata);
                if (acc == null)
                {
                    result.WasSuccessful = 0;
                    result.Exception     = "Unable to deserialize the JSON data.";
                    return(result);
                }

                BankDataContext dc         = new BankDataContext();
                Account         newAccount = new Account()
                {
                    balance        = acc.balance,
                    running_totals = acc.runningTotals,
                    first_name     = acc.firstName,
                    last_name      = acc.lastName,
                    address        = acc.Address,
                    postcode       = acc.postCode,
                    telephone      = acc.telePhone,
                    pin            = acc.pin
                };

                dc.Accounts.InsertOnSubmit(newAccount);
                dc.SubmitChanges();

                result.WasSuccessful = 1;
                result.Exception     = "";
                return(result);
            }
            catch (Exception ex)
            {
                result.WasSuccessful = 0;
                result.Exception     = ex.Message;
                return(result);
            }
        }
Esempio n. 2
0
        public int UpdateAccount(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();
                wsAccount            acc = jss.Deserialize <wsAccount>(JSONdata);
                if (acc == null)
                {
                    // Error: Couldn't deserialize our JSON string into a "wsOrder" object.
                    return(-2);
                }

                BankDataContext dc             = new BankDataContext();
                Account         currentAccount = dc.Accounts.Where(o => o.Acc_ID == acc.AccountID).FirstOrDefault();
                if (currentAccount == null)
                {
                    // Couldn't find an [Order] record with this ID
                    return(-3);
                }

                currentAccount.balance        = acc.balance;
                currentAccount.running_totals = acc.runningTotals;
                currentAccount.first_name     = acc.firstName;
                currentAccount.last_name      = acc.lastName;
                currentAccount.address        = acc.Address;
                currentAccount.postcode       = acc.postCode;
                currentAccount.telephone      = acc.telePhone;
                currentAccount.pin            = acc.pin;

                dc.SubmitChanges();

                return(0);     // Success !
            }
            catch (Exception)
            {
                return(-1);
            }
        }