Ejemplo n.º 1
0
        public bool SaveRestaurant(RestaurantInfo restInfo)
        {
            var allRestaurants = GetRestaurantsFromXml();
            var restToUpdate   = allRestaurants.restaurant.Where(res => res.name == restInfo.Name).FirstOrDefault();

            if (restToUpdate != null)
            {
                string xmlFile = HttpContext.Current.Server.MapPath(@"App_Data/restaurant_reviews.xml");
                restToUpdate.summary = restInfo.Summary;

                restToUpdate.rating.Value         = byte.Parse(restInfo.Rating);
                restToUpdate.location.address     = restInfo.Location.Street;
                restToUpdate.location.postal_code = restInfo.Location.PostalCode;
                restToUpdate.location.province    = restInfo.Location.Province;
                restToUpdate.location.city        = restInfo.Location.City;

                using (FileStream xs = new FileStream(xmlFile, FileMode.Create))
                {
                    XmlSerializer serializer = new XmlSerializer(typeof(restaurants));
                    serializer.Serialize(xs, allRestaurants);
                }
                return(true);
            }
            return(false);
        }
Ejemplo n.º 2
0
        public List <RestaurantInfo> GetRestaurantsByRating(int rating)
        {
            var listOfRestaurants = GetRestaurantsFromXml();
            var restaurantInfo    = new List <RestaurantInfo>();

            foreach (var rests in listOfRestaurants.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.location.address,
                            Province   = rests.location.province,
                            City       = rests.location.city,
                            PostalCode = rests.location.postal_code
                        }
                    };
                    restaurantInfo.Add(restInfo);
                }
            }
            ////if there is nothing found, it returns a new restaurantInfo, which is empty
            return(restaurantInfo);
        }