示例#1
0
        public IHttpActionResult PutRestaurant(RestaurantsModify restaurantsMod)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            if (!db.Restaurants.Any(x => x.IdRestaurant == restaurantsMod.IdRestaurant))
            {
                return(BadRequest());
            }
            int            cuisineTypeId = db.CuisineTypes.Where(x => x.Name == restaurantsMod.CuisineType).First().IdCuisine;
            RestaurantsObj restoModify   = db.Restaurants.Where(x => x.IdRestaurant == restaurantsMod.IdRestaurant).First();

            restoModify.Name         = restaurantsMod.Name;
            restoModify.Adress       = restaurantsMod.Adress;
            restoModify.PostalCode   = restaurantsMod.PostalCode;
            restoModify.Phone        = restaurantsMod.Phone;
            restoModify.IdCuisine    = cuisineTypeId;
            restoModify.urlThumbnail = restaurantsMod.urlThumbnail;
            restoModify.City         = restaurantsMod.City;
            db.SaveChanges();
            RestaurantsObj finalResto = db.Restaurants.Where(x => x.IdRestaurant == restaurantsMod.IdRestaurant).First();

            return(Ok(TransformObject.TransformRestoObjIntoRestoViewDetails(finalResto, db)));
        }
示例#2
0
        public IHttpActionResult PostRestaurant(RestaurantsCreate restaurantsC)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            int nb = 0;

            nb = db.CuisineTypes.Where(x => x.Name == restaurantsC.CuisineType).Count();
            if (nb == 0)
            {
                CuisineTypeObj newCui = new CuisineTypeObj
                {
                    Name = restaurantsC.CuisineType
                };
                db.CuisineTypes.Add(newCui);
                db.SaveChanges();
            }
            int            idCuisineType = db.CuisineTypes.Where(x => x.Name == restaurantsC.CuisineType).First().IdCuisine;
            RestaurantsObj newResto      = new RestaurantsObj
            {
                Adress       = restaurantsC.Adress,
                City         = restaurantsC.City,
                IdCuisine    = idCuisineType,
                Name         = restaurantsC.Name,
                Phone        = restaurantsC.Phone,
                PostalCode   = restaurantsC.PostalCode,
                Rating       = 10,
                urlThumbnail = restaurantsC.urlThumbnail
            };

            db.Restaurants.Add(newResto);
            db.SaveChanges();
            int idresto = db.Restaurants.Where(x => x.Name == restaurantsC.Name).First().IdRestaurant;

            foreach (var item in restaurantsC.Plats)
            {
                DishesObj dishe = new DishesObj
                {
                    Name         = item.Name,
                    Price        = item.Price,
                    Pde          = "a",
                    IdRestaurant = idresto
                };

                db.Dishes.Add(dishe);
                db.SaveChanges();
            }
            return(Ok(TransformObject.TransformRestoObjIntoRestoViewDetails(newResto, db)));
        }
示例#3
0
        public RestaurantsViewDetails GetRestaurantDetails(int id)
        {
            RestaurantsObj resto = db.Restaurants.Where(x => x.IdRestaurant == id).First();

            return(TransformObject.TransformRestoObjIntoRestoViewDetails(resto, db));
        }