예제 #1
0
        public IEnumerable <Cafe> GetCafesByUserId(int Id)
        {
            DbCafeTable dbCafeTable = new DbCafeTable();
            List <Cafe> cafes       = new List <Cafe>();

            try
            {
                using (SqlConnection connection = new SqlConnection(_connectionString))
                {
                    connection.Open();
                    using (SqlCommand command = connection.CreateCommand())
                    {
                        command.CommandText = "SELECT * FROM Cafe, ZipCity WHERE Cafe.UserID = @id and ZipCity.Zip = cafe.Zip";
                        command.Parameters.AddWithValue("@id", Id);

                        SqlDataReader reader = command.ExecuteReader();
                        while (reader.Read())
                        {
                            Cafe cafe = new Cafe
                            {
                                Id          = reader.GetInt32(reader.GetOrdinal("ID")),
                                Name        = reader.GetString(reader.GetOrdinal("CName")),
                                City        = reader.GetString(reader.GetOrdinal("City")),
                                Address     = reader.GetString(reader.GetOrdinal("CAddress")),
                                PriceRange  = reader.GetDecimal(reader.GetOrdinal("PriceRange")),
                                Rating      = reader.GetInt32(reader.GetOrdinal("Rating")),
                                OpenTime    = reader.GetDateTime(reader.GetOrdinal("OpenTime")),
                                CloseTime   = reader.GetDateTime(reader.GetOrdinal("CloseTime")),
                                PhoneNo     = reader.GetString(reader.GetOrdinal("PhoneNo")),
                                Description = reader.GetString(reader.GetOrdinal("CDescription")),
                                Type        = reader.GetString(reader.GetOrdinal("CType")),
                                Zip         = reader.GetString(reader.GetOrdinal("Zip")),
                            };
                            cafe.Tables = dbCafeTable.GetAllTablesInCafe(cafe.Id);
                            cafes.Add(cafe);
                        }
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
            return(cafes);
        }
예제 #2
0
        public Cafe GetCafeById(int Id)
        {
            DbCafeTable dbCafeTable = new DbCafeTable();
            DbUser      dbUser      = new DbUser();
            Cafe        cafe        = new Cafe();

            try
            {
                using (SqlConnection connection = new SqlConnection(_connectionString))
                {
                    connection.Open();
                    using (SqlCommand command = connection.CreateCommand())
                    {
                        command.CommandText = "SELECT * FROM Cafe, ZipCity WHERE ZipCity.Zip = Cafe.Zip AND Cafe.ID = @id";
                        command.Parameters.AddWithValue("@id", Id);

                        SqlDataReader reader = command.ExecuteReader();
                        while (reader.Read())
                        {
                            cafe.Id          = reader.GetInt32(reader.GetOrdinal("ID"));
                            cafe.Name        = reader.GetString(reader.GetOrdinal("CName"));
                            cafe.City        = reader.GetString(reader.GetOrdinal("City"));
                            cafe.Address     = reader.GetString(reader.GetOrdinal("CAddress"));
                            cafe.PriceRange  = reader.GetDecimal(reader.GetOrdinal("PriceRange"));
                            cafe.Rating      = reader.GetInt32(reader.GetOrdinal("Rating"));
                            cafe.OpenTime    = reader.GetDateTime(reader.GetOrdinal("OpenTime"));
                            cafe.CloseTime   = reader.GetDateTime(reader.GetOrdinal("CloseTime"));
                            cafe.PhoneNo     = reader.GetString(reader.GetOrdinal("PhoneNo"));
                            cafe.Description = reader.GetString(reader.GetOrdinal("CDescription"));
                            cafe.Type        = reader.GetString(reader.GetOrdinal("CType"));
                            cafe.User        = dbUser.GetUserByID(reader.GetInt32(reader.GetOrdinal("UserID")));
                            cafe.Zip         = reader.GetString(reader.GetOrdinal("Zip"));
                            cafe.Tables      = dbCafeTable.GetAllTablesInCafe(cafe.Id);
                        }
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
            return(cafe);
        }