Esempio n. 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="newStudent"></param>
        /// <param name="enrollment"></param>
        public void SetAsEnroll(Model.NewStudent newStudent, Model.Enrollment enrollment)
        {
            enrollment.NewStudentId   = newStudent.NewStudentId;
            enrollment.EnrollmentTime = DateTime.Now;
            newStudent.sfbd           = 1;

            using (MyDbContext dbContext = new MyDbContext())
            {
                using (IDbContextTransaction trans = dbContext.Database.BeginTransaction())
                {
                    try
                    {
                        dbContext.Set <Model.Enrollment>().Add(enrollment);
                        dbContext.Set <Model.NewStudent>().Update(newStudent);
                        dbContext.SaveChanges();

                        trans.Commit();
                    }
                    catch (Exception ex)
                    {
                        trans.Rollback();
                        throw (ex);
                    }
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="newStudent"></param>
        public void SetAsNotEnroll(Model.NewStudent newStudent)
        {
            using (MyDbContext dbContext = new MyDbContext())
            {
                Model.Enrollment enrollment = dbContext.Set <Model.Enrollment>().Single(x => x.EnrollmentId == newStudent.NewStudentId);

                if (enrollment != null)
                {
                    dbContext.Set <Model.Enrollment>().Remove(enrollment);
                    dbContext.SaveChanges();
                }
            }
        }
Esempio n. 3
0
            public async Task <Model> Handle(Query message, CancellationToken token)
            {
                var instructors = await _db.Instructors
                                  .Include(i => i.CourseAssignments)
                                  .ThenInclude(c => c.Course)
                                  .OrderBy(i => i.LastName)
                                  .ProjectTo <Model.Instructor>(_configuration)
                                  .ToArrayAsync(token);

                Model.Course[]     courses;
                Model.Enrollment[] enrollments;

                if (message.Id != null)
                {
                    courses = await _db.CourseAssignments
                              .Where(ci => ci.InstructorId == message.Id)
                              .Select(ci => ci.Course)
                              .ProjectTo <Model.Course>(_configuration)
                              .ToArrayAsync(token);
                }
                else
                {
                    courses = new Model.Course[0];
                }

                if (message.CourseId != null)
                {
                    enrollments = await _db.Enrollments
                                  .Where(x => x.CourseId == message.CourseId)
                                  .ProjectTo <Model.Enrollment>(_configuration)
                                  .ToArrayAsync(token);
                }
                else
                {
                    enrollments = new Model.Enrollment[0];
                }

                var viewModel = new Model
                {
                    Instructors  = instructors,
                    Courses      = courses,
                    Enrollments  = enrollments,
                    InstructorId = message.Id,
                    CourseId     = message.CourseId
                };

                return(viewModel);
            }