Ejemplo n.º 1
0
 public static void Initialize(PresidentContext context)
 {
     try
     {
         var presidents = context.PresidentInfo.ToList();
         presidents.Add(new Domain.PresidentInfo
         {
             Birthday      = new DateTime(1732, 2, 22),
             Birthplace    = "Westmoreland Co., Va.",
             Deathday      = new DateTime(1979, 12, 14),
             Deathplace    = "Mount Vernon, Va.",
             PresidentName = "George Washington"
         });
         presidents.Add(new Domain.PresidentInfo
         {
             Birthday      = new DateTime(1735, 10, 30),
             Birthplace    = "Quincy, Mass.",
             Deathday      = new DateTime(1826, 7, 4),
             Deathplace    = "Quincy, Mass.",
             PresidentName = "John Adams"
         });
         context.PresidentInfo.AddRange(presidents);
         context.SaveChanges();
     }
     catch (Exception)
     {
     }
 }
 public IEnumerable <President> GetPresidentsFromDb(bool?asc)
 {
     using (var db = new PresidentContext())
     {
         if (asc.HasValue)
         {
             if (asc.Value)
             {
                 var query = from president in db.Presidents
                             orderby president.PresidentName ascending
                             select president;
                 return(query.ToList());
             }
             else
             {
                 var query = from president in db.Presidents
                             orderby president.PresidentName descending
                             select president;
                 return(query.ToList());
             }
         }
         else
         {
             var query = from president in db.Presidents
                         select president;
             return(query.ToList());
         }
     }
 }
Ejemplo n.º 3
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, PresidentContext context)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseCors("miPolitica");
            app.UseMvc();
            context.Database.EnsureCreated();
            DBInitializer.Initialize(context);
        }
Ejemplo n.º 4
0
 public PresidentRepository(DbContext context)
 {
     _context = (PresidentContext)context;
 }
Ejemplo n.º 5
0
 public PresidentService(PresidentContext context)
 {
     _repository = new PresidentRepository(context);
 }
Ejemplo n.º 6
0
 public PresidentRepository(PresidentContext context)
 {
     _presidentContext = context;
 }