Beispiel #1
0
        // Getting the information for the restaurant from the list by rating
        public List <RestaurantInfo> GetRestaurantsByRating(int rating)
        {
            var restaurantListXML  = GetRestaurantsFromXml();
            var restaurantInfoList = new List <RestaurantInfo>();

            foreach (var rests in restaurantListXML.restaurant)
            {
                if (rests.rating.Value < rating)
                {
                    var restInfo = new RestaurantInfo
                    {
                        Name     = rests.name,
                        Rating   = rests.rating.Value.ToString(),
                        Summary  = rests.summary,
                        Location = new Address
                        {
                            Street     = rests.address.street,
                            Province   = rests.address.province,
                            City       = rests.address.city,
                            PostalCode = rests.address.postalCode
                        }
                    };
                    restaurantInfoList.Add(restInfo);
                }
            }
            //if there is nothing found, it returns an empty restinfo
            return(restaurantInfoList);
        }
Beispiel #2
0
        // Getting the information for the restaurant from the list by name
        public RestaurantInfo GetRestaurantByName(string name)
        {
            var restaurantList = GetRestaurantsFromXml();

            foreach (var rests in restaurantList.restaurant)
            {
                if (rests.name == name)
                {
                    var restInfo = new RestaurantInfo
                    {
                        Name     = rests.name,
                        Rating   = rests.rating.Value.ToString(),
                        Summary  = rests.summary,
                        Location = new Address
                        {
                            Street     = rests.address.street,
                            Province   = rests.address.province,
                            City       = rests.address.city,
                            PostalCode = rests.address.postalCode
                        }
                    };
                    return(restInfo);
                }
            }
            //if there is nothing found, it returns an empty restinfo
            return(new RestaurantInfo());
        }
Beispiel #3
0
        // saving restaurant info into XML
        public bool SaveRestaurant(RestaurantInfo restInfo)
        {
            var restaurantListXML  = GetRestaurantsFromXml();
            var selectedRestaurant = restaurantListXML.restaurant.Where(res => res.name == restInfo.Name).FirstOrDefault();

            if (selectedRestaurant != null)
            {
                string xmlFile = HttpContext.Current.Server.MapPath(@"App_Data/restaurant_reviews.xml");
                selectedRestaurant.summary      = restInfo.Summary;
                selectedRestaurant.rating.Value = byte.Parse(restInfo.Rating);
                using (FileStream xs = new FileStream(xmlFile, FileMode.Create))
                {
                    XmlSerializer serializer = new XmlSerializer(typeof(restaurants));
                    serializer.Serialize(xs, restaurantListXML);
                }
                return(true);
            }
            return(false);
        }