Exemplo n.º 1
0
        /// <summary>
        /// Seed function to seed that db with some classes and enroled student.
        /// </summary>
        public void Seed()
        {
            _db.Database.ExecuteSqlCommand("TRUNCATE TABLE Courses");
            _db.Database.ExecuteSqlCommand("TRUNCATE TABLE Students");
            _db.Database.ExecuteSqlCommand("TRUNCATE TABLE CourseTemplates");
            _db.Database.ExecuteSqlCommand("TRUNCATE TABLE CourseEnrolments");
            _db.Database.ExecuteSqlCommand("TRUNCATE TABLE CourseWaitinglists");

//            _db.Courses.AddRange(new List<Course>
//            {
//                new Course { TemplateID = "T-514-VEFT", Semester = "20143", StartDate = new DateTime(2014, 8, 15), EndDate = new DateTime(2014, 11, 19), MaxStudents = 5 },
//                new Course { TemplateID = "T-514-VEFT", Semester = "20153", StartDate = new DateTime(2015, 8, 17), EndDate = new DateTime(2015, 11, 21), MaxStudents = 10 },
//                new Course { TemplateID = "T-111-PROG", Semester = "20143", StartDate = new DateTime(2014, 8, 15), EndDate = new DateTime(2014, 11, 19), MaxStudents = 5 }
//            });
//            _db.SaveChanges();

            _db.CourseTemplates.AddRange(new List <CourseTemplate>
            {
                new CourseTemplate {
                    TemplateID = "T-514-VEFT", Name = "Vefþjónustur"
                }
//                new CourseTemplate { TemplateID = "T-111-PROG", Name = "Forritun" },
            });
            _db.SaveChanges();

            _db.Students.AddRange(new List <Student>
            {
//                new Student { SSN = "1234567890", Name = "Jón Jónsson" },
//                new Student { SSN = "9876543210", Name = "Guðrún Jónsdóttir" },
//                new Student { SSN = "6543219870", Name = "Gunnar Sigurðsson" },
//                new Student { SSN = "4567891230", Name = "Jóna Halldórsdóttir" },
                new Student {
                    SSN = "1234567890", Name = "Herp McDerpsson 1"
                },
                new Student {
                    SSN = "1234567891", Name = "Herpina Derpy 1"
                },
                new Student {
                    SSN = "1234567892", Name = "Herp McDerpsson 2"
                },
                new Student {
                    SSN = "1234567893", Name = "Herpina Derpy 2"
                },
                new Student {
                    SSN = "1234567894", Name = "Herp McDerpsson 3"
                },
                new Student {
                    SSN = "1234567895", Name = "Herpina Derpy 3"
                },
                new Student {
                    SSN = "1234567896", Name = "Herp McDerpsson 4"
                },
                new Student {
                    SSN = "1234567897", Name = "Herpina Derpy 4"
                },
                new Student {
                    SSN = "1234567898", Name = "Herp McDerpsson 5"
                },
                new Student {
                    SSN = "1234567899", Name = "Herpina Derpy 5"
                }
            });
            _db.SaveChanges();

//            _db.CourseEnrolments.AddRange(new List<CourseEnrolment>
//            {
//                new CourseEnrolment { CourseID = 1, StudentID = 1, Active = true },
//                new CourseEnrolment { CourseID = 1, StudentID = 2, Active = true },
//                new CourseEnrolment { CourseID = 2, StudentID = 3, Active = true },
//                new CourseEnrolment { CourseID = 2, StudentID = 4, Active = true },
//                new CourseEnrolment { CourseID = 3, StudentID = 1, Active = true },
//                new CourseEnrolment { CourseID = 3, StudentID = 2, Active = true },
//                new CourseEnrolment { CourseID = 1, StudentID = 5, Active = false },
//                new CourseEnrolment { CourseID = 2, StudentID = 6, Active = false },
//                new CourseEnrolment { CourseID = 3, StudentID = 7, Active = false }
//            });
//            _db.SaveChanges();
        }
 public void AddCourse(Courses courses)
 {
     _schoolDb.Set <Courses>().Add(courses);
     _schoolDb.SaveChanges();
 }
Exemplo n.º 3
0
 public int CreateSubject(Subjects subjects)
 {
     context.Subjects.Add(subjects);
     return(context.SaveChanges());
 }
Exemplo n.º 4
0
 //TODO: individual and all select shall work properly
 /// <summary>
 /// multiple delete - individual and all select shall work properly
 /// </summary>
 /// <param name="courseIdToDelete"></param>
 /// <returns></returns>
 public ActionResult MultipleDelete(IEnumerable <int> courseIdToDelete)
 {
     db.courses.RemoveRange(db.courses.Where(x => courseIdToDelete.Contains(x.CourseId)).ToList());
     db.SaveChanges();
     return(RedirectToAction("Index"));
 }
Exemplo n.º 5
0
        public static void Initialise(SchoolDbContext context)
        {
            context.Database.EnsureCreated();//要创建数据库

            if (context.Students.Any())
            {
                return;
            }

            #region 添加种子学生信息
            var students = new Student[] {
                new Student {
                    RealName = "乔峰", EnrollmnetDate = DateTime.Parse("2011-08-26")
                },
                new Student {
                    RealName = "段誉", EnrollmnetDate = DateTime.Parse("2012-08-26")
                },
                new Student {
                    RealName = "虚竹", EnrollmnetDate = DateTime.Parse("2011-08-26")
                },
                new Student {
                    RealName = "令狐冲", EnrollmnetDate = DateTime.Parse("2013-07-26")
                },
                new Student {
                    RealName = "张无忌", EnrollmnetDate = DateTime.Parse("2015-08-26")
                },
                new Student {
                    RealName = "杨过", EnrollmnetDate = DateTime.Parse("2014-08-26")
                },
                new Student {
                    RealName = "黄蓉", EnrollmnetDate = DateTime.Parse("2011-08-26")
                },
            };

            foreach (var student in students)
            {
                context.Students.Add(student);
            }
            context.SaveChanges();
            #endregion

            #region 添加种子老师信息

            var instructors = new Instructor[] {
                new Instructor {
                    RealName = "孔子", HireDate = DateTime.Parse("1993-08-12")
                },
                new Instructor {
                    RealName = "墨子", HireDate = DateTime.Parse("1994-08-12")
                },
                new Instructor {
                    RealName = "荀子", HireDate = DateTime.Parse("1995-08-12")
                },
                new Instructor {
                    RealName = "鬼谷子", HireDate = DateTime.Parse("1996-08-12")
                },
                new Instructor {
                    RealName = "孟子", HireDate = DateTime.Parse("1997-08-12")
                },
                new Instructor {
                    RealName = "朱熹", HireDate = DateTime.Parse("1998-08-12")
                },
                new Instructor {
                    RealName = "庄子", HireDate = DateTime.Parse("1999-08-12")
                },
            };

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

            #endregion

            #region 添加部门的种子数据

            var departments = new Department[]
            {
                new Department {
                    Name = "声乐", Budget = 350000, StartDate = DateTime.Parse("2013-09-04"), InstructorId = instructors.Single(i => i.RealName == "墨子").Id
                },
                new Department {
                    Name = "杂技", Budget = 350000, StartDate = DateTime.Parse("2014-09-04"), InstructorId = instructors.Single(i => i.RealName == "孔子").Id
                },
                new Department {
                    Name = "学说", Budget = 350000, StartDate = DateTime.Parse("2015-09-04"), InstructorId = instructors.Single(i => i.RealName == "庄子").Id
                },
                new Department {
                    Name = "兵法", Budget = 350000, StartDate = DateTime.Parse("2016-09-04"), InstructorId = instructors.Single(i => i.RealName == "荀子").Id
                }
            };

            foreach (var d in departments)
            {
                context.Departments.Add(d);
            }
            context.SaveChanges();
            #endregion

            #region 添加种子课程

            var courses = new Course[] {
                new Course {
                    Id = 10010, Title = "政治", Credits = 6, DepartmentId = departments.Single(d => d.Name == "声乐").Id
                },
                new Course {
                    Id = 10011, Title = "历史", Credits = 4, DepartmentId = departments.Single(d => d.Name == "杂技").Id
                },
                new Course {
                    Id = 10012, Title = "语文", Credits = 4, DepartmentId = departments.Single(d => d.Name == "杂技").Id
                },
                new Course {
                    Id = 10013, Title = "地理", Credits = 4, DepartmentId = departments.Single(d => d.Name == "兵法").Id
                },
            };

            foreach (var course in courses)
            {
                context.Courses.Add(course);
            }
            context.SaveChanges();
            #endregion

            #region 添加办公室分配的种子数据

            var officeAssignments = new OfficeAssignment[]
            {
                new OfficeAssignment {
                    InstructorId = instructors.Single(i => i.RealName == "墨子").Id, Location = "逸夫楼17"
                },
                new OfficeAssignment {
                    InstructorId = instructors.Single(i => i.RealName == "孔子").Id, Location = "逸夫楼18"
                },
                new OfficeAssignment {
                    InstructorId = instructors.Single(i => i.RealName == "庄子").Id, Location = "逸夫楼19"
                },
            };

            foreach (var o in officeAssignments)
            {
                context.OfficeAssignments.Add(o);
            }
            context.SaveChanges();
            #endregion

            #region 添加课程老师的种子数据

            var courseInstrutors = new CourseAssignment[]
            {
                new CourseAssignment {
                    CourseId = courses.Single(c => c.Title == "政治").Id, InstructorId = instructors.Single(i => i.RealName == "孟子").Id
                },
                new CourseAssignment {
                    CourseId = courses.Single(c => c.Title == "政治").Id, InstructorId = instructors.Single(i => i.RealName == "孔子").Id
                },
                new CourseAssignment {
                    CourseId = courses.Single(c => c.Title == "语文").Id, InstructorId = instructors.Single(i => i.RealName == "庄子").Id
                },
                new CourseAssignment {
                    CourseId = courses.Single(c => c.Title == "历史").Id, InstructorId = instructors.Single(i => i.RealName == "庄子").Id
                },
            };

            foreach (var c in courseInstrutors)
            {
                context.CourseAssignments.Add(c);
            }
            context.SaveChanges();
            #endregion

            #region 添加招生信息种子数据

            var enrollments = new Enrollment[]
            {
                new Enrollment {
                    StudentId = students.Single(s => s.RealName == "乔峰").Id, CourseId = courses.Single(c => c.Title == "政治").Id, Grade = CourseGrade.A
                },
                new Enrollment {
                    StudentId = students.Single(s => s.RealName == "乔峰").Id, CourseId = courses.Single(c => c.Title == "历史").Id, Grade = CourseGrade.A
                },
                new Enrollment {
                    StudentId = students.Single(s => s.RealName == "段誉").Id, CourseId = courses.Single(c => c.Title == "语文").Id, Grade = CourseGrade.B
                },
                new Enrollment {
                    StudentId = students.Single(s => s.RealName == "虚竹").Id, CourseId = courses.Single(c => c.Title == "地理").Id, Grade = CourseGrade.C
                },
            };

            foreach (var e in enrollments)
            {
                context.Enrollments.Add(e);
            }
            context.SaveChanges();

            #endregion
        }
Exemplo n.º 6
0
        private void CreateHostRoleAndUsers()
        {
            // Admin role for host

            var adminRoleForHost = _context.Roles.IgnoreQueryFilters().FirstOrDefault(r => r.TenantId == null && r.Name == StaticRoleNames.Host.Admin);

            if (adminRoleForHost == null)
            {
                adminRoleForHost = _context.Roles.Add(new Role(null, StaticRoleNames.Host.Admin, StaticRoleNames.Host.Admin)
                {
                    IsStatic = true, IsDefault = true
                }).Entity;
                _context.SaveChanges();
            }

            // Grant all permissions to admin role for host

            var grantedPermissions = _context.Permissions.IgnoreQueryFilters()
                                     .OfType <RolePermissionSetting>()
                                     .Where(p => p.TenantId == null && p.RoleId == adminRoleForHost.Id)
                                     .Select(p => p.Name)
                                     .ToList();

            var permissions = PermissionFinder
                              .GetAllPermissions(new AppAuthorizationProvider(true))
                              .Where(p => p.MultiTenancySides.HasFlag(MultiTenancySides.Host) &&
                                     !grantedPermissions.Contains(p.Name))
                              .ToList();

            if (permissions.Any())
            {
                _context.Permissions.AddRange(
                    permissions.Select(permission => new RolePermissionSetting
                {
                    TenantId  = null,
                    Name      = permission.Name,
                    IsGranted = true,
                    RoleId    = adminRoleForHost.Id
                })
                    );
                _context.SaveChanges();
            }

            // Admin user for host

            var adminUserForHost = _context.Users.IgnoreQueryFilters().FirstOrDefault(u => u.TenantId == null && u.UserName == AbpUserBase.AdminUserName);

            if (adminUserForHost == null)
            {
                var user = new User
                {
                    TenantId         = null,
                    UserName         = AbpUserBase.AdminUserName,
                    Name             = "admin",
                    Surname          = "admin",
                    EmailAddress     = "*****@*****.**",
                    IsEmailConfirmed = true,
                    IsActive         = true
                };

                user.Password = new PasswordHasher <User>(new OptionsWrapper <PasswordHasherOptions>(new PasswordHasherOptions())).HashPassword(user, "123qwe");
                user.SetNormalizedNames();

                adminUserForHost = _context.Users.Add(user).Entity;
                _context.SaveChanges();

                // Assign Admin role to admin user
                _context.UserRoles.Add(new UserRole(null, adminUserForHost.Id, adminRoleForHost.Id));
                _context.SaveChanges();

                // User account of admin user
                _context.UserAccounts.Add(new UserAccount
                {
                    TenantId     = null,
                    UserId       = adminUserForHost.Id,
                    UserName     = AbpUserBase.AdminUserName,
                    EmailAddress = adminUserForHost.EmailAddress
                });
                _context.SaveChanges();
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// 数据库初始化静态方法.
        /// </summary>
        /// <param name="context"></param>
        public static void Initialize(SchoolDbContext context)
        {
            // 确保数据库已经创建.
            context.Database.EnsureCreated();

            // 添加种子数据.
            if (!context.Students.Any())
            {
                var students = new Student[] {
                    new Student()
                    {
                        Name           = "LancerComet",
                        EnrollmentDate = DateTime.Parse("2017-12-11")
                    },

                    new Student()
                    {
                        Name           = "Wch",
                        EnrollmentDate = DateTime.Parse("2017-12-11")
                    }
                };

                foreach (Student item in students)
                {
                    context.Students.Add(item);
                }

                context.SaveChanges();
            }

            if (!context.Courses.Any())
            {
                var courses = new Course[] {
                    new Course()
                    {
                        Id = 1, Title = "Chinese", Credits = 2
                    },
                    new Course()
                    {
                        Id = 2, Title = "English", Credits = 2
                    },
                    new Course()
                    {
                        Id = 3, Title = "Math", Credits = 2
                    },
                    new Course()
                    {
                        Id = 4, Title = "Physics", Credits = 1
                    },
                    new Course()
                    {
                        Id = 5, Title = "Chemical", Credits = 1
                    }
                };

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

                context.SaveChanges();
            }

            if (!context.Enrollments.Any())
            {
                // 如果 Enrollments 创建失败, 请检查学生 ID 是否和上方一致.
                var enrollments = new Enrollment[] {
                    new Enrollment()
                    {
                        StudentId = 11, CourseId = 1, Grade = CourseGrade.B
                    },

                    new Enrollment()
                    {
                        StudentId = 11, CourseId = 2, Grade = CourseGrade.A
                    },

                    new Enrollment()
                    {
                        StudentId = 11, CourseId = 3, Grade = CourseGrade.C
                    },

                    new Enrollment()
                    {
                        StudentId = 12, CourseId = 1, Grade = CourseGrade.D
                    },

                    new Enrollment()
                    {
                        StudentId = 12, CourseId = 4, Grade = CourseGrade.E
                    },

                    new Enrollment()
                    {
                        StudentId = 12, CourseId = 5, Grade = CourseGrade.F
                    }
                };

                foreach (Enrollment item in enrollments)
                {
                    context.Enrollments.Add(item);
                }

                context.SaveChanges();
            }
        }
Exemplo n.º 8
0
 public int CreateStudent(Students students)
 {
     context.Students.Add(students);
     return(context.SaveChanges());
 }
 public void Add(Department department)
 {
     _schoolDb.Set <Department>().Add(department);
     _schoolDb.SaveChanges();
 }
Exemplo n.º 10
0
        /// <summary>
        /// 初始化数据
        /// </summary>
        /// <param name="context"></param>
        public static void Initialize(SchoolDbContext context)
        {
            context.Database.EnsureCreated();

            if (context.Students.Any())
            {
                return;
            }

            //Student
            var students = new Student[] {
                new Student {
                    Id = 1, StuName = "小王", EnrollmentDate = Convert.ToDateTime("2017-09-09")
                },
                new Student {
                    Id = 2, StuName = "小李", EnrollmentDate = Convert.ToDateTime("2017-09-09")
                },
                new Student {
                    Id = 3, StuName = "小张", EnrollmentDate = Convert.ToDateTime("2017-09-09")
                },
                new Student {
                    Id = 4, StuName = "小刘", EnrollmentDate = Convert.ToDateTime("2017-09-09")
                },
                new Student {
                    Id = 5, StuName = "小陈", EnrollmentDate = Convert.ToDateTime("2017-09-09")
                }
            };

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

            //Course
            var courses = new Course[] {
                new Course {
                    ID = 2001, Title = "语文", Credits = 3
                },
                new Course {
                    ID = 2002, Title = "英语", Credits = 3
                },
                new Course {
                    ID = 2003, Title = "政治", Credits = 4
                },
                new Course {
                    ID = 2004, Title = "生物", Credits = 4
                },
                new Course {
                    ID = 2005, Title = "历史", Credits = 5
                }
            };

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

            //Enrollment

            //Course
            var Enrollments = new Enrollment[] {
                new Enrollment {
                    EnrollmentId = 5001, StudentId = 1, CourseId = 2001, Grade = CourseGrade.A
                },
                new Enrollment {
                    EnrollmentId = 5002, StudentId = 2, CourseId = 2002, Grade = CourseGrade.B
                },
                new Enrollment {
                    EnrollmentId = 5003, StudentId = 3, CourseId = 2003, Grade = CourseGrade.C
                },
                new Enrollment {
                    EnrollmentId = 5004, StudentId = 4, CourseId = 2004, Grade = CourseGrade.D
                },
                new Enrollment {
                    EnrollmentId = 5005, StudentId = 5, CourseId = 2005, Grade = CourseGrade.E
                }
            };

            foreach (Enrollment item in Enrollments)
            {
                context.Enrollments.Add(item);
            }
            context.SaveChanges();
        }
Exemplo n.º 11
0
 public int CreateCourse(Courses courses)
 {
     context.Courses.Add(courses);
     return(context.SaveChanges());
 }
Exemplo n.º 12
0
 public int CreateStudent(Student item)
 {
     _context.Student.Add(item);
     _context.SaveChanges();
     return(item.StudentID);
 }
Exemplo n.º 13
0
 public void Save()
 {
     _context.SaveChanges();
 }
Exemplo n.º 14
0
 public int Commit()
 {
     return(_context.SaveChanges());
 }
Exemplo n.º 15
0
        public IActionResult Index()
        {
            //haal de cursus op met id 1
            var courseInDb = _schoolDbContext
                             .Courses
                             .SingleOrDefault(c => c.Id == 2);

            //haal alle cursussen op
            var courses = _schoolDbContext.Courses.ToList();

            foreach (var course in courses)
            {
                Console.WriteLine($"{course.Id}-{course.CourseName}");
            }
            //selectie op basis van voorwaarden
            //vb haal alle cursussen die beginnen met WB
            //linq Where
            var coursesWb = _schoolDbContext
                            .Courses
                            .Where(c => c.CourseName.Contains("WB"))
                            .OrderBy(c => c.CourseName)
                            .ToList();

            foreach (var courseWb in coursesWb)
            {
                Console.WriteLine($"{courseWb.Id}-{courseWb.CourseName}");
            }
            //selectie van veld(en)
            //bv enkel de courseName = enkel veld
            var courseOnlyTitle = _schoolDbContext
                                  .Courses
                                  .OrderBy(c => c.CourseName)
                                  .Select(c => c.CourseName)//vanaf hier = lijst van string
                                  .ToList();
            //select van 2(of meer) velden
            //gebruik anoniem object
            //vb Id en Coursename
            var coursesTitleId = _schoolDbContext
                                 .Courses
                                 .OrderBy(c => c.CourseName)
                                 .Select(c => new { c.CourseName, c.Id })
                                 .ToList();

            //ophalen gerelateerde data
            //gebruik de include method
            //(rechtreeks gerelateerd)
            //ThenInclude (onrechtstreeks gerelateerd)
            //haal courses met hun teachers op
            var coursesTeachers = _schoolDbContext
                                  .Courses
                                  .Include(c => c.Teachers)   //join CoursesTeachers
                                  .ThenInclude(ct => ct.Teacher)
                                  .OrderBy(c => c.CourseName) //join met Taachers
                                  .ToList();

            foreach (var coursesTeacher in coursesTeachers)
            {
                Console.WriteLine($"{coursesTeacher?.CourseName}");
                foreach (var teacher in coursesTeacher?.Teachers)
                {
                    Console.Write($"{teacher?.Teacher?.TeacherName} ");
                }
            }

            //toevoegen van data
            //single object(zonder gerelateerde data)
            //var newTeacher = new Teacher();
            //newTeacher.TeacherName = "Siegfried Deerdeyn";
            //change tracker
            // _schoolDbContext.Teachers.Add(newTeacher);


            //maak een nieuwe teacher
            //maak een nieuwe cursus
            //voeg ze toe aan CourseTeachers
            //var newTeacher = new Teacher
            //{ TeacherName = "Willie Schokkelé",YearlyWage=20000 };
            //var newCourse = new Course { CourseName = "CIA", Duration = 20 };
            //var courseTeacher = new CoursesTeachers
            //{ Course = newCourse, Teacher = newTeacher };
            ////toevoegen aan de databasecontext
            //_schoolDbContext.CoursesTeachers.Add(courseTeacher);

            var teacherCourse = new CoursesTeachers
            {
                CourseId = 1 /*WBA*/, TeacherId = 4/*William Schokkelé*/
            };

            //toevoegen aan chnge tracker
            _schoolDbContext.CoursesTeachers.Add(teacherCourse);

            //opslaan gebeurt op het einde
            _schoolDbContext.SaveChanges();
            return(View());
        }
        public ActionResult Create(AdmissionVM viewModel, HttpPostedFileBase StudentImage, HttpPostedFileBase Document)
        {
            using (var dbTransaction = db.Database.BeginTransaction())
            {
                try
                {
                    #region validation
                    //if (!ModelState.IsValid)
                    //{
                    //    var studentClass = db.StudentClass.Select(c => new
                    //    {
                    //        Id = c.Id,
                    //        Name = c.ClassName.Name + " || " + c.Shift.Name + " ||" + c.Section.Name
                    //    }).OrderBy(o => o.Name).ToList();

                    //    ViewBag.SessionId = new SelectList(db.Session, "Id", "Name");
                    //    ViewBag.GuardianTypeId = new SelectList(db.GuardianType, "Id", "Name");
                    //    ViewBag.StudentClassId = new SelectList(studentClass, "Id", "Name");
                    //    ViewBag.GroupId = new SelectList(db.Group, "Id", "Name");
                    //    return View();
                    //}
                    #endregion

                    #region Create Students

                    var student = new Student
                    {
                        Name             = viewModel.StudentName,
                        FatherName       = viewModel.FatherName,
                        MotherName       = viewModel.MotherName,
                        DateOfBirth      = viewModel.DateOfBirth,
                        Email            = viewModel.StudentEmail,
                        PresentAddress   = viewModel.PresentAddress,
                        ParmanentAddress = viewModel.ParmanentAddress,
                        Religion         = viewModel.Religion,
                        Gender           = viewModel.Gender
                    };
                    if (StudentImage != null && StudentImage.ContentLength > 0)
                    {
                        using (var reader = new System.IO.BinaryReader(StudentImage.InputStream))
                        {
                            student.Image = reader.ReadBytes(StudentImage.ContentLength);
                        }
                    }
                    db.Student.Add(student);
                    db.SaveChanges();

                    int studentId = student.Id;
                    #endregion

                    #region Create Guardian
                    if (viewModel.GuardianName != null)
                    {
                        var guardian = new Guardian
                        {
                            Name           = viewModel.GuardianName,
                            Email          = viewModel.GuardianEmail,
                            Phone          = viewModel.GuardianPhone,
                            NID            = viewModel.NID,
                            GuardianTypeId = viewModel.GuardianTypeId,
                            StudentId      = studentId
                        };

                        db.Guardian.Add(guardian);
                        db.SaveChanges();
                    }

                    #endregion

                    #region Create Admission
                    if (viewModel.SessionId != 0)
                    {
                        var admission = new Admission
                        {
                            AdmissionDate       = viewModel.AdmissionDate,
                            SessionId           = viewModel.SessionId,
                            PreviousSchool      = viewModel.PreviousSchool,
                            PreviousSchoolAddrs = viewModel.PreviousSchoolAddrs,
                            StudentClassId      = viewModel.StudentClassId,
                            GroupId             = viewModel.GroupId,
                            StudentId           = studentId
                        };
                        if (Document != null && Document.ContentLength > 0)
                        {
                            using (var reader = new System.IO.BinaryReader(Document.InputStream))
                            {
                                admission.PreviousSchoolDocument = reader.ReadBytes(Document.ContentLength);
                            }
                        }

                        db.Admission.Add(admission);
                        db.SaveChanges();
                    }

                    #endregion

                    #region update Admission Account
                    if (viewModel.ClassFeeId != 0)
                    {
                        var amount      = db.ClassFee.Where(i => i.Id == viewModel.ClassFeeId).Select(a => a.AdmissionFee).FirstOrDefault();
                        var prevBalance = db.AccountList.Where(n => n.Name == "Admission").Select(c => c.CurrentBalance).FirstOrDefault();
                        var newBalance  = prevBalance + amount;
                        ap.UpdateAccountListBalance(1000, newBalance);
                    }

                    #endregion

                    dbTransaction.Commit();
                    return(RedirectToAction("Index", "Students"));
                }
                catch (Exception ex)
                {
                    #region catch
                    string abc = ex.Message + ex.InnerException;
                    dbTransaction.Rollback();

                    var studentClass = db.StudentClass.Select(c => new
                    {
                        Id   = c.Id,
                        Name = c.ClassName.Name + " || " + c.Shift.Name + " ||" + c.Section.Name
                    }).OrderBy(o => o.Name).ToList();
                    ViewBag.SessionId      = new SelectList(db.Session, "Id", "Name");
                    ViewBag.GuardianTypeId = new SelectList(db.GuardianType, "Id", "Name");
                    ViewBag.StudentClassId = new SelectList(studentClass, "Id", "Name");
                    ViewBag.GroupId        = new SelectList(db.Group, "Id", "Name");
                    return(RedirectToAction("Create"));

                    #endregion
                }
            }
        }
Exemplo n.º 17
0
 public int CreateProgram(Programs program)
 {
     context.Programs.Add(program);
     return(context.SaveChanges());
 }
Exemplo n.º 18
0
        public static void Initialize(SchoolDbContext context)
        {
            context.Database.EnsureCreated();

            // 检查是否有学生信息
            if (context.Students.Any())
            {
                return;   //返回,不执行。
            }

            var students = new Student[]
            {
                new Student {
                    RealName = "龙傲天", EnrollmentDate = DateTime.Parse("2005-09-01")
                },
                new Student {
                    RealName = "王尼玛", EnrollmentDate = DateTime.Parse("2002-09-01")
                },
                new Student {
                    RealName = "张全蛋", EnrollmentDate = DateTime.Parse("2003-09-01")
                },
                new Student {
                    RealName = "叶良辰", EnrollmentDate = DateTime.Parse("2002-09-01")
                },
                new Student {
                    RealName = "和珅", EnrollmentDate = DateTime.Parse("2002-09-01")
                },
                new Student {
                    RealName = "纪晓岚", EnrollmentDate = DateTime.Parse("2001-09-01")
                },
                new Student {
                    RealName = "李逍遥", EnrollmentDate = DateTime.Parse("2003-09-01")
                },
                new Student {
                    RealName = "王小虎", EnrollmentDate = DateTime.Parse("2005-09-01")
                }
            };

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

            var courses = new Course[]
            {
                new Course {
                    CourseId = 1050, Title = "数学", Credits = 3
                },
                new Course {
                    CourseId = 4022, Title = "政治", Credits = 3
                },
                new Course {
                    CourseId = 4041, Title = "物理", Credits = 3
                },
                new Course {
                    CourseId = 1045, Title = "化学", Credits = 4
                },
                new Course {
                    CourseId = 3141, Title = "生物", Credits = 4
                },
                new Course {
                    CourseId = 2021, Title = "英语", Credits = 3
                },
                new Course {
                    CourseId = 2042, Title = "历史", Credits = 4
                }
            };

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

            var enrollments = new Enrollment[]
            {
                new Enrollment {
                    StudentId = 1, CourseId = 1050, Grade = CourseGrade.A
                },
                new Enrollment {
                    StudentId = 1, CourseId = 4022, Grade = CourseGrade.C
                },
                new Enrollment {
                    StudentId = 1, CourseId = 4041, Grade = CourseGrade.B
                },
                new Enrollment {
                    StudentId = 2, CourseId = 1045, Grade = CourseGrade.B
                },
                new Enrollment {
                    StudentId = 2, CourseId = 3141, Grade = CourseGrade.F
                },
                new Enrollment {
                    StudentId = 2, CourseId = 2021, Grade = CourseGrade.F
                },
                new Enrollment {
                    StudentId = 3, CourseId = 1050
                },
                new Enrollment {
                    StudentId = 4, CourseId = 1050
                },
                new Enrollment {
                    StudentId = 4, CourseId = 4022, Grade = CourseGrade.F
                },
                new Enrollment {
                    StudentId = 5, CourseId = 4041, Grade = CourseGrade.C
                },
                new Enrollment {
                    StudentId = 6, CourseId = 1045
                },
                new Enrollment {
                    StudentId = 7, CourseId = 3141, Grade = CourseGrade.A
                },
            };

            foreach (Enrollment e in enrollments)
            {
                context.Enrollments.Add(e);
            }
            context.SaveChanges();
        }
Exemplo n.º 19
0
 public void Add(Enrollment _Enrollment)
 {
     context.Enrollments.Add(_Enrollment);
     context.SaveChanges();
 }
Exemplo n.º 20
0
        public static void Initialize(SchoolDbContext context)
        {
            context.Database.EnsureCreated();

            // 检查是否有学生信息
            if (context.Students.Any())
            {
                return; //返回,不执行。
            }


            #region 添加种子学生信息

            var students = new[]
            {
                new Student {
                    RealName = "龙傲天", EnrollmentDate = DateTime.Parse("2005-09-01")
                },
                new Student {
                    RealName = "王尼玛", EnrollmentDate = DateTime.Parse("2002-09-01")
                },
                new Student {
                    RealName = "张全蛋", EnrollmentDate = DateTime.Parse("2003-09-01")
                },
                new Student {
                    RealName = "叶良辰", EnrollmentDate = DateTime.Parse("2002-09-01")
                },
                new Student {
                    RealName = "和珅", EnrollmentDate = DateTime.Parse("2002-09-01")
                },
                new Student {
                    RealName = "纪晓岚", EnrollmentDate = DateTime.Parse("2001-09-01")
                },
                new Student {
                    RealName = "李逍遥", EnrollmentDate = DateTime.Parse("2003-09-01")
                },
                new Student {
                    RealName = "王小虎", EnrollmentDate = DateTime.Parse("2005-09-01")
                }
            };
            foreach (var s in students)
            {
                context.Students.Add(s);
            }
            context.SaveChanges();

            #endregion


            #region 添加种子老师信息

            var instructors = new[]
            {
                new Instructor
                {
                    RealName = "孔子",
                    HireDate = DateTime.Parse("1995-03-11")
                },
                new Instructor
                {
                    RealName = "墨子",
                    HireDate = DateTime.Parse("2003-03-11")
                },
                new Instructor
                {
                    RealName = "荀子",
                    HireDate = DateTime.Parse("1990-03-11")
                },
                new Instructor
                {
                    RealName = "鬼谷子",
                    HireDate = DateTime.Parse("1985-03-11")
                },
                new Instructor
                {
                    RealName = "孟子",
                    HireDate = DateTime.Parse("2003-03-11")
                },
                new Instructor
                {
                    RealName = "朱熹",
                    HireDate = DateTime.Parse("2003-03-11")
                }
            };

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

            #endregion


            #region 添加部门的种子的数据

            var departments = new[]
            {
                new Department
                {
                    Name         = "论语",
                    Budget       = 350000,
                    StartDate    = DateTime.Parse("2017-09-01"),
                    InstructorId = instructors.Single(i => i.RealName == "孟子").Id
                },
                new Department
                {
                    Name         = "兵法",
                    Budget       = 100000,
                    StartDate    = DateTime.Parse("2017-09-01"),
                    InstructorId = instructors.Single(i => i.RealName == "鬼谷子").Id
                },
                new Department
                {
                    Name         = "文言文",
                    Budget       = 350000,
                    StartDate    = DateTime.Parse("2017-09-01"),
                    InstructorId = instructors.Single(i => i.RealName == "朱熹").Id
                },
                new Department
                {
                    Name         = "世界和平",
                    Budget       = 100000,
                    StartDate    = DateTime.Parse("2017-09-01"),
                    InstructorId = instructors.Single(i => i.RealName == "墨子").Id
                }
            };

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

            #endregion


            var courses = new[]
            {
                new Course
                {
                    CourseId     = 1050,
                    Title        = "数学",
                    Credits      = 3,
                    DepartmentId = departments.Single(s => s.Name == "兵法").Id
                },
                new Course
                {
                    CourseId     = 4022,
                    Title        = "政治",
                    Credits      = 3,
                    DepartmentId = departments.Single(s => s.Name == "文言文").Id
                },
                new Course
                {
                    CourseId     = 4041,
                    Title        = "物理",
                    Credits      = 3,
                    DepartmentId = departments.Single(s => s.Name == "兵法").Id
                },
                new Course
                {
                    CourseId     = 1045,
                    Title        = "化学",
                    Credits      = 4,
                    DepartmentId = departments.Single(s => s.Name == "世界和平").Id
                },
                new Course
                {
                    CourseId     = 3141,
                    Title        = "生物",
                    Credits      = 4,
                    DepartmentId = departments.Single(s => s.Name == "论语").Id
                },
                new Course
                {
                    CourseId     = 2021,
                    Title        = "英语",
                    Credits      = 3,
                    DepartmentId = departments.Single(s => s.Name == "论语").Id
                },
                new Course
                {
                    CourseId     = 2042,
                    Title        = "历史",
                    Credits      = 4,
                    DepartmentId = departments.Single(s => s.Name == "文言文").Id
                }
            };


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


            #region 办公室分配的种子数据

            var officeAssignments = new[]
            {
                new OfficeAssignment
                {
                    InstructorId = instructors.Single(i => i.RealName == "孟子").Id,
                    Location     = "逸夫楼 17"
                },
                new OfficeAssignment
                {
                    InstructorId = instructors.Single(i => i.RealName == "朱熹").Id,
                    Location     = "青霞路 27"
                },
                new OfficeAssignment
                {
                    InstructorId = instructors.Single(i => i.RealName == "墨子").Id,
                    Location     = "天府楼 304"
                }
            };

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

            #endregion

            #region 课程老师的种子数据

            var courseInstructors = new[]
            {
                new CourseAssignment
                {
                    CourseId     = courses.Single(c => c.Title == "数学").CourseId,
                    InstructorId = instructors.Single(i => i.RealName == "鬼谷子").Id
                },
                new CourseAssignment
                {
                    CourseId     = courses.Single(c => c.Title == "数学").CourseId,
                    InstructorId = instructors.Single(i => i.RealName == "墨子").Id
                },
                new CourseAssignment
                {
                    CourseId     = courses.Single(c => c.Title == "政治").CourseId,
                    InstructorId = instructors.Single(i => i.RealName == "朱熹").Id
                },
                new CourseAssignment
                {
                    CourseId     = courses.Single(c => c.Title == "化学").CourseId,
                    InstructorId = instructors.Single(i => i.RealName == "墨子").Id
                },
                new CourseAssignment
                {
                    CourseId     = courses.Single(c => c.Title == "生物").CourseId,
                    InstructorId = instructors.Single(i => i.RealName == "孟子").Id
                },
                new CourseAssignment
                {
                    CourseId     = courses.Single(c => c.Title == "英语").CourseId,
                    InstructorId = instructors.Single(i => i.RealName == "孟子").Id
                },
                new CourseAssignment
                {
                    CourseId     = courses.Single(c => c.Title == "物理").CourseId,
                    InstructorId = instructors.Single(i => i.RealName == "鬼谷子").Id
                },
                new CourseAssignment
                {
                    CourseId     = courses.Single(c => c.Title == "历史").CourseId,
                    InstructorId = instructors.Single(i => i.RealName == "朱熹").Id
                }
            };

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

            #endregion


            var enrollments = new[]
            {
                new Enrollment
                {
                    StudentId = students.Single(s => s.RealName == "龙傲天").Id,
                    CourseId  = courses.Single(c => c.Title == "数学").CourseId,
                    Grade     = CourseGrade.A
                },
                new Enrollment
                {
                    StudentId = students.Single(s => s.RealName == "龙傲天").Id,
                    CourseId  = courses.Single(c => c.Title == "政治").CourseId,
                    Grade     = CourseGrade.C
                },
                new Enrollment
                {
                    StudentId = students.Single(s => s.RealName == "龙傲天").Id,
                    CourseId  = courses.Single(c => c.Title == "物理").CourseId,
                    Grade     = CourseGrade.D
                },
                new Enrollment
                {
                    StudentId = students.Single(s => s.RealName == "王尼玛").Id,
                    CourseId  = courses.Single(c => c.Title == "物理").CourseId,
                    Grade     = CourseGrade.F
                },
                new Enrollment
                {
                    StudentId = students.Single(s => s.RealName == "王尼玛").Id,
                    CourseId  = courses.Single(c => c.Title == "化学").CourseId
                },
                new Enrollment
                {
                    StudentId = students.Single(s => s.RealName == "王尼玛").Id,
                    CourseId  = courses.Single(c => c.Title == "生物").CourseId
                },
                new Enrollment
                {
                    StudentId = students.Single(s => s.RealName == "叶良辰").Id,
                    CourseId  = courses.Single(c => c.Title == "英语").CourseId,
                    Grade     = CourseGrade.A
                }, new Enrollment
                {
                    StudentId = students.Single(s => s.RealName == "叶良辰").Id,
                    CourseId  = courses.Single(c => c.Title == "历史").CourseId,
                    Grade     = CourseGrade.D
                },
                new Enrollment
                {
                    StudentId = students.Single(s => s.RealName == "张全蛋").Id,
                    CourseId  = courses.Single(c => c.Title == "英语").CourseId,
                    Grade     = CourseGrade.B
                },
                new Enrollment
                {
                    StudentId = students.Single(s => s.RealName == "张全蛋").Id,
                    CourseId  = courses.Single(c => c.Title == "数学").CourseId,
                    Grade     = CourseGrade.A
                },
                new Enrollment
                {
                    StudentId = students.Single(s => s.RealName == "纪晓岚").Id,
                    CourseId  = courses.Single(c => c.Title == "英语").CourseId
                },
                new Enrollment
                {
                    StudentId = students.Single(s => s.RealName == "王小虎").Id,
                    CourseId  = courses.Single(c => c.Title == "生物").CourseId
                },
                new Enrollment
                {
                    StudentId = students.Single(s => s.RealName == "和珅").Id,
                    CourseId  = courses.Single(c => c.Title == "物理").CourseId,
                    Grade     = CourseGrade.A
                },
                new Enrollment
                {
                    StudentId = students.Single(s => s.RealName == "和珅").Id,
                    CourseId  = courses.Single(c => c.Title == "英语").CourseId
                }
            };
            foreach (var e in enrollments)
            {
                context.Enrollments.Add(e);
            }
            context.SaveChanges();
        }
Exemplo n.º 21
0
        private void CreateRolesAndUsers()
        {
            // Admin role

            var adminRole = _context.Roles.IgnoreQueryFilters().FirstOrDefault(r => r.TenantId == _tenantId && r.Name == StaticRoleNames.Tenants.Admin);

            if (adminRole == null)
            {
                adminRole = _context.Roles.Add(new Role(_tenantId, StaticRoleNames.Tenants.Admin, StaticRoleNames.Tenants.Admin)
                {
                    IsStatic = true
                }).Entity;
                _context.SaveChanges();
            }

            // Grant all permissions to admin role

            var grantedPermissions = _context.Permissions.IgnoreQueryFilters()
                                     .OfType <RolePermissionSetting>()
                                     .Where(p => p.TenantId == _tenantId && p.RoleId == adminRole.Id)
                                     .Select(p => p.Name)
                                     .ToList();

            var permissions = PermissionFinder
                              .GetAllPermissions(new AppAuthorizationProvider(true))
                              .Where(p => p.MultiTenancySides.HasFlag(MultiTenancySides.Tenant) &&
                                     !grantedPermissions.Contains(p.Name))
                              .ToList();

            if (permissions.Any())
            {
                _context.Permissions.AddRange(
                    permissions.Select(permission => new RolePermissionSetting
                {
                    TenantId  = _tenantId,
                    Name      = permission.Name,
                    IsGranted = true,
                    RoleId    = adminRole.Id
                })
                    );
                _context.SaveChanges();
            }

            // Admin user

            var adminUser = _context.Users.IgnoreQueryFilters().FirstOrDefault(u => u.TenantId == _tenantId && u.UserName == AbpUserBase.AdminUserName);

            if (adminUser == null)
            {
                adminUser                  = User.CreateTenantAdminUser(_tenantId, "*****@*****.**");
                adminUser.Password         = new PasswordHasher <User>(new OptionsWrapper <PasswordHasherOptions>(new PasswordHasherOptions())).HashPassword(adminUser, "123qwe");
                adminUser.IsEmailConfirmed = true;
                adminUser.IsActive         = true;
                _context.Users.Add(adminUser);
                _context.SaveChanges();

                // Assign Admin role to admin user
                _context.UserRoles.Add(new UserRole(_tenantId, adminUser.Id, adminRole.Id));
                _context.SaveChanges();

                // User account of admin user
                if (_tenantId == 1)
                {
                    _context.UserAccounts.Add(new UserAccount
                    {
                        TenantId     = _tenantId,
                        UserId       = adminUser.Id,
                        UserName     = AbpUserBase.AdminUserName,
                        EmailAddress = adminUser.EmailAddress
                    });
                    _context.SaveChanges();
                }
            }

            //  CreateSuperAdminsFromDb(adminRole);
        }
Exemplo n.º 22
0
 public void Create(Student student)
 {
     _context.Students.Add(student);
     _context.SaveChanges();
 }
Exemplo n.º 23
0
 public void AddRequest(Request request)
 {
     _context.Requests.Add(request);
     _context.SaveChanges();
 }