Exemple #1
0
        public PrisonService(ILogger <GreeterService> logger, IConfiguration config, PrisonDbContext dbContext)
        {
            this.logger = logger;
            this.config = config;

            unitOfWork = new UnitOfWork(dbContext);
        }
 public async Task <IActionResult> GetCourse()
 {
     using (var context = new PrisonDbContext())
     {
         return(Ok(await context.Cells.ToListAsync()));
     }
 }
 public async Task <IActionResult> CreateCourse([FromBody] Cell Cell)
 {
     using (var context = new PrisonDbContext())
     {
         context.Cells.Add(Cell);
         await context.SaveChangesAsync();
     }
     return(Ok());
 }
Exemple #4
0
        public async Task <IActionResult> UpdateStudent([FromBody] Prisoner prisoner)
        {
            using (var context = new PrisonDbContext())
            {
                context.Prisoners.Update(prisoner);
                await context.SaveChangesAsync();

                return(Ok());
            }
        }
        public async Task <IActionResult> UpdateCell([FromBody] Cell cell)
        {
            using (var context = new PrisonDbContext())
            {
                context.Cells.Update(cell);
                await context.SaveChangesAsync();

                return(Ok());
            }
        }
Exemple #6
0
        public async Task <IActionResult> DeletePrisoner([FromQuery] int id)
        {
            using (var context = new PrisonDbContext())
            {
                var prisoner = await context.Prisoners.FirstOrDefaultAsync(x => x.Id == id);

                context.Prisoners.Remove(prisoner);
                await context.SaveChangesAsync();

                return(Ok());
            }
        }
Exemple #7
0
 public IActionResult SetupDatabase()
 {
     lock (setupLock)
     {
         using (var context = new PrisonDbContext())
         {
             // Create database
             context.Database.EnsureCreated();
         }
         return(Ok("database created"));
     }
 }
Exemple #8
0
        public async Task <IActionResult> GetPrisoners()
        {
            try
            {
                await parallelism.WaitAsync();

                using (var context = new PrisonDbContext())
                {
                    return(Ok(await context.Prisoners.ToListAsync()));
                }
            }
            finally
            {
                parallelism.Release();
            }
        }
Exemple #9
0
        static void Main(string[] args)
        {
            using (var context = new PrisonDbContext())

            {
                context.Database.EnsureCreated();
            }
            var host = new WebHostBuilder()
                       .UseKestrel()
                       .UseStartup <Startup>()
                       .Build();

            Task restService = host.RunAsync();

            //System.Diagnostics.Process.Start("chrome.exe", "http://localhost/netcoreapp2.0/corsoing/");
            //System.Diagnostics.Process.Start("cmd", "/C start http://localhost/netcoreapp2.0/corsoing/");
            restService.Wait();
        }
 public UnitOfWork(PrisonDbContext context)
 {
     this.context = context;
 }
Exemple #11
0
 public GenericRepo(PrisonDbContext context)
 {
     this.context = context;
     set          = context.Set <T>();
 }