Ejemplo n.º 1
0
 public void SavePlace(Place place)
 {
     if (place.Id == 0)
     {
         context.Places.Add(place);
     }
     else
     {
         Place dbEntry = context.Places
                         .FirstOrDefault(p => p.Id == place.Id);
         if (dbEntry != null)
         {
             dbEntry.Name    = place.Name;
             dbEntry.Lat     = place.Lat;
             dbEntry.Lng     = place.Lng;
             dbEntry.Address = place.Address;
             dbEntry.City    = place.City;
             dbEntry.Country = place.Country;
             dbEntry.PlaceId = place.PlaceId;
             dbEntry.Rating  = place.Rating;
             dbEntry.Site    = place.Site;
             dbEntry.State   = place.State;
             dbEntry.Street  = place.Street;
             dbEntry.Type    = place.Type;
             dbEntry.UserId  = place.UserId;
         }
     }
     context.SaveChanges();
 }
Ejemplo n.º 2
0
        public static void EnsurePopulated(IApplicationBuilder app)
        {
            MapContext context = app.ApplicationServices.GetRequiredService <MapContext>();

            context.Database.Migrate();
            if (!context.Places.Any())
            {
                context.Places.AddRange(
                    new Place {
                    Name = "Place1"
                },
                    new Place {
                    Name = "Place2"
                },
                    new Place {
                    Name = "Place3"
                }
                    );
                context.SaveChanges();
            }
            if (!context.Users.Any())
            {
                context.Users.AddRange(
                    new User {
                    Name = "User1"
                },
                    new User {
                    Name = "User2"
                },
                    new User {
                    Name = "User2"
                }
                    );
                context.SaveChanges();
            }
        }