Exemplo n.º 1
0
        private static Guid PersistToDatabase(RegisterRestoCommand command, Coordinates coordinates)
        {
            using (var ctx = new RestoContext())
            {
                var restaurant = ctx.Restaurants.Add(new Restaurant()
                {
                    Id            = Guid.NewGuid(),
                    Locality      = command.City,
                    StreetAddress = command.Street,
                    Name          = command.Name
                });

                if (coordinates != null)
                {
                    restaurant.Latitude  = coordinates.Latitude;
                    restaurant.Longitude = coordinates.Longitude;
                }

                if (!String.IsNullOrEmpty(command.Region))
                {
                    restaurant.RegionId = int.Parse(command.Region);
                }

                if (!String.IsNullOrEmpty(command.Cuisine))
                {
                    restaurant.Cuisines = new Collection <RestaurantCuisine>
                    {
                        new RestaurantCuisine
                        {
                            Id        = Guid.NewGuid(),
                            CuisineId = int.Parse(command.Cuisine)
                        }
                    };
                }

                if (command.SelectedAccommodationIds != null)
                {
                    restaurant.Accommodations = new Collection <RestaurantAccommodation>();

                    foreach (var accommodation in command.SelectedAccommodationIds)
                    {
                        restaurant.Accommodations.Add(new RestaurantAccommodation
                        {
                            Id = Guid.NewGuid(),
                            AccommodationId = accommodation
                        });
                    }
                }

                ctx.SaveChanges();

                Console.WriteLine("Persisted to DB.");

                return(restaurant.Id);
            }
        }
Exemplo n.º 2
0
 public int Persist()
 {
     return(_restoContext.SaveChanges());
 }