コード例 #1
0
ファイル: Mapper.cs プロジェクト: nicolassargos/EatB
 /// <summary>
 /// RestaurantModel to kitchenType
 /// </summary>
 /// <param name="restaurant"></param>
 /// <returns></returns>
 public static IEnumerable <Kitchen> ConvertModelToKitchen(this NewRestaurantModel restaurant, int restaurantID)
 {
     return(restaurant.kitchenTypes.Select(k => new Kitchen()
     {
         KitchenTypeID = k, RestaurantID = restaurantID
     }));
 }
コード例 #2
0
ファイル: Mapper.cs プロジェクト: nicolassargos/EatB
 /// <summary>
 /// RestaurantModel to Image
 /// </summary>
 /// <param name="restaurant"></param>
 /// <returns></returns>
 public static IEnumerable <Image> ConvertModelToImages(this NewRestaurantModel restaurant, int restaurantID)
 {
     return(restaurant.images.Select(i => new Image()
     {
         ImageUrl = i, RestaurantID = restaurantID
     }));
 }
コード例 #3
0
        public async Task <IHttpActionResult> PostRestaurant(NewRestaurantModel restaurant)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            // Ajoute le restaurant
            db.Restaurants.Add(restaurant.ConvertModelToRestaurant());
            db.SaveChanges();

            var newRestaurant = db.Restaurants.FirstOrDefault(x => x.Name == restaurant.name);

            // Ajoute les images correspondantes
            if (restaurant.images != null && restaurant.images.Count() > 0)
            {
                foreach (var img in restaurant.ConvertModelToImages(newRestaurant.RestaurantID))
                {
                    db.Images.Add(img);
                }
            }

            // Ajoute les kitchenTypes
            if (restaurant.kitchenTypes != null && restaurant.kitchenTypes.Count() > 0)
            {
                foreach (var kt in restaurant.ConvertModelToKitchen(newRestaurant.RestaurantID))
                {
                    db.Kitchens.Add(kt);
                }
            }

            await db.SaveChangesAsync();

            return(CreatedAtRoute("DefaultApi", new { id = newRestaurant.RestaurantID }, newRestaurant));
        }
コード例 #4
0
ファイル: Mapper.cs プロジェクト: nicolassargos/EatB
 /// <summary>
 /// RestaurantModel to Restaurant
 /// </summary>
 /// <param name="restaurantModel"></param>
 /// <returns></returns>
 public static Restaurant ConvertModelToRestaurant(this NewRestaurantModel restaurantModel)
 {
     return(new Restaurant()
     {
         RestaurantID = restaurantModel.restaurantID,
         Name = restaurantModel.name,
         Address = restaurantModel.address,
         ZipCode = restaurantModel.zipCode,
         OpeningHour = restaurantModel.openingHour,
         ClosingHour = restaurantModel.closingHour,
         Description = restaurantModel.description
     });
 }