public FormController(IPostalCodeProviderService postalCodeProviderService, EducationContext educationContext, ILocalizationManager localizationManager)
        {
            this._postalCodeProviderService = postalCodeProviderService;
            this._educationContext          = educationContext;

            this._localizationManager = localizationManager;
        }
Exemple #2
0
        public ActionResult Login(LoginViewModel viewModel)
        {
            try
            {
                using (var context = new EducationContext())
                {
                    if (!ModelState.IsValid)
                    {
                        return(View(viewModel));
                    }

                    var user = context.Users.FirstOrDefault(x => x.UserName.Trim().ToLower() == viewModel.UserName.Trim().ToLower() && x.Password.Trim().ToLower() == viewModel.Password.Trim().ToLower());
                    if (user != null)
                    {
                        FormsAuthentication.SetAuthCookie(user.UserName, true);
                        Session["LoginUser"] = viewModel;
                        return(RedirectToAction("Index", "Education"));
                    }
                    else
                    {
                        ModelState.AddModelError("Error", "Kullanıcı adı veya parola hatalı");
                    }
                }
                return(View(viewModel));
            }
            catch (Exception exception)
            {
                throw new Exception(exception.Message);
            }
        }
Exemple #3
0
 public ActionResult Update(int studentId)
 {
     try
     {
         using (var context = new EducationContext())
         {
             TempData["studentClasses"] = context.Classes.ToList();
             var student = context.Students.FirstOrDefault(s => s.Id == studentId);
             if (student == null)
             {
                 return(View("Error"));
             }
             var model = new StudentViewModel()
             {
                 PhoneNumber    = student.PhoneNumber,
                 ClassId        = student.ClassId,
                 IdentityNumber = student.IdentityNumber,
                 LastName       = student.LastName,
                 Name           = student.Name,
                 SchoolNumber   = student.SchoolNumber,
                 Id             = student.Id,
                 Age            = student.Age,
                 Email          = student.Email
             };
             return(View(model));
         }
     }
     catch
     {
         return(View("Error"));
     }
 }
Exemple #4
0
        public ActionResult Update(StudentViewModel viewModel)
        {
            try
            {
                using (var context = new EducationContext())
                {
                    if (!ModelState.IsValid)
                    {
                        return(View(viewModel));
                    }

                    var student = context.Students?.FirstOrDefault(s => s.Id == viewModel.Id && s.IsDeleted == false);
                    if (student == null)
                    {
                        return(View("Error"));
                    }

                    student.PhoneNumber    = viewModel.PhoneNumber;
                    student.ClassId        = viewModel.ClassId;
                    student.IdentityNumber = viewModel.IdentityNumber;
                    student.LastName       = viewModel.LastName;
                    student.Name           = viewModel.Name;
                    student.SchoolNumber   = viewModel.SchoolNumber;
                    student.Id             = viewModel.Id;
                    student.Email          = viewModel.Email; student.Age = viewModel.Age;
                    context.SaveChanges();
                    return(RedirectToAction("Index", "Education"));
                }
            }
            catch
            {
                return(View("Error"));
            }
        }
Exemple #5
0
        public EducationVO FindEducationById(int id, EducationContext ctx)
        {
            EducationVO model = new EducationVO();

            try
            {
                var query = (from edu in ctx.Educations.AsEnumerable()
                             where edu.Id == id
                             select new EducationVO
                {
                    Id = edu.Id,
                    MemberId = edu.MemberId,
                    Degree = edu.Degree,
                    School = edu.School,
                    Department = edu.Department,
                    StartYear = edu.StartYear,
                    GraduationYear = edu.GraduationYear,
                    Grade = edu.Grade
                }).Single();

                model.Id             = FillItemForDatabase.FillItem(query.Id);
                model.MemberId       = FillItemForDatabase.FillItem(query.MemberId);
                model.Degree         = FillItemForDatabase.FillItem(query.Degree);
                model.School         = FillItemForDatabase.FillItem(query.School);
                model.Department     = FillItemForDatabase.FillItem(query.Department);
                model.StartYear      = FillItemForDatabase.FillItem(query.StartYear);
                model.GraduationYear = FillItemForDatabase.FillItem(query.GraduationYear);
                model.Grade          = FillItemForDatabase.FillItem(query.Grade);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(model);
        }
        private static async Task InsertOrUpdateStudent(EducationContext _context, IPostalCodeProviderService service, FormSubmitRequest request, CancellationToken cancellationToken)
        {
            var country = await _context.Countries.Where(x => x.Code == "GR").SingleAsync(cancellationToken);

            var student = await _context.Students
                          .Where(x => x.RegistrationId == request.StudentId)
                          .FirstOrDefaultAsync(cancellationToken);

            if (student == null)
            {
                _context.Students.Add(student = new Student
                {
                    RegistrationId = request.StudentId
                });
            }

            var postalCode = await service.GetPostalCodeAsync(request.PostalCode, cancellationToken);

            student.Gender       = Enum.TryParse(request.Gender, out Gender _gender) ? _gender : Gender.Unspecified;
            student.DepartmentId = await _context.Departments.Where(x => x.Code == request.Department).Select(x => x.Id).FirstOrDefaultAsync(cancellationToken);

            student.Name       = request.Name;
            student.Surname    = request.Surname;
            student.Email      = request.Email;
            student.Mobile     = request.Mobile;
            student.Phone      = request.Phone;
            student.PostalCode = postalCode.Code;
            student.Address    = request.Address;
            student.City       = postalCode.Area;
            student.Prefecture = postalCode.Prefecture;
            student.CountryId  = country.Id;
        }
Exemple #7
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, EducationContext educationContext)
        {
            educationContext.Database.Migrate();

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseSwagger();
                app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "server v1"));
            }

            //app.UseHttpsRedirection();

            app.UseRouting();

            app.UseCors(builder =>
            {
                builder.AllowAnyHeader();
                builder.AllowAnyMethod();
                builder.AllowAnyOrigin();
            });

            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });
        }
Exemple #8
0
        public EFUnitOfWork(EducationContext db)
        {
            this.db = db;

            groupRepository     = new Lazy <GroupRepository>(() => new GroupRepository(db));
            subjectRepository   = new Lazy <SubjectRepository>(() => new SubjectRepository(db));
            studentRepository   = new Lazy <StudentRepository>(() => new StudentRepository(db));
            educationRepository = new Lazy <EducationRepository>(() => new EducationRepository(db));
        }
Exemple #9
0
 public ActionResult ErrorPageTest(int customId)
 {
     using (var context = new EducationContext())
     {
         var student = new Student();
         student.Id = customId;
         context.Students.Add(student);
         context.SaveChanges();
         return(RedirectToAction("Index"));
     }
 }
 public void TestCleanup()
 {
     if (Container != null)
     {
         Container.Dispose();
     }
     if (EducationContext != null)
     {
         EducationContext.Dispose();
     }
 }
Exemple #11
0
 public EducationVO Insert(EducationContext ctx, EducationVO model)
 {
     try
     {
         ctx.Educations.Add(model);
         ctx.SaveChanges();
     }
     catch (Exception ex)
     {
         throw ex;
     }
     return(model);
 }
Exemple #12
0
 public void Update(EducationContext ctx, EducationVO model)
 {
     try
     {
         ctx.Entry(model).State = EntityState.Modified;
         ctx.Educations.Attach(model);
         ctx = UpdateProperties(model, ctx);
         ctx.SaveChanges();
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Exemple #13
0
        public EducationVO Save(EducationVO model)
        {
            MemberState state = MemberStateBL.State;

            try
            {
                model.MemberId = state.Member.Id;
                bool success = int.TryParse(model.GraduationYear, out int graduationYear);
                success = int.TryParse(model.StartYear, out int startYear);
                if (success)
                {
                    if (graduationYear < startYear)
                    {
                        throw new Exception(Resource.Er0009);
                    }
                }
                else
                {
                    throw new Exception(Resource.ErSomethingWrong);
                }
                // Insert new Education
                if (model.Id == 0)
                {
                    model.CreatedDate  = DateTime.UtcNow;
                    model.ModifiedDate = null;
                    using (var ctx = new EducationContext())
                    {
                        IEducationDA da = new EducationDA();
                        model = da.Insert(ctx, model);
                    }
                }
                // Update Education
                else
                {
                    model.ModifiedDate = TimeZone.CurrentTimeZone.ToLocalTime(DateTime.Now);
                    using (var ctx = new EducationContext())
                    {
                        IEducationDA da = new EducationDA();
                        da.Update(ctx, model);
                    }
                }
            }
            catch
            {
                throw;
            }
            return(model);
        }
Exemple #14
0
 public ActionResult Index()
 {
     /*
      * LazyLoading , Include ve Select  Yöntemleri üzerine konuş.
      */
     using (var context = new EducationContext())
     {
         var students = context.Students.Where(x => x.IsDeleted == false).Include("Class").Select(x => new StudentListViewModel()
         {
             Id         = x.Id, LastName = x.LastName, SchoolNumber = x.SchoolNumber, IsDeleted = x.IsDeleted,
             Name       = x.Name, PhoneNumber = x.PhoneNumber, ClassName = x.Class.Name, Email = x.Email, Age = x.Age,
             CreateDate = x.CreateDate, IdentityNumber = x.IdentityNumber
         }).ToList();
         return(View(students));
     }
 }
Exemple #15
0
 public ActionResult Add()
 {
     /*
      * Html.BeginForm
      * ViewBag
      * TempData
      * Mvc Html Helper kullanımı
      * Üzerine konuş
      */
     using (var context = new EducationContext())
     {
         ViewBag.studentClasses     = context.Classes.ToList();
         TempData["studentClasses"] = context.Classes.ToList();
     }
     return(View());
 }
Exemple #16
0
        /// <summary>
        /// Get Member's educations async
        /// </summary>
        /// <param name="memberId"></param>
        /// <returns></returns>
        public List <EducationVO> GetEducationsByMemberId(int memberId)
        {
            List <EducationVO> model = new List <EducationVO>();

            try
            {
                using (var ctx = new EducationContext())
                {
                    IEducationDA da = new EducationDA();
                    model = da.FindEducationsByMemberId(memberId, ctx);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(model);
        }
Exemple #17
0
 private EducationContext UpdateProperties(EducationVO model, EducationContext ctx)
 {
     try
     {
         ctx.Entry(model).Property("Degree").IsModified         = UpdateItemToDatabasecs.Item(model.Degree);
         ctx.Entry(model).Property("School").IsModified         = UpdateItemToDatabasecs.Item(model.School);
         ctx.Entry(model).Property("Department").IsModified     = UpdateItemToDatabasecs.Item(model.Department);
         ctx.Entry(model).Property("Grade").IsModified          = UpdateItemToDatabasecs.Item(model.Grade);
         ctx.Entry(model).Property("StartYear").IsModified      = UpdateItemToDatabasecs.Item(model.StartYear);
         ctx.Entry(model).Property("GraduationYear").IsModified = UpdateItemToDatabasecs.Item(model.GraduationYear);
         ctx.Entry(model).Property("CreatedDate").IsModified    = UpdateItemToDatabasecs.Item(model.CreatedDate);
         ctx.Entry(model).Property("MemberId").IsModified       = UpdateItemToDatabasecs.Item(model.MemberId);
         ctx.Entry(model).Property("ModifiedDate").IsModified   = UpdateItemToDatabasecs.Item(model.ModifiedDate);
     }
     catch
     {
         throw;
     }
     return(ctx);
 }
Exemple #18
0
 public ActionResult Add(StudentViewModel viewModel)
 {
     /*
      * RouteValueDictionary
      * DatabaseFirst
      */
     try
     {
         using (var context = new EducationContext())
         {
             TempData["studentClasses"] = context.Classes.ToList();
             if (!ModelState.IsValid)
             {
                 return(View(viewModel));
             }
             else
             {
                 var student = new Student()
                 {
                     PhoneNumber    = viewModel.PhoneNumber,
                     ClassId        = viewModel.ClassId,
                     IdentityNumber = viewModel.IdentityNumber,
                     LastName       = viewModel.LastName,
                     Name           = viewModel.Name,
                     CreateDate     = viewModel.CreateDate,
                     SchoolNumber   = viewModel.SchoolNumber,
                     IsDeleted      = viewModel.IsDeleted,
                     Age            = viewModel.Age,
                     Email          = viewModel.Email
                 };
                 context.Students.Add(student);
                 context.SaveChanges();
                 return(RedirectToAction("Index", "Education"));
             }
         }
     }
     catch
     {
         return(View(viewModel));
     }
 }
Exemple #19
0
 public ActionResult Delete(int studentId)
 {
     try
     {
         using (var context = new EducationContext())
         {
             var student = context.Students?.FirstOrDefault(s => s.Id == studentId && s.IsDeleted == false);
             if (student == null)
             {
                 return(View("Error"));
             }
             student.IsDeleted = true;
             context.SaveChanges();
             return(RedirectToAction("Index"));
         }
     }
     catch
     {
         return(View("Error"));
     }
 }
Exemple #20
0
        public void OnException(ExceptionContext filterContext)
        {
            using (var context = new EducationContext())
            {
                var user      = HttpContext.Current.Session["LoginUser"] as LoginViewModel;
                var exception = new Log()
                {
                    UserName       = user.UserName, ExceptionMessage = filterContext.Exception.Message, CreatedDate = DateTime.Now,
                    ControllerName = filterContext.RouteData.Values["controller"].ToString(),
                    ActionName     = filterContext.RouteData.Values["action"].ToString()
                };
                context.Logs.Add(exception);
                context.SaveChanges();

                filterContext.ExceptionHandled = true;
                filterContext.Result           = new ViewResult()
                {
                    ViewName = "Error"
                };
            }
        }
Exemple #21
0
 public PartialViewResult GetPartialViewResult()
 {
     using (var context = new EducationContext())
     {
         var students = context.Students.Where(x => x.IsDeleted == false).Include("Class").Select(x => new StudentListViewModel()
         {
             Id             = x.Id,
             LastName       = x.LastName,
             SchoolNumber   = x.SchoolNumber,
             IsDeleted      = x.IsDeleted,
             Name           = x.Name,
             PhoneNumber    = x.PhoneNumber,
             ClassName      = x.Class.Name,
             Email          = x.Email,
             Age            = x.Age,
             CreateDate     = x.CreateDate,
             IdentityNumber = x.IdentityNumber
         }).ToList();
         return(PartialView("ListPartialView", students));
     }
 }
Exemple #22
0
        public List <EducationVO> FindEducationsByMemberId(int memberId, EducationContext ctx)
        {
            List <EducationVO> model = new List <EducationVO>();

            try
            {
                var query = (from edu in ctx.Educations.AsEnumerable()
                             where edu.MemberId == memberId
                             select new EducationVO
                {
                    Id = edu.Id,
                    Degree = edu.Degree,
                    School = edu.School,
                    Department = edu.Department,
                    StartYear = edu.StartYear,
                    GraduationYear = edu.GraduationYear,
                    Grade = edu.Grade
                }).ToList();

                foreach (EducationVO edu in query)
                {
                    EducationVO education = new EducationVO()
                    {
                        Id             = FillItemForDatabase.FillItem(edu.Id),
                        Degree         = FillItemForDatabase.FillItem(edu.Degree),
                        School         = FillItemForDatabase.FillItem(edu.School),
                        Department     = FillItemForDatabase.FillItem(edu.Department),
                        StartYear      = FillItemForDatabase.FillItem(edu.StartYear),
                        GraduationYear = FillItemForDatabase.FillItem(edu.GraduationYear),
                        Grade          = FillItemForDatabase.FillItem(edu.Grade),
                    };
                    model.Add(education);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(model);
        }
Exemple #23
0
        public EducationVO GetEducationById(int id)
        {
            MemberState state = MemberStateBL.State;
            EducationVO model = new EducationVO();

            try
            {
                using (var ctx = new EducationContext())
                {
                    IEducationDA da = new EducationDA();
                    model = da.FindEducationById(id, ctx);
                    if (model.MemberId != state.Member.Id)
                    {
                        throw new AuthenticationException();
                    }
                }
            }
            catch
            {
                throw;
            }
            return(model);
        }
        public void GivenSort_AndOneServiceAttendanceIsVeryLarge_WhenGenerateDataTableResultViewModel_ThenSucceed()
        {
            DataTableRequestModel model = new DataTableRequestModel();

            model.iDisplayLength = 10;
            var request = MockHttpContextFactory.CreateRequest();

            request.Expect(r => r["id"]).Return("1");
            request.Expect(r => r["iSortCol_0"]).Return("0");
            request.Expect(r => r["sSortDir_0"]).Return("asc");
            ServiceAttendanceClientDataTable dataTable = new ServiceAttendanceClientDataTable(request);
            ServiceAttendance attendance = new ServiceAttendance
            {
                DateAttended            = DateTime.Now.AddYears(100),
                StudentAssignedOffering = EducationContext.StudentAssignedOfferings.Where(s => s.Id == 1).Single(),
                Subject      = EducationContext.Subjects.First(),
                CreatingUser = User.Identity.User
            };

            EducationContext.ServiceAttendances.Add(attendance);
            EducationContext.SaveChanges();

            var actual = Target.GenerateDataTableResultViewModel(model, dataTable);
        }
        public static void Initialize(EducationContext context)
        {
            context.Database.EnsureCreated();

            // Look for any students.
            if (context.Student.Any())
            {
                return;   // DB has been seeded
            }

            var students = new Student[]
            {
                new Student {
                    FirstMidName   = "Carson", LastName = "Alexander",
                    EnrollmentDate = DateTime.Parse("2010-09-01")
                },
                new Student {
                    FirstMidName   = "Meredith", LastName = "Alonso",
                    EnrollmentDate = DateTime.Parse("2012-09-01")
                },
                new Student {
                    FirstMidName   = "Arturo", LastName = "Anand",
                    EnrollmentDate = DateTime.Parse("2013-09-01")
                },
                new Student {
                    FirstMidName   = "Gytis", LastName = "Barzdukas",
                    EnrollmentDate = DateTime.Parse("2012-09-01")
                },
                new Student {
                    FirstMidName   = "Yan", LastName = "Li",
                    EnrollmentDate = DateTime.Parse("2012-09-01")
                },
                new Student {
                    FirstMidName   = "Peggy", LastName = "Justice",
                    EnrollmentDate = DateTime.Parse("2011-09-01")
                },
                new Student {
                    FirstMidName   = "Laura", LastName = "Norman",
                    EnrollmentDate = DateTime.Parse("2013-09-01")
                },
                new Student {
                    FirstMidName   = "Nino", LastName = "Olivetto",
                    EnrollmentDate = DateTime.Parse("2005-09-01")
                }
            };

            foreach (Student s in students)
            {
                context.Student.Add(s);
            }
            context.SaveChanges();

            var instructors = new Instructor[]
            {
                new Instructor {
                    FirstMidName = "Kim", LastName = "Abercrombie",
                    HireDate     = DateTime.Parse("1995-03-11")
                },
                new Instructor {
                    FirstMidName = "Fadi", LastName = "Fakhouri",
                    HireDate     = DateTime.Parse("2002-07-06")
                },
                new Instructor {
                    FirstMidName = "Roger", LastName = "Harui",
                    HireDate     = DateTime.Parse("1998-07-01")
                },
                new Instructor {
                    FirstMidName = "Candace", LastName = "Kapoor",
                    HireDate     = DateTime.Parse("2001-01-15")
                },
                new Instructor {
                    FirstMidName = "Roger", LastName = "Zheng",
                    HireDate     = DateTime.Parse("2004-02-12")
                }
            };

            foreach (Instructor i in instructors)
            {
                context.Instructors.Add(i);
            }
            context.SaveChanges();

            var departments = new Department[]
            {
                new Department {
                    Name         = "English", Budget = 350000,
                    StartDate    = DateTime.Parse("2007-09-01"),
                    InstructorID = instructors.Single(i => i.LastName == "Abercrombie").ID
                },
                new Department {
                    Name         = "Mathematics", Budget = 100000,
                    StartDate    = DateTime.Parse("2007-09-01"),
                    InstructorID = instructors.Single(i => i.LastName == "Fakhouri").ID
                },
                new Department {
                    Name         = "Engineering", Budget = 350000,
                    StartDate    = DateTime.Parse("2007-09-01"),
                    InstructorID = instructors.Single(i => i.LastName == "Harui").ID
                },
                new Department {
                    Name         = "Economics", Budget = 100000,
                    StartDate    = DateTime.Parse("2007-09-01"),
                    InstructorID = instructors.Single(i => i.LastName == "Kapoor").ID
                }
            };

            foreach (Department d in departments)
            {
                context.Departments.Add(d);
            }
            context.SaveChanges();

            var courses = new Course[]
            {
                new Course {
                    CourseID     = 1050, Title = "Chemistry", Credits = 3,
                    DepartmentID = departments.Single(s => s.Name == "Engineering").DepartmentID
                },
                new Course {
                    CourseID     = 4022, Title = "Microeconomics", Credits = 3,
                    DepartmentID = departments.Single(s => s.Name == "Economics").DepartmentID
                },
                new Course {
                    CourseID     = 4041, Title = "Macroeconomics", Credits = 3,
                    DepartmentID = departments.Single(s => s.Name == "Economics").DepartmentID
                },
                new Course {
                    CourseID     = 1045, Title = "Calculus", Credits = 4,
                    DepartmentID = departments.Single(s => s.Name == "Mathematics").DepartmentID
                },
                new Course {
                    CourseID     = 3141, Title = "Trigonometry", Credits = 4,
                    DepartmentID = departments.Single(s => s.Name == "Mathematics").DepartmentID
                },
                new Course {
                    CourseID     = 2021, Title = "Composition", Credits = 3,
                    DepartmentID = departments.Single(s => s.Name == "English").DepartmentID
                },
                new Course {
                    CourseID     = 2042, Title = "Literature", Credits = 4,
                    DepartmentID = departments.Single(s => s.Name == "English").DepartmentID
                },
            };

            foreach (Course c in courses)
            {
                context.Courses.Add(c);
            }
            context.SaveChanges();

            var officeAssignments = new OfficeAssignment[]
            {
                new OfficeAssignment {
                    InstructorID = instructors.Single(i => i.LastName == "Fakhouri").ID,
                    Location     = "Smith 17"
                },
                new OfficeAssignment {
                    InstructorID = instructors.Single(i => i.LastName == "Harui").ID,
                    Location     = "Gowan 27"
                },
                new OfficeAssignment {
                    InstructorID = instructors.Single(i => i.LastName == "Kapoor").ID,
                    Location     = "Thompson 304"
                },
            };

            foreach (OfficeAssignment o in officeAssignments)
            {
                context.OfficeAssignments.Add(o);
            }
            context.SaveChanges();

            var courseInstructors = new CourseAssignment[]
            {
                new CourseAssignment {
                    CourseID     = courses.Single(c => c.Title == "Chemistry").CourseID,
                    InstructorID = instructors.Single(i => i.LastName == "Kapoor").ID
                },
                new CourseAssignment {
                    CourseID     = courses.Single(c => c.Title == "Chemistry").CourseID,
                    InstructorID = instructors.Single(i => i.LastName == "Harui").ID
                },
                new CourseAssignment {
                    CourseID     = courses.Single(c => c.Title == "Microeconomics").CourseID,
                    InstructorID = instructors.Single(i => i.LastName == "Zheng").ID
                },
                new CourseAssignment {
                    CourseID     = courses.Single(c => c.Title == "Macroeconomics").CourseID,
                    InstructorID = instructors.Single(i => i.LastName == "Zheng").ID
                },
                new CourseAssignment {
                    CourseID     = courses.Single(c => c.Title == "Calculus").CourseID,
                    InstructorID = instructors.Single(i => i.LastName == "Fakhouri").ID
                },
                new CourseAssignment {
                    CourseID     = courses.Single(c => c.Title == "Trigonometry").CourseID,
                    InstructorID = instructors.Single(i => i.LastName == "Harui").ID
                },
                new CourseAssignment {
                    CourseID     = courses.Single(c => c.Title == "Composition").CourseID,
                    InstructorID = instructors.Single(i => i.LastName == "Abercrombie").ID
                },
                new CourseAssignment {
                    CourseID     = courses.Single(c => c.Title == "Literature").CourseID,
                    InstructorID = instructors.Single(i => i.LastName == "Abercrombie").ID
                },
            };

            foreach (CourseAssignment ci in courseInstructors)
            {
                context.CourseAssignments.Add(ci);
            }
            context.SaveChanges();

            var enrollments = new Enrollment[]
            {
                new Enrollment {
                    StudentID = students.Single(s => s.LastName == "Alexander").ID,
                    CourseID  = courses.Single(c => c.Title == "Chemistry").CourseID,
                    Grade     = Grade.A
                },
                new Enrollment {
                    StudentID = students.Single(s => s.LastName == "Alexander").ID,
                    CourseID  = courses.Single(c => c.Title == "Microeconomics").CourseID,
                    Grade     = Grade.C
                },
                new Enrollment {
                    StudentID = students.Single(s => s.LastName == "Alexander").ID,
                    CourseID  = courses.Single(c => c.Title == "Macroeconomics").CourseID,
                    Grade     = Grade.B
                },
                new Enrollment {
                    StudentID = students.Single(s => s.LastName == "Alonso").ID,
                    CourseID  = courses.Single(c => c.Title == "Calculus").CourseID,
                    Grade     = Grade.B
                },
                new Enrollment {
                    StudentID = students.Single(s => s.LastName == "Alonso").ID,
                    CourseID  = courses.Single(c => c.Title == "Trigonometry").CourseID,
                    Grade     = Grade.B
                },
                new Enrollment {
                    StudentID = students.Single(s => s.LastName == "Alonso").ID,
                    CourseID  = courses.Single(c => c.Title == "Composition").CourseID,
                    Grade     = Grade.B
                },
                new Enrollment {
                    StudentID = students.Single(s => s.LastName == "Anand").ID,
                    CourseID  = courses.Single(c => c.Title == "Chemistry").CourseID
                },
                new Enrollment {
                    StudentID = students.Single(s => s.LastName == "Anand").ID,
                    CourseID  = courses.Single(c => c.Title == "Microeconomics").CourseID,
                    Grade     = Grade.B
                },
                new Enrollment {
                    StudentID = students.Single(s => s.LastName == "Barzdukas").ID,
                    CourseID  = courses.Single(c => c.Title == "Chemistry").CourseID,
                    Grade     = Grade.B
                },
                new Enrollment {
                    StudentID = students.Single(s => s.LastName == "Li").ID,
                    CourseID  = courses.Single(c => c.Title == "Composition").CourseID,
                    Grade     = Grade.B
                },
                new Enrollment {
                    StudentID = students.Single(s => s.LastName == "Justice").ID,
                    CourseID  = courses.Single(c => c.Title == "Literature").CourseID,
                    Grade     = Grade.B
                }
            };

            foreach (Enrollment e in enrollments)
            {
                var enrollmentInDataBase = context.Enrollment.Where(
                    s =>
                    s.Student.ID == e.StudentID &&
                    s.Course.CourseID == e.CourseID).SingleOrDefault();
                if (enrollmentInDataBase == null)
                {
                    context.Enrollment.Add(e);
                }
            }
            context.SaveChanges();
        }
Exemple #26
0
 public EnrollmentRepository(EducationContext dbContext) : base(dbContext)
 {
 }
Exemple #27
0
 public EscolasController(EducationContext context)
 {
     _context = context;
 }
 public TaskRepositoryImpl(EducationContext context)
 {
     this.db = context;
 }
Exemple #29
0
 public LocalizationManager(EducationContext context)
 {
     this._context = context;
 }
 public FormSubmitController(EducationContext context, IPostalCodeProviderService postalCodeProviderService)
 {
     this._context = context;
     this._postalCodeProviderService = postalCodeProviderService;
 }