Beispiel #1
0
 public static void Ajouter(Restaurant restaurant)
 {
     try
     {
         using (Context db = new Context())
         {
             db.Restaurants.Add(restaurant);
             db.SaveChanges();
         }
     }
     catch (Exception e)
     {
         throw new Exception("Erreur repository : erreur de creation de restaurant", e);
     }
 }
Beispiel #2
0
        public static void Supprimer(Restaurant restaurant)
        {
            try
            {
                using (Context db = new Context())
                {
                    db.Restaurants.Remove(restaurant);
                    db.SaveChanges();
                }
            }

            catch (Exception e)
            {
                throw new Exception("Erreur repository : erreur de suppression de restaurant", e);
            }
        }
        public void Edit_ShouldReturn400BadRequestWhenModelIsNull()
        {
            var context = new RestaurantsContext();
            var newTown = new Town()
            {
                Name = "New town"
            };

            context.Towns.Add(newTown);
            context.SaveChanges();

            var newRestaurant = new Restaurant()
            {
                Name = "New restaurant",
                TownId = newTown.Id
            };

            context.Restaurants.Add(newRestaurant);
            context.SaveChanges();

            var newMeal = new Meal()
            {
                Name = "New meal",
                Price = 4.99M,
                RestaurantId = newRestaurant.Id,
                TypeId = 3
            };

            context.Meals.Add(newMeal);
            context.SaveChanges();

            var content = new FormUrlEncodedContent(new[]
            {
                new KeyValuePair<string, string>("name", "aaaaa")
            });

            var response = httpClient.PutAsync(string.Format("api/meals/{0}", newMeal.Id), content).Result;

            Assert.AreEqual(HttpStatusCode.BadRequest, response.StatusCode);
        }
        private void SeedRestaurant(LoginData loginData)
        {
            using (var context = new RestaurantsContext())
            {
                var newRestaurant = new Restaurant()
                {
                    Name = "New restaurant",
                    TownId = townId,
                    OwnerId = context.Users.FirstOrDefault(u => u.UserName == loginData.Username).Id
                };

                context.Restaurants.Add(newRestaurant);
                context.SaveChanges();

                this.restaurantId = newRestaurant.Id;
            }
        }
 private void LoadCurrentRestaurant()
 {
     Current = new Restaurant
     {
         Name = "Burger Restaurant",
         Address = "803 Taylor Ave S (at Moi St)",
         Category = "American",
         Image = "BurgerRestaurant",
         Position = 1,
         GeoLocation = new Geopoint(new BasicGeoposition()
         {
             // Seattle 
             Latitude = 47.604,
             Longitude = -122.329
         }),
         Checkin = new Checkin
         {
             Today = 12,
             Total = 1128
         },
         Reviews = LoadReviews(),
         Images = LoadImages()
     };
 }