示例#1
0
        private QueryModel ParseInsert()
        {
            var queryModel = new InsertQueryModel();

            DiscardToken(TokenType.InsertKeyword);
            DiscardToken(TokenType.IntoKeyword);

            queryModel.TargetTable = ParseObject();

            DiscardToken(TokenType.ValuesKeyword);

            queryModel.Rows = ParseInsertRow();

            ExpectToken(TokenType.EndOfSequence);

            return(queryModel);
        }
示例#2
0
文件: Store.cs 项目: mattherman/MinDb
        public QueryResult Insert(InsertQueryModel query)
        {
            if (string.Compare(query.TargetTable.Name, "users") != 0)
            {
                throw new DataAccessException("Table does not exist");
            }

            var result = new QueryResult();

            foreach (var row in query.Rows)
            {
                var values = row.Values.ToList();

                var id       = int.Parse(values[0].Value);
                var username = values[1].Value;
                var email    = values[2].Value;

                _users.Insert(id, username, email);

                result.Rows.Add(new Row(id, username, email));
            }

            return(result);
        }
示例#3
0
        public ActionResult Register(LoginRegisterModel id)
        {
            //Check if we already have a user registered with the same email address
            if (customerTable.SelectRecord(new SelectCustomerModel()
            {
                Email = id.email
            }).CustomerUUID != null)
            {
                return(Json(new { result = "Fail", reason = "Email address is already registered" }));
            }

            //Generate Password's Salt and Hash
            byte[] salt       = Password.ComputeSaltBytes();
            string hashString = Password.ComputeHash(id.password, salt);
            string saltString = Convert.ToBase64String(salt);

            //Insert into Customer table
            InsertCustomerModel newCustomer = new InsertCustomerModel()
            {
                FirstName = id.firstName,
                LastName  = id.lastName,
                Phone     = id.phone,
                Email     = id.email,
                Hash      = hashString,
                Salt      = saltString
            };
            CustomerResultModel customerResult = customerTable.InsertRecord(newCustomer);

            //If it didn't insert, then we won't get a UUID back
            if (customerResult.CustomerUUID == null)
            {
                return(Json(new { result = "Fail", reason = "Insert into the database was not successful" }));
            }

            //Insert customer's address into the address table
            InsertAddressModel customerAddress = new InsertAddressModel()
            {
                CustomerUUID = customerResult.CustomerUUID,

                BillingAddress  = id.address,
                BillingAddress2 = id.address2,
                BillingCity     = id.city,
                BillingState    = id.state,
                BillingZip      = Int32.Parse(id.postalCode),

                ShippingAddress  = id.address,
                ShippingAddress2 = id.address2,
                ShippingCity     = id.city,
                ShippingState    = id.state,
                ShippingZip      = Int32.Parse(id.postalCode)
            };

            NonQueryResultModel addressResult = addressTable.InsertRecord(customerAddress); //We have the option to 'do something' if the insert fails

            //Insert into Query table
            InsertQueryModel customerQuery = new InsertQueryModel()
            {
                CustomerUUID = customerResult.CustomerUUID,

                Category   = "",
                CategoryID = "",
                Frequency  = "",
                PriceLimit = ""
            };
            NonQueryResultModel queryResult = queryTable.InsertRecord(customerQuery); //If this fails, we have the option of doing something

            //Aaaand we're done.
            return(Json(new { result = "Success" }));
        }