public virtual void Update(BLL.Models.Review r)
        {
            try
            {
                RestaurantRepository  restaurantRepository = new RestaurantRepository();
                BLL.Models.Restaurant rest = restaurantRepository.GetByID(r.RestaurantID);
                if (rest == null)
                {
                    throw new ArgumentException();
                }

                // Conform rating input to rating bounds
                r.FoodRating = r.FoodRating < 0 ? 0 :
                               (r.FoodRating > 5 ? 5 : r.FoodRating);
                r.ServiceRating = r.ServiceRating < 0 ? 0 :
                                  (r.ServiceRating > 5 ? 5 : r.ServiceRating);
                r.PriceRating = r.PriceRating < 0 ? 0 :
                                (r.PriceRating > 5 ? 5 : r.PriceRating);
                r.AtmosphereRating = r.AtmosphereRating < 0 ? 0 :
                                     (r.AtmosphereRating > 5 ? 5 : r.AtmosphereRating);

                crud.Update(ReviewService.LibraryToData(r));
            }
            catch
            {
                throw;
            }
        }
 public virtual void Delete(BLL.Models.Restaurant r)
 {
     try
     {
         crud.Delete(RestaurantService.LibraryToData(r));
     }
     catch
     {
         throw;
     }
 }
Example #3
0
 public static Restaurant Map(BLL.Models.Restaurant source)
 {
     return(new Restaurant()
     {
         Id = source.Id,
         Name = source.Name,
         Rating = source.Rating,
         Address = source.Address,
         Url = source.Url,
         Phone = source.Phone,
         Reviews = source.Reviews != null?Map(source.Reviews).ToList() : null
     });
 }
        public static DL.Restaurant LibraryToData(BLL.Models.Restaurant libModel)
        {
            var dataModel = new DL.Restaurant();

            {
                dataModel.ID          = libModel.ID;
                dataModel.Name        = libModel.Name;
                dataModel.Location    = libModel.Location;
                dataModel.Cuisine     = libModel.Cuisine;
                dataModel.Specialty   = libModel.Specialty;
                dataModel.PhoneNumber = libModel.PhoneNumber;
                dataModel.WebAddress  = libModel.WebAddress;
                dataModel.Type        = libModel.Type;
                dataModel.Hours       = libModel.Hours;
                dataModel.Active      = libModel.Active;
            };
            return(dataModel);
        }
 public ActionResult Create(BLL.Models.Restaurant restaurant)
 {
     try
     {
         if (ModelState.IsValid) // server-side validation
         {
             restaurant.Active = true;
             restaurantRepository.Add(restaurant);
             return(RedirectToAction("Index"));
         }
         else
         {
             return(View(ModelState));
         }
     }
     catch (Exception e)
     {
         log.Error($"[Restaurants Controller] [Create] Exception thrown: {e.Message}");
         return(View());
     }
 }
Example #6
0
        public static BLL.Models.Restaurant DataToLibrary(DL.Restaurant dataModel)
        {
            int           restID = dataModel.ID;
            List <Review> revs   = Review.GetReviewsByRestaurantID(restID);

            var libModel = new BLL.Models.Restaurant()
            {
                ID          = dataModel.ID,
                Name        = dataModel.Name,
                Location    = dataModel.Location,
                Cuisine     = dataModel.Cuisine,
                Specialty   = dataModel.Specialty,
                PhoneNumber = dataModel.PhoneNumber,
                WebAddress  = dataModel.WebAddress,
                Type        = dataModel.Type,
                Hours       = dataModel.Hours,
                Active      = dataModel.Active,
                Reviews     = revs // Eager loading
            };

            return(libModel);
        }
 public virtual void Add(BLL.Models.Restaurant r)
 {
     crud.Add(RestaurantService.LibraryToData(r));
 }