Пример #1
0
 public IJourney Single(int Id)
 {
     using (MilesDb db = new MilesDb())
     {
         return(MapFromDto(db.Journeys.Single(s => s.Id == Id)));
     }
 }
Пример #2
0
 public void Dispose()
 {
     using (MilesDb db = new MilesDb())
     {
         db.Dispose();
     }
 }
Пример #3
0
        // private MilesDb db = new MilesDb();

        public IEnumerable <IJourney> All()
        {
            using (MilesDb db = new MilesDb())
            {
                /*
                 * var items = db.Journeys.Include(l => l.StartLocation).Include(l => l.EndLocation);
                 *
                 * var s = items.ToString();
                 * foreach (var i in items)
                 * {
                 *  var x = MapFromDto(i);
                 * }
                 * return null;
                 */

                var list = new List <IJourney>();

                var items = db.Journeys.Include(l => l.StartLocation).Include(l => l.EndLocation);

                foreach (var i in items)
                {
                    var toAdd = MapFromDto(i);
                    list.Add(toAdd);
                }

                return(list);
            }
        }
Пример #4
0
 public void Add(IJourney entity)
 {
     using (MilesDb db = new MilesDb())
     {
         var dto = MapToDto(entity);
         db.Journeys.Add(dto);
         db.SaveChanges();
         //db.Entry(dto).State = EntityState.Detached;
     }
 }
Пример #5
0
 public void Delete(int Id)
 {
     using (MilesDb db = new MilesDb())
     {
         var exiting = db.Journeys.Single(s => s.Id == Id);
         if (exiting != null)
         {
             db.Journeys.Remove(exiting);
             db.SaveChanges();
         }
     }
 }
Пример #6
0
 public void Update(IJourney entity)
 {
     using (MilesDb db = new MilesDb())
     {
         var newValues = MapToDto(entity);
         var exiting   = db.Journeys.Single(s => s.Id == newValues.Id);
         if (exiting != null)
         {
             db.Journeys.Update(newValues);
             db.SaveChanges();
         }
     }
 }
Пример #7
0
        public Dto.Journey MapToDto(IJourney journey)
        {
            using (MilesDb db = new MilesDb())
            {
                var dto = new Dto.Journey
                {
                    Id            = journey.Id,
                    Distance      = journey.Distance,
                    StartLocation = LocationRepo.MapToDto(journey.StartLocation),
                    EndLocation   = LocationRepo.MapToDto(journey.EndLocation)
                };

                return(dto);
            }
        }
Пример #8
0
        public Startup(IHostingEnvironment env)
        {
            // Set up configuration sources.
            var builder = new ConfigurationBuilder()
                          .AddJsonFile("appsettings.json");

            if (env.IsEnvironment("Development"))
            {
                // This will push telemetry data through Application Insights pipeline faster, allowing you to view results immediately.
                builder.AddApplicationInsightsSettings(developerMode: true);
            }

            builder.AddEnvironmentVariables();
            Configuration = builder.Build().ReloadOnChanged("appsettings.json");

            using (var db = new MilesDb())
            {
                db.Database.EnsureCreated();
            }
        }