public RestaurantModel Create(Restaurant restaurant)
 {
     return new RestaurantModel()
         {
             //Url = RestaurantUrl(restaurant),
             ID = restaurant.ID,
             Name = restaurant.Name,
             Created = restaurant.AddDate,
             Address = restaurant.Address,
             ImgUrl = "../../Content/images/restaurant.jpg",
             Reviews = restaurant.Reviews.Select(rr => _reviewModelFactory.Create(rr))
         };
 }
Example #2
0
 public RestaurantModel Create(Restaurant restaurant)
 {
     return new RestaurantModel()
     {
         Url = ControllerUrl(restaurant),
         Links =
         new List<LinkModel>()
             {
                 //v1
                 //CreateLink(_urlHelper.Link("Restaurants", new { restaurantid = restaurant.ID }),"self"),
                 //v2
                 CreateLink(_urlHelper.Link("Restaurant", new { restaurantid = restaurant.ID }),"self"),
                 CreateLink(_urlHelper.Link("Reviews", new { restaurantid = restaurant.ID }), "newReviewEntry", "POST")
             },
         ID = restaurant.ID,
         Name = restaurant.Name,
         Created = restaurant.AddDate,
         Address = restaurant.Address,
         ImgUrl = "../../Content/images/restaurant.jpg",
         Reviews = restaurant.Reviews.Select(rr => Create(rr))
     };
 }
 private string RestaurantUrl(Restaurant restaurant)
 {
     return _urlHelper.Link("Restaurants", new { restaurantid = restaurant.ID });
 }
Example #4
0
 private string ControllerUrl(Restaurant restaurant)
 {
     //v1
     //return _urlHelper.Link("Restaurants", new { restaurantid = restaurant.ID });
     //v2
     return _urlHelper.Link("Restaurant", new { restaurantid = restaurant.ID });
 }
Example #5
0
        public Restaurant Parse(RestaurantModel model)
        {
            try
            {
                var entry = new Restaurant();

                var selfLink = model.Links.Where(l => l.Rel == "self").FirstOrDefault();

                //if (!string.IsNullOrWhiteSpace(model.Url))
                if(selfLink !=null && !string.IsNullOrWhiteSpace(selfLink.Href))
                {
                    //var uri = new Uri(model.Url);
                    var uri = new Uri(selfLink.Href);
                    entry.ID = int.Parse(uri.Segments.Last());
                }

                if (model.ID != default(int))
                {
                    entry.ID = model.ID;
                }

                if (!string.IsNullOrEmpty(model.Name))
                {
                    entry.Name = model.Name;
                }
                entry.ImageUrl = model.ImgUrl;
                entry.Address = model.Address;

                return entry;
            }
            catch
            {
                return null;
            }
        }