private void RolesSeeder(SchoolSystemDbContext context) { var roleStore = new RoleStore <IdentityRole>(context); var roleManager = new RoleManager <IdentityRole>(roleStore); var roleAdmin = new IdentityRole() { Name = UserType.Admin }; var roleTeacher = new IdentityRole() { Name = UserType.Teacher }; var roleStudent = new IdentityRole() { Name = UserType.Student }; if (!context.Roles.Any(role => role.Name == UserType.Admin)) { roleManager.Create(roleAdmin); } if (!context.Roles.Any(role => role.Name == UserType.Teacher)) { roleManager.Create(roleTeacher); } if (!context.Roles.Any(role => role.Name == UserType.Student)) { roleManager.Create(roleStudent); } }
private void SeedHomeworks(SchoolSystemDbContext context) { if (context.Homeworks.Any()) { return; } context.Homeworks.AddOrUpdate(new Homework() { Content = "DI Patterns", TimeSent = DateTime.Now }); context.Homeworks.AddOrUpdate(new Homework() { Content = "DI Refactorings", TimeSent = new DateTime(2017, 10, 10) }); context.Homeworks.AddOrUpdate(new Homework() { Content = "DI Refactorings", TimeSent = new DateTime(2017, 10, 10) }); }
public static List <Student> GetAllStudents() { using (SchoolSystemDbContext db = new SchoolSystemDbContext()) { var students = db.Students.ToList(); return(students); } }
public static void AddStudent(Student student) { using (SchoolSystemDbContext db = new SchoolSystemDbContext()) { db.Students.Add(student); db.SaveChanges(); } }
protected override void Seed(SchoolSystemDbContext context) { this.RolesSeeder(context); this.SubjectSeeder(context); this.ClassOfStudentsSeeder(context); this.UsersSeeder(context); this.DaysOfWeekSeeder(context); this.MarksSeeder(context); }
public static void DeleteStudent(int id) { using (SchoolSystemDbContext db = new SchoolSystemDbContext()) { var student = db.Students.FirstOrDefault(s => s.Id == id); if (student != null) { db.Students.Remove(student); db.SaveChanges(); } } }
private void SeedCourses(SchoolSystemDbContext context) { if (context.Courses.Any()) { return; } var course = new Course() { Description = "Learn all about programming", Name = "C#", }; course.Students.Add(context.Students.FirstOrDefault()); }
private void DaysOfWeekSeeder(SchoolSystemDbContext context) { var culture = new System.Globalization.CultureInfo("bg-BG"); context.DaysOfWeek.AddOrUpdate(new DaysOfWeek() { Id = 1, Name = culture.DateTimeFormat.GetDayName(DayOfWeek.Monday) }); context.DaysOfWeek.AddOrUpdate(new DaysOfWeek() { Id = 2, Name = culture.DateTimeFormat.GetDayName(DayOfWeek.Tuesday) }); context.DaysOfWeek.AddOrUpdate(new DaysOfWeek() { Id = 3, Name = culture.DateTimeFormat.GetDayName(DayOfWeek.Wednesday) }); context.DaysOfWeek.AddOrUpdate(new DaysOfWeek() { Id = 4, Name = culture.DateTimeFormat.GetDayName(DayOfWeek.Thursday) }); context.DaysOfWeek.AddOrUpdate(new DaysOfWeek() { Id = 5, Name = culture.DateTimeFormat.GetDayName(DayOfWeek.Friday) }); context.DaysOfWeek.AddOrUpdate(new DaysOfWeek() { Id = 6, Name = culture.DateTimeFormat.GetDayName(DayOfWeek.Saturday) }); context.DaysOfWeek.AddOrUpdate(new DaysOfWeek() { Id = 7, Name = culture.DateTimeFormat.GetDayName(DayOfWeek.Sunday) }); context.SaveChanges(); }
public static void Main(string[] args) { var context = new SchoolSystemDbContext(); var student = context.Students.FirstOrDefault(); var courseToAdd = new Course() { Name = "C# Unit Testing", Description = "Learn all about unit testing in .NET" }; student.Courses.Add(courseToAdd); context.SaveChanges(); }
public static void Main(string[] args) { // Note - you may need to change in ConsoleApp/App.config // connectionString="Data Source=DESKTOP-SDB9NHO\SQLEXPRESS; // the DESKTOP-SDB9NHO\SQLEXPRESS part with the server name on your pc. // You can find it when you start Microsoft SQL Server Management Studio // under Server name SchoolSystemDbContext db = new SchoolSystemDbContext(); Database.SetInitializer(new MigrateDatabaseToLatestVersion <SchoolSystemDbContext, Configuration>()); var student = db.Students.Where(st => st.Name == "Todor Todorov").FirstOrDefault(); db.SaveChanges(); }
private void UsersSeeder(SchoolSystemDbContext context) { var userStore = new UserStore <User>(context); var userManager = new UserManager <User>(userStore); if (!context.Users.Any(u => u.UserName == "*****@*****.**")) { var adminUser = new User { UserName = "******", Email = "*****@*****.**", AvatarPictureUrl = "~/Images/avatars/modified-avatar.png" }; userManager.Create(adminUser, "admin123"); userManager.AddToRole(adminUser.Id, UserType.Admin); } }
private void SeedStudents(SchoolSystemDbContext context) { if (context.Students.Any()) { return; } context.Students.AddOrUpdate(new Student() { Name = "Ivan Ivanov", Number = 12345 }); context.Students.AddOrUpdate(new Student() { Name = "Petko Petkov", Number = 123456 }); }
private void MarksSeeder(SchoolSystemDbContext context) { context.Marks.AddOrUpdate(new Mark() { Id = 1, Name = "Слаб", Value = 2 }); context.Marks.AddOrUpdate(new Mark() { Id = 2, Name = "Среден", Value = 3 }); context.Marks.AddOrUpdate(new Mark() { Id = 3, Name = "Добър", Value = 4 }); context.Marks.AddOrUpdate(new Mark() { Id = 4, Name = "Много добър", Value = 5 }); context.Marks.AddOrUpdate(new Mark() { Id = 5, Name = "Отличен", Value = 6 }); }
private void ClassOfStudentsSeeder(SchoolSystemDbContext context) { context.ClassOfStudents.AddOrUpdate(new ClassOfStudents() { Id = 1, Name = "7 А", SubjectClassOfStudents = new HashSet <SubjectClassOfStudents>() { new SubjectClassOfStudents() { SubjectId = 1, ClassOfStudentsId = 1 }, new SubjectClassOfStudents() { SubjectId = 2, ClassOfStudentsId = 1 }, new SubjectClassOfStudents() { SubjectId = 3, ClassOfStudentsId = 1 }, new SubjectClassOfStudents() { SubjectId = 10, ClassOfStudentsId = 1 }, new SubjectClassOfStudents() { SubjectId = 11, ClassOfStudentsId = 1 }, new SubjectClassOfStudents() { SubjectId = 12, ClassOfStudentsId = 1 } } }); context.SaveChanges(); }
private void SubjectSeeder(SchoolSystemDbContext context) { context.Subjects.AddOrUpdate(new Subject() { Id = 1, Name = "Български", ImageUrl = "~/Images/subject_images/subject1.png" }); context.Subjects.AddOrUpdate(new Subject() { Id = 2, Name = "Литература", ImageUrl = "~/Images/subject_images/subject2.png" }); context.Subjects.AddOrUpdate(new Subject() { Id = 3, Name = "Математика", ImageUrl = "~/Images/subject_images/subject3.png" }); context.Subjects.AddOrUpdate(new Subject() { Id = 4, Name = "Биология", ImageUrl = "~/Images/subject_images/subject4.png" }); context.Subjects.AddOrUpdate(new Subject() { Id = 5, Name = "Физика", ImageUrl = "~/Images/subject_images/subject5.png" }); context.Subjects.AddOrUpdate(new Subject() { Id = 6, Name = "Химия", ImageUrl = "~/Images/subject_images/subject6.png" }); context.Subjects.AddOrUpdate(new Subject() { Id = 7, Name = "Музика", ImageUrl = "~/Images/subject_images/subject7.png" }); context.Subjects.AddOrUpdate(new Subject() { Id = 8, Name = "Рисуване", ImageUrl = "~/Images/subject_images/subject8.png" }); context.Subjects.AddOrUpdate(new Subject() { Id = 9, Name = "Информатика", ImageUrl = "~/Images/subject_images/subject12.png" }); context.Subjects.AddOrUpdate(new Subject() { Id = 10, Name = "География", ImageUrl = "~/Images/subject_images/subject16.png" }); context.Subjects.AddOrUpdate(new Subject() { Id = 11, Name = "Физкултура", ImageUrl = "~/Images/subject_images/subject23.png" }); context.Subjects.AddOrUpdate(new Subject() { Id = 12, Name = "История", ImageUrl = "~/Images/subject_images/subject24.png" }); context.SaveChanges(); }
public StudentService(SchoolSystemDbContext dbContext) { this._dbContext = dbContext; }
public static void Initialize() { Database.SetInitializer(new MigrateDatabaseToLatestVersion <SchoolSystemDbContext, Configuration>()); SchoolSystemDbContext.Create().Database.Initialize(true); }
public StudentSubjectService(Data.SchoolSystemDbContext context, IMapper mapper) { _context = context; _mapper = mapper; }
public ClassService(SchoolSystemDbContext dbContext) { this._dbContext = dbContext; }