private void testAccountCRUD()
        {
            string accId = createAccount(true);

            Account accountQuery = queryAccount(accId);
            print("Create Active Account: " + accId);
            // print(toString(accountQuery));

            var accUpdate = new Account();
            accUpdate.Id = accId;
            accUpdate.Name = "testUpdate" + DateTime.Now.Ticks;

            update(accUpdate);

            accountQuery = queryAccount(accId);
            print("Updated Account: " + accId);
            // print(toString(accountQuery));

            bool deleted = delete("Account", accId);
            print("Deleted Account: " + deleted);
        }
 /// <summary>
 /// Validates the login and returns the users saved settings.
 /// </summary>
 /// <param name="username"></param>
 /// <param name="password"></param>
 /// <returns></returns>
 public JsonResult ValidateLogin(string username, string password)
 {
     var test = new Account() { Username = username, Password = password };
     Account data =
         connection.Query<Account>(
             "select * from Account where Username='******' and Password='******'").FirstOrDefault();
     if (data != null)
     {
         return Json(new
         {
             Success = true,
             Email = data.Email,
             Settings = data.Settings,
         }, JsonRequestBehavior.AllowGet);
     }
     else
     {
         return Json(new
         {
             Success = false,
             Email = "",
         }, JsonRequestBehavior.AllowGet);
     }
 }
 public JsonResult CreateAccount(string username, string password, string email)
 {
     try
     {
         Account data = connection.Query<Account>("select * from Account where Username='******'").FirstOrDefault();
         if (data == null)
         {
             var test = new Account() { Username = username, Password = password, Email = email };
             var testId = connection.Query<int>(
                 "insert Account (Username, Password, Email) values (@Username, @Password, @Email); select cast(scope_identity() as int)", test).First();
             if (testId != 0)
             {
                 return Json(new
                 {
                     Success = true,
                     Email = email,
                     Username = username,
                     Message = "Account Added."
                 }, JsonRequestBehavior.AllowGet);
             }
         }
         else
         {
             return Json(new
             {
                 Success = false,
                 Message = "Username is taken.",
                 Email = email,
                 Username = username,
             }, JsonRequestBehavior.AllowGet);
         }
         return Json(new
         {
             Success = false,
             Message = "There was an error processing this account, try again later.",
             Email = email,
             Username = username,
         }, JsonRequestBehavior.AllowGet);
     }
     catch (Exception ex)
     {
         return Json(new
         {
             Success = false,
             Message = ex.InnerException,
             //Message = "There was an error processing this account, try again later.",
             Email = email,
             Username = username,
         }, JsonRequestBehavior.AllowGet);
     }
 }
        public string createAccount(bool active)
        {
            // create account
            Account acc1 = makeAccount();
            string accountId = create(acc1);

            if (active)
            {
                // create contact
                Contact con = makeContact();
                con.AccountId = accountId;
                string contactId = create(con);

                PaymentMethod pm = makePaymentMethod();
                pm.AccountId = accountId;
                string pmId = create(pm);

                // set required active fields and activate
                var accUpdate = new Account();
                accUpdate.Id = accountId;
                accUpdate.Status = "Active";
                accUpdate.SoldToId = contactId;
                accUpdate.BillToId = contactId;
                accUpdate.AutoPay = true;
                accUpdate.PaymentTerm = "Due Upon Receipt";
                accUpdate.DefaultPaymentMethodId = pmId;
                update(accUpdate);
            }

            return accountId;
        }
 private Account makeAccount()
 {
     long time = DateTime.Now.Ticks;
     var acc = new Account();
     acc.AccountNumber = "t-" + time; // string
     acc.Batch = "Batch1"; // enum
     acc.BillCycleDay = 1; // int
     acc.BillCycleDaySpecified = true;
     acc.AllowInvoiceEdit = true; // boolean
     acc.AutoPay = false;
     acc.CrmId = "SFDC-" + time;
     acc.Currency = "USD"; // standard DB enum
     acc.CustomerServiceRepName = "CSR Dude";
     acc.Name = "SomeAccount" + time;
     acc.PurchaseOrderNumber = "PO-" + time;
     acc.SalesRepName = "Sales Dude";
     acc.PaymentTerm = "Due Upon Receipt";
     acc.Status = "Draft";
     return acc;
 }