示例#1
0
        public void CustomerSaveTest()
        {
            Customer customer = new Customer("Ali");
            customer.Email = "*****@*****.**";

            Address address = new Address();
            address.Street = "2534 Lorong 2 Taman India";
            address.Postal = "12345";
            address.State = "Melaka";

            Stock stock = new Stock(3);
            Nisan nisan = new Nisan(stock);
            nisan.Name = "Ramli" + new System.Random().Next(100) + " bin Taib";
            nisan.Death = RandomDate();

            Order target = new Order();
            target.Status = TransactionStage.Submit;
            //target.Agent = new Agent("W002");
            target.Amount = stock.Price;
            target.Quantity = 1;
            target.Stock = nisan;
            target.ShipTo = address;
            target.Parent.CreatedBy = customer;//can be an agent
            Assert.IsTrue(target.Save());
        }
示例#2
0
        public void CustomerAddressSaveTest()
        {
            Customer target = new Customer("Ahmad bin talib");
            target.Email = "*****@*****.**";

            Address address = new Address();
            address.Street = "963 Jalan 6 Machang Bubok";
            address.Postal = "14020";
            address.State = "Penang";
            target.Address = address;

            Assert.IsTrue(target.Save());
        }
示例#3
0
        public User Find()
        {
            User user = null;
            using (DbConnection connection = factory.CreateConnection())
            {
                connection.ConnectionString = connectionString;
                connection.Open();
                using (DbCommand command = connection.CreateCommand())
                {
                    command.CommandType = System.Data.CommandType.Text;
                    if (this.idField > 0)
                        command.CommandText = "SELECT * FROM " + this.tableName + " WHERE Id=" + this.idField + ";";
                    else if (this.emailField.Length > 0)
                    {
                        command.CommandText = "SELECT * FROM " + this.tableName + " WHERE Email=@Email;";
                        command.Parameters.Add(CreateParameter("@Email", this.emailField));
                    }
                    else if (this.codeField.Length > 0)
                    {
                        command.CommandText = "SELECT * FROM " + this.tableName + " WHERE Code=@Code;";
                        command.Parameters.Add(CreateParameter("@Code", this.codeField));
                    }

                    using (DbDataReader reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            Role role = (Role)Convert.ToInt32(reader["Type"]);
                            switch (role)
                            {
                                case Role.Admin:
                                    user = new Admin();
                                    break;
                                case Role.Designer:
                                    user = new Designer();
                                    break;
                                case Role.Agent:
                                    user = new Agent();
                                    break;
                                case Role.Customer:
                                default:
                                    user = new Customer();
                                    break;
                            }
                            user.Id = Convert.ToInt32(reader["Id"]);
                            user.Code = reader["Code"].ToString();
                            user.Name = reader["Name"].ToString();
                            user.Password = reader["Password"].ToString();
                            user.Email = reader["Email"].ToString();
                            user.Phone = reader["Phone"].ToString();
                            user.Remarks = reader["Remarks"].ToString();
                            user.Uri = reader["Uri"].ToString();

                            if (reader["AddressId"] != DBNull.Value)
                            {
                                int addressId = Convert.ToInt32(reader["AddressId"]);
                                if (addressId > 0) user.Address = new Address(addressId);
                            }
                        }
                    }
                }

                connection.Close();
            }//end

            return user;
        }