// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, TrainingDBContext context) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } //Add database creation if not exist to request pipeline context.Database.EnsureCreated(); app.UseRouting(); app.UseAuthorization(); app.UseCors(); //Add swagger UI to pipeline and remove the swagger prefix app.UseSwagger(); app.UseSwaggerUI(setupAction => { setupAction.SwaggerEndpoint("/swagger/WDSTrainingAPISpecification/swagger.json", "WDS Training API"); setupAction.RoutePrefix = ""; }); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); }
public Institution GetById(int id) { TrainingDBContext db = new TrainingDBContext(); var institution = db.Institutions.Include(c => c.Trainees).FirstOrDefault(c => c.Id == id); return(institution); }
public List <Trainee> Search(TraineeSearchCriteria criteria) { TrainingDBContext db = new TrainingDBContext(); var traineeList = db.Trainee.AsQueryable(); if (criteria == null) { return(traineeList.ToList()); } if (!String.IsNullOrEmpty(criteria.Name)) { traineeList = traineeList.Where(c => c.Name.StartsWith(criteria.Name)); } if (!String.IsNullOrEmpty(criteria.SEID)) { traineeList = traineeList.Where(c => c.SEID == criteria.SEID); } if (criteria.EnrollFrom != null) { traineeList = traineeList.Where(c => c.EnrollDate >= criteria.EnrollFrom); } if (criteria.EnrollTo != null) { traineeList = traineeList.Where(c => c.EnrollDate <= criteria.EnrollTo); } return(traineeList.ToList()); }
public TrainingDBContext GetInMemoryDbContext() { var options = new DbContextOptionsBuilder <TrainingDBContext>() .UseInMemoryDatabase(databaseName: "InMemoryArticleDatabase") .Options; var dbContext = new TrainingDBContext(options); return(dbContext); }
public bool Add(Trainee trainee) { TrainingDBContext db = new TrainingDBContext(); db.Trainee.Add(trainee); int rowAffeted = db.SaveChanges(); return(rowAffeted > 0); }
public bool Delete(Trainee trainee) { TrainingDBContext db = new TrainingDBContext(); db.Trainee.Attach(trainee); db.Entry(trainee).State = EntityState.Deleted; int rowAffected = db.SaveChanges(); return(rowAffected > 0); }
public static TrainingDBContext GetTrainingDbContext(string dbName) { // Create options for DbContext instance var options = new DbContextOptionsBuilder <TrainingDBContext>() .UseInMemoryDatabase(databaseName: dbName) .Options; // Create instance of DbContext var dbContext = new TrainingDBContext(options); return(dbContext); }
public Institution GetWithExistingTraineeById(int id) { TrainingDBContext db = new TrainingDBContext(); var institution = db.Institutions.FirstOrDefault(c => c.Id == id); db.Entry(institution) .Collection(c => c.Trainees) .Query() .Where(c => c.IsDeleted == false) .Load(); return(institution); }
public IActionResult GetStudentInfo(int id) { var db = new TrainingDBContext(); var student = db.Student.Find(id); var studentVm = new StudentViewModel { }; studentVm = _mapper.Map <StudentViewModel>(student); studentVm.CourseName = db.StudentCourse.AsQueryable() .Include(ops => ops.Course) .Where(course => course.StudentId == id).Select(course => course.Course.Name).FirstOrDefault(); return(Ok(studentVm)); }
public async Task <IActionResult> AddNewStudent([FromBody] Student student) { var db = new TrainingDBContext(); try { await db.AddAsync(student); await db.SaveChangesAsync(); return(Ok(student)); } catch (Exception ex) { return(Json(new { Success = false, Message = ex.Message })); } }
public ExcerciseRepository(TrainingDBContext database) : base(database) { }
public EFUnitOfWork(TrainingDBContext dBContext) { _dBContext = dBContext; }
protected CommonRepository(TrainingDBContext database) { Database = database; }
public KickRepository(TrainingDBContext database) : base(database) { }
public UserEFRepository(TrainingDBContext trainingDBContext) : base(trainingDBContext) { _trainingDBContext = trainingDBContext; }
public RoleRepository(TrainingDBContext database) : base(database) { }
public List <Institution> GetAll() { TrainingDBContext db = new TrainingDBContext(); return(db.Institutions.ToList()); }
public GenericEFRepository(TrainingDBContext trainingDBContext) { _trainingDBContext = trainingDBContext; }
public Trainee GetById(int id) { TrainingDBContext db = new TrainingDBContext(); return(db.Trainee.AsNoTracking().Include(c => c.Institution).FirstOrDefault(c => c.Id == id)); }
public List <Trainee> GetAll() { TrainingDBContext db = new TrainingDBContext(); return(db.Trainee.Include(t => t.Institution).ToList()); }
public StudentXSubjectEFRepository(TrainingDBContext trainingDBContext) : base(trainingDBContext) { _trainingDBContext = trainingDBContext; }
public SensorRepository(TrainingDBContext database) : base(database) { }
public List <Student> GetStudentsList() { var db = new TrainingDBContext(); return(db.Student.ToList()); }
/// <summary> /// Constructor received dependent database context object from IoC container via dependency injection /// </summary> /// <param name="context"></param> public TrainingService(TrainingDBContext context) { _context = context; }
public TrainingsController(ILogger <TrainingsController> logger, TrainingDBContext context) { Logger = logger; _context = context; }