Example #1
0
 public Student GetStudent(int id)
 {
     using (var ctx = new ArgonDbContext(_connectionStringWrapper))
     {
         return(ctx.Students.FirstOrDefault(q => q.Id == id));
     }
 }
Example #2
0
 public ICollection <Student> GetStudents()
 {
     using (var ctx = new ArgonDbContext(_connectionStringWrapper))
     {
         var queryable = ctx.Students.AsQueryable();
         return(queryable.ToList());
     }
 }
Example #3
0
 public void RegisterStudent(Student student)
 {
     using (var ctx = new ArgonDbContext(_connectionStringWrapper))
     {
         ctx.Students.Add(student);
         ctx.SaveChanges();
     }
 }
Example #4
0
 public void UnregisterStudent(int id)
 {
     using (var ctx = new ArgonDbContext(_connectionStringWrapper))
     {
         var student = GetStudent(id);
         if (student == null)
         {
             throw new ArgumentException($"Student {id} does not exist.");
         }
         ctx.Students.Remove(student);
         ctx.SaveChanges();
     }
 }
Example #5
0
 public void Update(int id, Student student)
 {
     using (var ctx = new ArgonDbContext(_connectionStringWrapper))
     {
         var entity = ctx.Students.FirstOrDefault(q => q.Id == id);
         if (entity == null)
         {
             throw new ArgumentException($"Student {id} does not exist.");
         }
         entity.Name    = student.Name;
         entity.Surname = student.Surname;
         ctx.Students.Update(entity);
         ctx.SaveChanges();
     }
 }
Example #6
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ArgonDbContext argonDbContext)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseMvc();
            app.UseSwagger();
            app.UseSwaggerUI(c =>
            {
                c.SwaggerEndpoint("/swagger/v1/swagger.json", "Argon API");
            });

            argonDbContext.Database.EnsureCreated();
        }