Example #1
0
        // 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();
            });
        }
Example #2
0
        public Institution GetById(int id)
        {
            TrainingDBContext db = new TrainingDBContext();
            var institution      = db.Institutions.Include(c => c.Trainees).FirstOrDefault(c => c.Id == id);

            return(institution);
        }
Example #3
0
        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());
        }
Example #4
0
        public TrainingDBContext GetInMemoryDbContext()
        {
            var options = new DbContextOptionsBuilder <TrainingDBContext>()
                          .UseInMemoryDatabase(databaseName: "InMemoryArticleDatabase")
                          .Options;
            var dbContext = new TrainingDBContext(options);

            return(dbContext);
        }
Example #5
0
        public bool Add(Trainee trainee)
        {
            TrainingDBContext db = new TrainingDBContext();

            db.Trainee.Add(trainee);

            int rowAffeted = db.SaveChanges();

            return(rowAffeted > 0);
        }
Example #6
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);
        }
Example #7
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);
        }
Example #8
0
        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);
        }
Example #9
0
        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));
        }
Example #10
0
        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)
 {
 }
Example #12
0
 public EFUnitOfWork(TrainingDBContext dBContext)
 {
     _dBContext = dBContext;
 }
Example #13
0
 protected CommonRepository(TrainingDBContext database)
 {
     Database = database;
 }
Example #14
0
 public KickRepository(TrainingDBContext database) : base(database)
 {
 }
 public UserEFRepository(TrainingDBContext trainingDBContext) : base(trainingDBContext)
 {
     _trainingDBContext = trainingDBContext;
 }
 public RoleRepository(TrainingDBContext database) : base(database)
 {
 }
Example #17
0
        public List <Institution> GetAll()
        {
            TrainingDBContext db = new TrainingDBContext();

            return(db.Institutions.ToList());
        }
 public GenericEFRepository(TrainingDBContext trainingDBContext)
 {
     _trainingDBContext = trainingDBContext;
 }
Example #19
0
        public Trainee GetById(int id)
        {
            TrainingDBContext db = new TrainingDBContext();

            return(db.Trainee.AsNoTracking().Include(c => c.Institution).FirstOrDefault(c => c.Id == id));
        }
Example #20
0
        public List <Trainee> GetAll()
        {
            TrainingDBContext db = new TrainingDBContext();

            return(db.Trainee.Include(t => t.Institution).ToList());
        }
Example #21
0
 public StudentXSubjectEFRepository(TrainingDBContext trainingDBContext) : base(trainingDBContext)
 {
     _trainingDBContext = trainingDBContext;
 }
Example #22
0
 public SensorRepository(TrainingDBContext database) : base(database)
 {
 }
Example #23
0
        public List <Student> GetStudentsList()
        {
            var db = new TrainingDBContext();

            return(db.Student.ToList());
        }
Example #24
0
 /// <summary>
 /// Constructor received dependent database context object from IoC container via dependency injection
 /// </summary>
 /// <param name="context"></param>
 public TrainingService(TrainingDBContext context)
 {
     _context = context;
 }
Example #25
0
 public TrainingsController(ILogger <TrainingsController> logger, TrainingDBContext context)
 {
     Logger   = logger;
     _context = context;
 }