public List <RestaurantInfo> GetRestaurantsByRating(int rating)
        {
            restaurants           all_restaurants = GetRestaurantsFromXml();
            List <RestaurantInfo> restaurant_info = new List <RestaurantInfo>();

            if (all_restaurants != null)
            {
                foreach (restaurant restaurant in all_restaurants.restaurant)
                {
                    if (restaurant.rating >= rating)
                    {
                        RestaurantInfo info = new RestaurantInfo
                        {
                            Name     = restaurant.name,
                            Rating   = restaurant.rating.ToString(),
                            Summary  = restaurant.summary,
                            Location = new Address
                            {
                                Street     = restaurant.location.street,
                                City       = restaurant.location.city,
                                Province   = restaurant.location.provstate,
                                PostalCode = restaurant.location.postalzipcode
                            }
                        };
                        restaurant_info.Add(info);
                    }
                }
                return(restaurant_info);
            }
            // return empty RestaurantInfo is name not found
            return(restaurant_info);
        }
Exemplo n.º 2
0
        public List <RestaurantInfo> GetRestaurantsByRating(int rating)
        {
            restaurants           allRestauants = GetRestaurantsFromXml();
            List <RestaurantInfo> restInfos     = new List <RestaurantInfo>();

            foreach (restaurant rest in allRestauants.restaurant)
            {
                if (rest.rating >= rating)
                {
                    RestaurantInfo restInfo = new RestaurantInfo();
                    restInfo.Name    = rest.name;
                    restInfo.Summary = rest.summary;
                    restInfo.Rating  = rest.rating;

                    restInfo.Location            = new Address();
                    restInfo.Location.Street     = rest.location.street;
                    restInfo.Location.City       = rest.location.city;
                    restInfo.Location.Province   = rest.location.provstate.ToString();
                    restInfo.Location.PostalCode = rest.location.postalzipcode;

                    restInfos.Add(restInfo);
                }
            }
            return(restInfos);
        }
Exemplo n.º 3
0
        public bool SaveRestaurant(RestaurantInfo restInfo)
        {
            restaurants allRestaurants = GetRestaurantsFromXml();

            foreach (restaurant rest in allRestaurants.restaurant)
            {
                if (rest.name == restInfo.Name)
                {
                    rest.summary                = restInfo.Summary;
                    rest.rating                 = restInfo.Rating;
                    rest.location.street        = restInfo.Location.Street;
                    rest.location.city          = restInfo.Location.City;
                    rest.location.provstate     = restInfo.Location.Province;
                    rest.location.postalzipcode = restInfo.Location.PostalCode;

                    XmlSerializer serializor = new XmlSerializer(typeof(restaurants));
                    string        xmlFile    = System.Web.HttpContext.Current.Server.MapPath(@"~/App_Data/restaurant_reviews.xml");

                    XmlTextWriter tw = new XmlTextWriter(xmlFile, Encoding.UTF8);
                    serializor.Serialize(tw, allRestaurants);
                    tw.Close();
                    return(true);
                }
            }
            return(false);
        }
        public RestaurantInfo GetRestaurantByName(string name)
        {
            restaurants all_restaurants = GetRestaurantsFromXml();

            if (all_restaurants != null)
            {
                foreach (restaurant restaurant in all_restaurants.restaurant)
                {
                    if (restaurant.name == name)
                    {
                        var restaurant_info = new RestaurantInfo
                        {
                            Name     = restaurant.name,
                            Rating   = restaurant.rating.ToString(),
                            Summary  = restaurant.summary,
                            Location = new Address
                            {
                                Street     = restaurant.location.street,
                                City       = restaurant.location.city,
                                Province   = restaurant.location.provstate,
                                PostalCode = restaurant.location.postalzipcode
                            }
                        };
                        return(restaurant_info);
                    }
                }
            }
            // return empty RestaurantInfo is name not found
            return(new RestaurantInfo());
        }
        public bool SaveRestaurant(RestaurantInfo restaurant_info)
        {
            restaurants all_restaurants = GetRestaurantsFromXml();
            restaurant  selected_restaurant;

            foreach (restaurant rest in all_restaurants.restaurant)
            {
                if (rest.name == restaurant_info.Name)
                {
                    selected_restaurant = rest;
                    string xmlFile = HttpContext.Current.Server.MapPath(@"App_Data/restaurant_reviews.xml");
                    selected_restaurant.summary                = restaurant_info.Summary;
                    selected_restaurant.rating                 = int.Parse(restaurant_info.Rating);
                    selected_restaurant.location.street        = restaurant_info.Location.Street;
                    selected_restaurant.location.postalzipcode = restaurant_info.Location.PostalCode;
                    selected_restaurant.location.provstate     = restaurant_info.Location.Province;
                    selected_restaurant.location.city          = restaurant_info.Location.City;
                    using (FileStream xs = new FileStream(xmlFile, FileMode.Create))
                    {
                        XmlSerializer serializer = new XmlSerializer(typeof(restaurants));
                        serializer.Serialize(xs, all_restaurants);
                    }
                    return(true);
                }
            }
            return(false);
        }
Exemplo n.º 6
0
        public RestaurantInfo GetRestaurantByName(string name)
        {
            restaurants allRestaurants = GetRestaurantsFormXml();

            RestaurantInfo restaurantInfo = new RestaurantInfo();
            Address        address        = new Address();

            for (int i = 0; i < allRestaurants.restaurant.Length; i++)
            {
                if (name == allRestaurants.restaurant[i].name)
                {
                    address.Street = allRestaurants.restaurant[i].location.street;

                    address.City = allRestaurants.restaurant[i].location.city;

                    address.Province = allRestaurants.restaurant[i].location.provstate;

                    address.PostalCode = allRestaurants.restaurant[i].location.postalzipcode;

                    restaurantInfo.Name    = allRestaurants.restaurant[i].name;
                    restaurantInfo.Summary = allRestaurants.restaurant[i].summary;

                    restaurantInfo.Rating   = allRestaurants.restaurant[i].rating;
                    restaurantInfo.Location = address;
                }
            }

            return(restaurantInfo);
        }
Exemplo n.º 7
0
        public bool SaveRestaurant(RestaurantInfo restInfo)
        {
            bool        saveResult     = false;
            restaurants allRestaurants = GetRestaurantsFormXml();


            for (int i = 0; i < allRestaurants.restaurant.Length; i++)
            {
                if (allRestaurants.restaurant[i].name == restInfo.Name)
                {
                    allRestaurants.restaurant[i].summary = restInfo.Summary;

                    allRestaurants.restaurant[i].rating = restInfo.Rating;

                    allRestaurants.restaurant[i].location.street        = restInfo.Location.Street;
                    allRestaurants.restaurant[i].location.city          = restInfo.Location.City;
                    allRestaurants.restaurant[i].location.provstate     = restInfo.Location.Province;
                    allRestaurants.restaurant[i].location.postalzipcode = restInfo.Location.PostalCode;

                    saveResult = true;
                }
            }


            XmlSerializer serializor = new XmlSerializer(typeof(restaurants));
            XmlTextWriter tw         = new XmlTextWriter("C:/temp/restaurant_reviews.xml", Encoding.UTF8);

            serializor.Serialize(tw, allRestaurants);
            tw.Close();

            return(saveResult);
        }
Exemplo n.º 8
0
        //Summary
        //Methods retrieves specific restaurant by given id from XML file
        //
        // @param id
        //
        public RestaurantInfo GetRestaurantById(int?id)
        {
            //Check if id is not null
            if (id == null)
            {
                return(null);
            }

            //Get all restaurants from xml file
            restaurant_reviews allRestaurantsFromXml = GetRestaurantsFromXml();
            RestaurantInfo     restaurantInfo        = null;

            if (allRestaurantsFromXml != null)
            {
                foreach (restaurant_reviewsRestaurant r in allRestaurantsFromXml.restaurant)
                {
                    if (r.id == id)
                    {
                        //Initialize Address object to pass it into RestaurantInfo
                        Address restaurantLocation = new Address
                        {
                            City       = r.address.City,
                            PostalCode = r.address.Postal_code,
                            Province   = r.address.Province,
                            Street     = r.address.Street
                        };

                        //Initialize RestaurantInfo object
                        RestaurantInfo restaurant = new RestaurantInfo
                        {
                            Id       = r.id,
                            Name     = r.name,
                            Location = restaurantLocation,
                            Cost     = r.prices.Value,
                            Rating   = r.reviews.review.rating.Value,
                            Summary  = r.reviews.review.summary
                        };
                        restaurantInfo = restaurant;
                    }
                }
                return(restaurantInfo);
            }

            return(null);
        }
Exemplo n.º 9
0
        //Summary
        //Methods saves any changes and updates the xml file
        //
        // @param RestaurantInfo object
        //
        // @return bool
        //
        public bool SaveRestaurant(RestaurantInfo restInfo)
        {
            if (restInfo == null)
            {
                return(false);
            }

            string filePath = HttpContext.Current.Server.MapPath("~/Data/RestaurantReview.xml");

            restaurant_reviews restaurantReviews = null;

            //Read xml file
            using (FileStream file = new FileStream(filePath, FileMode.Open))
            {
                XmlSerializer serializer = new XmlSerializer(typeof(restaurant_reviews));
                restaurantReviews = (restaurant_reviews)serializer.Deserialize(file);
            }

            restaurant_reviewsRestaurant restaurant = restaurantReviews.restaurant[restInfo.Id - 1];

            if (restInfo != null)
            {
                restaurant.id                          = restInfo.Id;
                restaurant.name                        = restInfo.Name;
                restaurant.address.Street              = restInfo.Location.Street;
                restaurant.address.Province            = restInfo.Location.Province;
                restaurant.address.Postal_code         = restInfo.Location.PostalCode;
                restaurant.address.City                = restInfo.Location.City;
                restaurant.prices.Value                = (byte)restInfo.Cost;
                restaurant.reviews.review.rating.Value = (byte)restInfo.Rating;
                restaurant.reviews.review.summary      = restInfo.Summary;

                using (FileStream file = new FileStream(filePath, FileMode.Create))
                {
                    XmlSerializer serializer = new XmlSerializer(typeof(restaurant_reviews));
                    serializer.Serialize(file, restaurantReviews);
                }
            }
            return(true);
        }
Exemplo n.º 10
0
        //Summary
        //Method retrieves specific restaurant by given name
        //
        //@param string
        //
        public RestaurantInfo GetRestaurantByName(string name)
        {
            if (name == null || name == "")
            {
                return(null);
            }

            restaurant_reviews allRestaurantsFromXml = GetRestaurantsFromXml();

            RestaurantInfo restaurant = null;

            foreach (restaurant_reviewsRestaurant r in allRestaurantsFromXml.restaurant)
            {
                if (name == r.name)
                {
                    Address restaurantLocation = new Address
                    {
                        City       = r.address.City,
                        Province   = r.address.Province,
                        PostalCode = r.address.Postal_code,
                        Street     = r.address.Street
                    };

                    RestaurantInfo restaurantInfo = new RestaurantInfo
                    {
                        Id       = r.id,
                        Name     = r.name,
                        Location = restaurantLocation,
                        Cost     = r.prices.Value,
                        Rating   = r.reviews.review.rating.Value,
                        Summary  = r.reviews.review.summary
                    };

                    restaurant = restaurantInfo;
                }
            }

            return(restaurant);
        }
Exemplo n.º 11
0
        public List <RestaurantInfo> GetRestaurantsByRating(int rating)
        // public RestaurantInfo[] GetRestaurantsByRating(int rating)

        {
            restaurants allRestaurants = GetRestaurantsFormXml();


            //RestaurantInfo[]  restaurantsInfo = new RestaurantInfo[2];

            List <RestaurantInfo> restaurantsInfo = new List <RestaurantInfo>();

            for (int i = 0; i < allRestaurants.restaurant.Length; i++)
            {
                if (allRestaurants.restaurant[i].rating >= rating)
                {
                    RestaurantInfo restaurantInfo = new RestaurantInfo();
                    Address        address        = new Address();


                    address.Street = allRestaurants.restaurant[i].location.street.ToString();

                    address.City = allRestaurants.restaurant[i].location.city.ToString();

                    address.Province = allRestaurants.restaurant[i].location.provstate;

                    address.PostalCode = allRestaurants.restaurant[i].location.postalzipcode.ToString();

                    restaurantInfo.Name    = allRestaurants.restaurant[i].name;
                    restaurantInfo.Summary = allRestaurants.restaurant[i].summary.ToString();

                    restaurantInfo.Rating   = allRestaurants.restaurant[i].rating;
                    restaurantInfo.Location = address;

                    restaurantsInfo.Add(restaurantInfo);
                }
            }

            return(restaurantsInfo);
        }
Exemplo n.º 12
0
        public RestaurantInfo GetRestaurantByName(string name)
        {
            restaurants allRestaurants = GetRestaurantsFromXml();

            foreach (restaurant rest in allRestaurants.restaurant)
            {
                if (rest.name == name)
                {
                    RestaurantInfo restInfo = new RestaurantInfo();
                    restInfo.Location = new Address();

                    restInfo.Name                = rest.name;
                    restInfo.Summary             = rest.summary;
                    restInfo.Rating              = rest.rating;
                    restInfo.Location.Street     = rest.location.street;
                    restInfo.Location.City       = rest.location.city;
                    restInfo.Location.Province   = rest.location.provstate;
                    restInfo.Location.PostalCode = rest.location.postalzipcode;
                    return(restInfo);
                }
            }
            return(null);
        }
Exemplo n.º 13
0
        //Summary
        //Method returns a List of restaurants
        public List <RestaurantInfo> GetAllRestaurants()
        {
            //Initialize list of restaurants
            List <RestaurantInfo> restaurants = new List <RestaurantInfo>();
            //Retrive restaurants information from xml file
            restaurant_reviews allRestaurantsFromXml = GetRestaurantsFromXml();


            if (allRestaurantsFromXml != null)
            {
                foreach (restaurant_reviewsRestaurant r in allRestaurantsFromXml.restaurant)
                {
                    //Create new Address object
                    Address restaurantLocation = new Address();
                    restaurantLocation.City       = r.address.City;
                    restaurantLocation.PostalCode = r.address.Postal_code;
                    restaurantLocation.Province   = r.address.Province;
                    restaurantLocation.Street     = r.address.Street;

                    //Create new RestaurantInfo object and pass Address object as a Location
                    RestaurantInfo restaurant = new RestaurantInfo
                    {
                        Id       = r.id,
                        Name     = r.name,
                        Location = restaurantLocation,
                        Cost     = r.prices.Value,
                        Rating   = r.reviews.review.rating.Value,
                        Summary  = r.reviews.review.summary
                    };

                    //Add restaurant to RestaurantInfo List
                    restaurants.Add(restaurant);
                }
            }
            //Return the list
            return(restaurants);
        }