Esempio n. 1
0
 public StudentService(IUserManager userManager, ApplicationRoleManager roleManager, IStudentRepository repository, CustomUserStore store, CustomRoleStore roleStore)
 {
     _userManager = userManager;
     _roleManager = roleManager;
     _repository  = repository;
     _store       = store;
     _roleStore   = roleStore;
 }
Esempio n. 2
0
        protected override void Seed(ITHelpDeskSystem.Models.ApplicationDbContext context)
        {
            string[] roles = { "Admin", "ITStaff", "Staff", "ITManager" };

            string adminEmail    = "*****@*****.**";
            string adminUserName = "******";
            string adminPassword = "******";

            // Create roles
            var roleStore   = new CustomRoleStore(context);
            var roleManager = new RoleManager <CustomRole, int>(roleStore);

            foreach (var role in roles)
            {
                if (!roleManager.RoleExists(role))
                {
                    roleManager.Create(new CustomRole {
                        Name = role
                    });
                }
            }

            // Define admin user
            var userStore   = new CustomUserStore(context);
            var userManager = new ApplicationUserManager(userStore);

            //TODO Change the type of the admin user
            var admin = new ApplicationUser
            {
                UserName       = adminUserName,
                Email          = adminEmail,
                EmailConfirmed = true,
                LockoutEnabled = false
            };

            // Create admin user
            if (userManager.FindByName(admin.UserName) == null)
            {
                userManager.Create(admin, adminPassword);
            }

            // Add admin user to admin role
            // roles[0] is "Admin"
            var user = userManager.FindByName(admin.UserName);

            if (!userManager.IsInRole(user.Id, roles[0]))
            {
                userManager.AddToRole(admin.Id, roles[0]);
            }

            //Adding IT Staff
            var ITstaffs = new List <ITStaff>
            {
                new ITStaff {
                    UserName = "******", Email = "*****@*****.**", FirstName = "Jack", LastName = "White", JobTitle = "User support ", Department = "IT Department", ExtensionNumber = "544", Mobile = "0553334445", OfficeNumber = "B17", Speciality = " ", StartingDate = null, Position = " ", IsManager = false,
                },

                new ITStaff {
                    UserName = "******", Email = "*****@*****.**", FirstName = "Jane", LastName = "Black", JobTitle = "Network admin", Department = "IT Department", ExtensionNumber = "577", Mobile = "0553334447", OfficeNumber = "C04", Speciality = " ", StartingDate = null, Position = " ", IsManager = false,
                },

                new ITStaff {
                    UserName = "******", Email = "*****@*****.**", FirstName = "Majid", LastName = "Salem", JobTitle = "SAP specialist", Department = "IT Department", ExtensionNumber = "322", Mobile = "0553334448", OfficeNumber = "C05", Speciality = " ", StartingDate = null, Position = " ", IsManager = false,
                },

                new ITStaff {
                    UserName = "******", Email = "*****@*****.**", FirstName = "Mark", LastName = "Brown", JobTitle = "System engineer", Department = "IT Department", ExtensionNumber = "322", Mobile = "0553334448", OfficeNumber = "C06", Speciality = " ", StartingDate = null, Position = " ", IsManager = false,
                },

                new ITStaff {
                    UserName = "******", Email = "*****@*****.**", FirstName = "Ali", LastName = "Kareem", JobTitle = "Factory technician", Department = "IT Department", ExtensionNumber = "322", Mobile = "0553334448", OfficeNumber = "C06", Speciality = " ", StartingDate = null, Position = " ", IsManager = false,
                },


                new ITStaff {
                    UserName = "******", Email = "*****@*****.**", FirstName = "Mike", LastName = "Smith", JobTitle = "IT manager", Department = "IT Department", ExtensionNumber = "741", Mobile = "0553334448", OfficeNumber = "A13", Speciality = " ", StartingDate = null, Position = " ", IsManager = true,
                },
            };

            foreach (var ITstaff in ITstaffs)
            {
                if (userManager.FindByName(ITstaff.UserName) == null)
                {
                    userManager.Create(ITstaff, "123456");
                }

                var usertemp = userManager.FindByName(ITstaff.UserName);
                if (!userManager.IsInRole(usertemp.Id, roles[1]) && ITstaff.IsManager == false)
                {
                    userManager.AddToRole(usertemp.Id, roles[1]);
                }
                if (ITstaff.IsManager == true)
                {
                    userManager.AddToRole(usertemp.Id, roles[3]);
                }
            }

            //Adding IT Help Desk system admimn
            var IThelpDeskAdmin = new List <ITHelpDeskAdmin>
            {
                new ITHelpDeskAdmin {
                    UserName = "******", Email = "*****@*****.**", FirstName = "Wiliam", LastName = "Allen", JobTitle = "Help desk admin", Department = "IT Department", ExtensionNumber = " ", Mobile = " ", OfficeNumber = " ", Speciality = " ", StartingDate = null, Position = " ", IsManager = false, Degree = "",
                },
            };

            foreach (var ITHelpDeskAdmin in IThelpDeskAdmin)
            {
                if (userManager.FindByName(ITHelpDeskAdmin.UserName) == null)
                {
                    userManager.Create(ITHelpDeskAdmin, "123456");
                }

                var usertemp = userManager.FindByName(ITHelpDeskAdmin.UserName);

                if (!userManager.IsInRole(usertemp.Id, roles[0]))
                {
                    userManager.AddToRole(usertemp.Id, roles[0]);
                }
            }

            //Adding Staff
            var Staffs = new List <Staff>
            {
                new Staff {
                    UserName = "******", Email = "*****@*****.**", FirstName = "Khalid", LastName = "Saad", JobTitle = "Recruiter", Department = "HR", ExtensionNumber = " ", Mobile = " ", OfficeNumber = " ", StaffLevel = " ", ManagerialPosition = ManagerialPosition.Regular,
                },

                new Staff {
                    UserName = "******", Email = "*****@*****.**", FirstName = "Suzan", LastName = "Adam", JobTitle = "Brand manager", Department = "Marketing", ExtensionNumber = " ", Mobile = " ", OfficeNumber = " ", StaffLevel = " ", ManagerialPosition = ManagerialPosition.High,
                },

                new Staff {
                    UserName = "******", Email = "*****@*****.**", FirstName = "Ahmad", LastName = "Ali", JobTitle = "HR manager", Department = "HR", ExtensionNumber = " ", Mobile = " ", OfficeNumber = " ", StaffLevel = " ", ManagerialPosition = ManagerialPosition.High,
                },

                new Staff {
                    UserName = "******", Email = "*****@*****.**", FirstName = "Malek", LastName = "Ahmad", JobTitle = "Sales", Department = "Marketing", ExtensionNumber = " ", Mobile = " ", OfficeNumber = " ", StaffLevel = " ", ManagerialPosition = ManagerialPosition.High,
                },

                new Staff {
                    UserName = "******", Email = "*****@*****.**", FirstName = "Sara", LastName = "Murad", JobTitle = "Sales", Department = "Marketing", ExtensionNumber = " ", Mobile = " ", OfficeNumber = " ", StaffLevel = " ", ManagerialPosition = ManagerialPosition.High,
                },

                new Staff {
                    UserName = "******", Email = "*****@*****.**", FirstName = "Salam", LastName = "Abdulrahman", JobTitle = "Sales", Department = "Marketing", ExtensionNumber = " ", Mobile = " ", OfficeNumber = " ", StaffLevel = " ", ManagerialPosition = ManagerialPosition.High,
                },

                new Staff {
                    UserName = "******", Email = "*****@*****.**", FirstName = "Masood", LastName = "Khan", JobTitle = "Sales", Department = "Marketing", ExtensionNumber = " ", Mobile = " ", OfficeNumber = " ", StaffLevel = " ", ManagerialPosition = ManagerialPosition.High,
                },

                new Staff {
                    UserName = "******", Email = "*****@*****.**", FirstName = "Muhannad", LastName = "Droobi", JobTitle = "Sales", Department = "Marketing", ExtensionNumber = " ", Mobile = " ", OfficeNumber = " ", StaffLevel = " ", ManagerialPosition = ManagerialPosition.High,
                },

                new Staff {
                    UserName = "******", Email = "*****@*****.**", FirstName = "Sana", LastName = "Akram", JobTitle = "Sales", Department = "Marketing", ExtensionNumber = " ", Mobile = " ", OfficeNumber = " ", StaffLevel = " ", ManagerialPosition = ManagerialPosition.High,
                },
            };

            foreach (var staff in Staffs)
            {
                if (userManager.FindByName(staff.UserName) == null)
                {
                    userManager.Create(staff, "123456");
                }

                var usertemp = userManager.FindByName(staff.UserName);
                if (!userManager.IsInRole(usertemp.Id, roles[2]))
                {
                    userManager.AddToRole(usertemp.Id, roles[2]);
                }
            }

            var categories = new List <Category>
            {
                new Category {
                    CategoryName = "Hardware", CategoryDescription = "No description", ITStaffId = ITstaffs.Single(d => d.UserName == "itstaff").Id,
                },

                new Category {
                    CategoryName = "Software", CategoryDescription = "No description", ITStaffId = ITstaffs.Single(d => d.UserName == "itstaff1").Id
                },

                new Category {
                    CategoryName = "SAP", CategoryDescription = "No description", ITStaffId = ITstaffs.Single(d => d.UserName == "itstaff1").Id
                },

                new Category {
                    CategoryName = "WiFi", CategoryDescription = "No description", ITStaffId = ITstaffs.Single(d => d.UserName == "itstaff").Id,
                },

                new Category {
                    CategoryName = "Printer", CategoryDescription = "No description", ITStaffId = ITstaffs.Single(d => d.UserName == "itstaff1").Id,
                },

                new Category {
                    CategoryName = "Email", CategoryDescription = "No description", ITStaffId = ITstaffs.Single(d => d.UserName == "itstaff1").Id,
                },
            };

            categories.ForEach(s => context.Categories.AddOrUpdate(p => p.CategoryName, s));
            context.SaveChanges();

            var tickets = new List <Ticket>
            {
                new Ticket {
                    Subject = "Issue", IncidentDescription = "Cannot log in to email", CategoryId = categories.Single(d => d.CategoryName == "Software").CategoryId, Status = TicketStatus.Closed, CreationDate = DateTime.Now, TicketOwner = Staffs.Single(m => m.UserName == "staff").Id, CreatedBy = Staffs.Single(m => m.UserName == "staff").Id, IncidentSolution = "Follow the steps of resetting password", Priority = TicketPriority.Critical, ResultionDate = DateTime.Now, DueDate = DateTime.Now.AddDays(1), CreatedByName = Staffs.Single(m => m.UserName == "staff").FullName,
                },
            };

            tickets.ForEach(s => context.Tickets.AddOrUpdate(p => p.Subject, s));
            context.SaveChanges();

            var knowledgeBase = new List <KnowledgeBase>
            {
                new KnowledgeBase {
                    CreatedBy = ITstaffs.Single(d => d.UserName == "itstaff1").Id, ITStaffId = ITstaffs.Single(d => d.UserName == "itstaff1").Id, Topic = "Software", CreationDate = DateTime.Now, IncidentTitle = "Uninstall software", IncidentDescription = "For windows users facing any troubles while uninstalling a software", SolutionDescription = "Select a program you wish to uninstall from Control Panel and click either Remove, or Change/Remove"
                },

                new KnowledgeBase {
                    CreatedBy = ITstaffs.Single(d => d.UserName == "itstaff").Id, ITStaffId = ITstaffs.Single(d => d.UserName == "itstaff").Id, Topic = "Hardware", CreationDate = DateTime.Now, IncidentTitle = "Connect to projector", IncidentDescription = "Mac users cannot connect to projector", SolutionDescription = "Connect the video cable then select System Preferences and click the Detect Displays"
                },

                new KnowledgeBase {
                    CreatedBy = ITstaffs.Single(d => d.UserName == "itstaff2").Id, ITStaffId = ITstaffs.Single(d => d.UserName == "itstaff2").Id, Topic = "WiFi", CreationDate = DateTime.Now, IncidentTitle = "Connect to WiFi", IncidentDescription = "Connecting mobile devices to WiFi", SolutionDescription = "Go to your device settings, WiFi options then enter your username and password"
                },

                new KnowledgeBase {
                    CreatedBy = ITstaffs.Single(d => d.UserName == "itstaff").Id, ITStaffId = ITstaffs.Single(d => d.UserName == "itstaff").Id, Topic = "Booting", CreationDate = DateTime.Now, IncidentTitle = "Booting error from disck", IncidentDescription = "Error disck at booting", SolutionDescription = "If you can hear a repeated scraping noise, power off the computer as soon as possible, as there may be a physical problem with the hard disk and you may lose data."
                },


                new KnowledgeBase {
                    CreatedBy = ITstaffs.Single(d => d.UserName == "itstaff").Id, ITStaffId = ITstaffs.Single(d => d.UserName == "itstaff1").Id, Topic = "Connectivity", CreationDate = DateTime.Now, IncidentTitle = "USB not recognized", IncidentDescription = "USB not recognized when blugged in to computer", SolutionDescription = "This method resolves issues where the currently loaded USB driver has become unstable or corrupt. Select Start, type Device Manager in the Search box Select Device Manager from the returned list. Select Disk Drives from the list of hardware Press and hold (or right-click) the USB external hard drive with the issue, and select Uninstall. After the hard drive is uninstalled, unplug the USB cable. Wait for 1 minute and then reconnect the USB cable. The driver should automatically load Check for the USB drive in Windows Explorer"
                },

                new KnowledgeBase {
                    CreatedBy = ITstaffs.Single(d => d.UserName == "itstaff").Id, ITStaffId = ITstaffs.Single(d => d.UserName == "itstaff1").Id, Topic = "Printer", CreationDate = DateTime.Now, IncidentTitle = "Printer jammed", IncidentDescription = "Printer jammed when printing more than 50 pages", SolutionDescription = "Removing a rear access panel Locate the knob or access tab on the back of the printer by or on the panel itself. If it's a knob, move it to the Unlocked position. Remove the panel and carefully pull out the jammed paper. Locate and clear away any small bits of paper that remain. Replace and secure the rear panel. Remove the two-sided printing accessory to clear the paper jam Press both RELEASE buttons on either end of the module at the same time and remove it."
                },

                new KnowledgeBase {
                    CreatedBy = ITstaffs.Single(d => d.UserName == "itstaff").Id, ITStaffId = ITstaffs.Single(d => d.UserName == "itstaff1").Id, Topic = "Email", CreationDate = DateTime.Now, IncidentTitle = "Connot login to email", IncidentDescription = "Connot log in to email feom this computer", SolutionDescription = "Clear the cache and remove cookies only from websites that cause problems. Clear the Cache: Edit > Preferences > Advanced > Network > Cached Web Content: Clear Now, Remove Cookies from sites causing problems: Edit > Preferences > Privacy >  Use custom settings for history  > Cookies:  Show Cookies."
                },

                new KnowledgeBase {
                    CreatedBy = ITstaffs.Single(d => d.UserName == "itstaff").Id, ITStaffId = ITstaffs.Single(d => d.UserName == "itstaff1").Id, Topic = "Software", CreationDate = DateTime.Now, IncidentTitle = "Deleting browse history", IncidentDescription = "Connot log in to email feom this computer", SolutionDescription = "On your computer, open Chrome. At the top right, click More  . Click History   History. On the left, click Clear browsing data. A box will appear. From the drop-down menu, select how much history you want to delete. To clear everything, select the beginning of time. Check the boxes for the info you want Chrome to clear, including “browsing history."
                },
            };

            knowledgeBase.ForEach(s => context.KnowledgeBases.AddOrUpdate(p => p.Topic, s));
            context.SaveChanges();

            var criteria = new List <Criterion>
            {
                new Criterion {
                    CreationDate = DateTime.Now, ActiveCriterion = true, CriterionDescription = "Waiting time", EditionDate = DateTime.Now
                },
                new Criterion {
                    CreationDate = DateTime.Now, ActiveCriterion = true, CriterionDescription = "Effectiveness of the solution", EditionDate = DateTime.Now
                },
                new Criterion {
                    CreationDate = DateTime.Now, ActiveCriterion = true, CriterionDescription = "Friendliness of IT staff", EditionDate = DateTime.Now
                },
                new Criterion {
                    CreationDate = DateTime.Now, ActiveCriterion = true, CriterionDescription = "Overall satisfaction", EditionDate = DateTime.Now
                },
            };

            criteria.ForEach(s => context.Criteria.AddOrUpdate(p => p.CriterionDescription, s));
            context.SaveChanges();
        }
Esempio n. 3
0
        public static async Task SeedUser()
        {
            var user = new ApplicationUser
            {
                UserName           = "******",
                NormalizedUserName = "******",
                Email           = "*****@*****.**",
                NormalizedEmail = "*****@*****.**",
                EmailConfirmed  = true,
                LockoutEnabled  = false,
                SecurityStamp   = Guid.NewGuid().ToString()
            };

            var roleStore = new CustomRoleStore(_context);

            IList <ApplicationRole> roles = new List <ApplicationRole>()
            {
                new ApplicationRole()
                {
                    Name = MembershipConstant.SuperAdmin, NormalizedName = MembershipConstant.SuperAdmin.ToUpper()
                },
                new ApplicationRole()
                {
                    Name = MembershipConstant.Admin, NormalizedName = MembershipConstant.Admin.ToUpper()
                },
                new ApplicationRole()
                {
                    Name = MembershipConstant.Operator, NormalizedName = MembershipConstant.Operator.ToUpper()
                },
                new ApplicationRole()
                {
                    Name = MembershipConstant.Staff, NormalizedName = MembershipConstant.Staff.ToUpper()
                },
                new ApplicationRole()
                {
                    Name = MembershipConstant.Owner, NormalizedName = MembershipConstant.Owner.ToUpper()
                },
                new ApplicationRole()
                {
                    Name = MembershipConstant.Member, NormalizedName = MembershipConstant.Member.ToUpper()
                }
            };

            foreach (var role in roles)
            {
                //var existRole = await roleStore.FindByNameAsync(role.NormalizedName);
                if (!_context.Roles.Any(x => x.Name == role.Name))
                {
                    await roleStore.CreateAsync(new ApplicationRole { Name = role.Name, NormalizedName = role.NormalizedName });
                }
            }

            if (!_context.Users.Any(u => u.UserName == user.UserName))
            {
                var password = new PasswordHasher <ApplicationUser>();
                var hashed   = password.HashPassword(user, "test123!");
                user.PasswordHash = hashed;
                var userStore = new CustomUserStore(_context);
                await userStore.CreateAsync(user);

                await userStore.AddToRoleAsync(user, MembershipConstant.SuperAdmin);
            }
        }
Esempio n. 4
0
        protected override void Seed(ConsumerPanelTestSystemApplication.Models.ApplicationDbContext context)
        {
            //TODO Define roles to add to your app, keep the Admin role first
            string[] roles = { "Admin", "Brand Manager", "Marketing Director", "Requester", "CPT Coordinator", "CRU Manager", "CRU Supervisor", "CRU Member" };

            //TODO Change admin user login information
            string adminEmail    = "*****@*****.**";
            string adminUserName = "******";
            string adminPassword = "******";


            // Create roles
            var roleStore   = new CustomRoleStore(context);
            var roleManager = new RoleManager <CustomRole, int>(roleStore);

            foreach (var role in roles)
            {
                if (!roleManager.RoleExists(role))
                {
                    roleManager.Create(new CustomRole {
                        Name = role
                    });
                }
            }

            // Define admin user
            var userStore   = new CustomUserStore(context);
            var userManager = new ApplicationUserManager(userStore);

            //TODO Change the type of the admin user
            var admin = new ApplicationUser
            {
                UserName       = adminUserName,
                Email          = adminEmail,
                EmailConfirmed = true,
                LockoutEnabled = false
            };

            // Create admin user
            if (userManager.FindByName(admin.UserName) == null)
            {
                userManager.Create(admin, adminPassword);
            }

            // Add admin user to admin role
            // roles[0] is "Admin"
            var user = userManager.FindByName(admin.UserName);

            if (!userManager.IsInRole(user.Id, roles[0]))
            {
                userManager.AddToRole(admin.Id, roles[0]);
            }


            // Add examples of locations.
            var locations = new List <Location>
            {
                new Location {
                    City = "Jeddah", Region = SupervisorRegion.WesternRegion
                },
                new Location {
                    City = "Madina", Region = SupervisorRegion.WesternRegion
                },
                new Location {
                    City = "Riyadh", Region = SupervisorRegion.CentralRegion
                },
                new Location {
                    City = "Dammam", Region = SupervisorRegion.EasternRegion
                },
                new Location {
                    City = "Taif", Region = SupervisorRegion.WesternRegion
                },
                new Location {
                    City = "Khobar", Region = SupervisorRegion.EasternRegion
                },
                new Location {
                    City = "Jubail", Region = SupervisorRegion.EasternRegion
                },
                new Location {
                    City = "Qassim", Region = SupervisorRegion.CentralRegion
                }
            };

            locations.ForEach(s => context.Locations.AddOrUpdate(p => p.City, s));
            context.SaveChanges();


            // Add Marketing Director user.
            var mdUser = new MarketingDirector
            {
                UserName    = "******",
                Email       = "*****@*****.**",
                FirstName   = "Rola",
                LastName    = "Aref",
                PhoneNumber = "0512345678",
                Country     = EmployeeCountry.SaudiArabia,
                City        = EmployeeCity.Dammam,
                Type        = EmployeeType.MarketingDirector,
            };

            userManager.Create(mdUser, "123456");

            var userMD = userManager.FindByName(mdUser.UserName);

            if (!userManager.IsInRole(userMD.Id, roles[2]))
            {
                userManager.AddToRole(mdUser.Id, roles[2]);
            }

            // Add CPT Coordinator user.
            var cptUser = new CPTCoordinator
            {
                UserName    = "******",
                Email       = "*****@*****.**",
                FirstName   = "Carla",
                LastName    = "Attiah",
                PhoneNumber = "0512345678",
                Country     = EmployeeCountry.Lebanon,
                City        = EmployeeCity.Beirut,
                Type        = EmployeeType.CPTCoordinator,
            };

            userManager.Create(cptUser, "123456");

            var userCPT = userManager.FindByName(cptUser.UserName);

            if (!userManager.IsInRole(userCPT.Id, roles[4]))
            {
                userManager.AddToRole(cptUser.Id, roles[4]);
            }

            // Add CRU Manager user.
            var crumUser = new CRUManager
            {
                UserName    = "******",
                Email       = "*****@*****.**",
                FirstName   = "CRUMFN",
                LastName    = "CRUMLN",
                PhoneNumber = "0512345698",
                Country     = EmployeeCountry.SaudiArabia,
                City        = EmployeeCity.Dammam,
                Type        = EmployeeType.CRUManager,
            };

            userManager.Create(crumUser, "123456");

            var userCRUM = userManager.FindByName(crumUser.UserName);

            if (!userManager.IsInRole(userCRUM.Id, roles[5]))
            {
                userManager.AddToRole(crumUser.Id, roles[5]);
            }


            // Add Brand Managers to the database.
            var brandmanagers = new List <BrandManager>
            {
                new BrandManager {
                    UserName    = "******", Email = "*****@*****.**", FirstName = "Ehab", LastName = "Mohamed",
                    PhoneNumber = "0513146789", Country = EmployeeCountry.SaudiArabia, City = EmployeeCity.Dammam,
                    Type        = EmployeeType.BrandManager, ProductDivision = BrandManagerProductDivision.FamilyCare
                },
                new BrandManager {
                    UserName    = "******", Email = "*****@*****.**", FirstName = "Lama", LastName = "Hafez",
                    PhoneNumber = "0518946789", Country = EmployeeCountry.SaudiArabia, City = EmployeeCity.Dammam,
                    Type        = EmployeeType.BrandManager, ProductDivision = BrandManagerProductDivision.FeminineCare
                },
                new BrandManager {
                    UserName    = "******", Email = "*****@*****.**", FirstName = "Maryam", LastName = "Mahfouz",
                    PhoneNumber = "0574146789", Country = EmployeeCountry.SaudiArabia, City = EmployeeCity.Dammam,
                    Type        = EmployeeType.BrandManager, ProductDivision = BrandManagerProductDivision.HouseholdItems
                },
                new BrandManager {
                    UserName    = "******", Email = "*****@*****.**", FirstName = "Mahmoud", LastName = "Shawqy",
                    PhoneNumber = "0574145789", Country = EmployeeCountry.SaudiArabia, City = EmployeeCity.Dammam,
                    Type        = EmployeeType.BrandManager, ProductDivision = BrandManagerProductDivision.BabyCare
                }
            };

            foreach (var brandmanager in brandmanagers)
            {
                if (userManager.FindByName(brandmanager.UserName) == null)
                {
                    userManager.Create(brandmanager, "crus123");
                }

                var usertemp = userManager.FindByName(brandmanager.UserName);
                if (!userManager.IsInRole(usertemp.Id, roles[1]))
                {
                    userManager.AddToRole(usertemp.Id, roles[1]);
                }
            }


            // Add CRU Supervisors to the database.
            var crusupervisors = new List <CRUSupervisor>
            {
                new CRUSupervisor {
                    UserName    = "******", Email = "*****@*****.**", FirstName = "Manal", LastName = "Mahmoud",
                    PhoneNumber = "0513456789", Country = EmployeeCountry.SaudiArabia, City = EmployeeCity.Dammam,
                    Region      = SupervisorRegion.EasternRegion, Type = EmployeeType.CRUSupervisor
                },
                new CRUSupervisor {
                    UserName    = "******", Email = "*****@*****.**", FirstName = "Lamees", LastName = "Gazzaz",
                    PhoneNumber = "0523456654", Country = EmployeeCountry.SaudiArabia, City = EmployeeCity.Jeddah,
                    Region      = SupervisorRegion.WesternRegion, Type = EmployeeType.CRUSupervisor
                },
                new CRUSupervisor {
                    UserName    = "******", Email = "*****@*****.**", FirstName = "Hala", LastName = "Muhammad",
                    PhoneNumber = "0533452589", Country = EmployeeCountry.SaudiArabia, City = EmployeeCity.Riyadh,
                    Region      = SupervisorRegion.CentralRegion, Type = EmployeeType.CRUSupervisor
                }
            };

            foreach (var crusupervisor in crusupervisors)
            {
                if (userManager.FindByName(crusupervisor.UserName) == null)
                {
                    userManager.Create(crusupervisor, "crus123");
                }

                var usertemp = userManager.FindByName(crusupervisor.UserName);
                if (!userManager.IsInRole(usertemp.Id, roles[6]))
                {
                    userManager.AddToRole(usertemp.Id, roles[6]);
                }
            }


            // Add CRU Members to the database.
            var crumembers = new List <CRUMember>
            {
                new CRUMember {
                    UserName    = "******", Email = "*****@*****.**", FirstName = "Hala", LastName = "Farouq",
                    PhoneNumber = "0509637789", Country = EmployeeCountry.SaudiArabia, City = EmployeeCity.Dammam,
                    Region      = SupervisorRegion.WesternRegion, Type = EmployeeType.CRUMember, CRUSupervisorId = 10
                },
                new CRUMember {
                    UserName    = "******", Email = "*****@*****.**", FirstName = "Dalal", LastName = "Ahmed",
                    PhoneNumber = "0508547789", Country = EmployeeCountry.SaudiArabia, City = EmployeeCity.Jeddah,
                    Region      = SupervisorRegion.EasternRegion, Type = EmployeeType.CRUMember, CRUSupervisorId = 9
                },
                new CRUMember {
                    UserName    = "******", Email = "*****@*****.**", FirstName = "Dalia", LastName = "Rami",
                    PhoneNumber = "0589047789", Country = EmployeeCountry.SaudiArabia, City = EmployeeCity.Riyadh,
                    Region      = SupervisorRegion.CentralRegion, Type = EmployeeType.CRUMember, CRUSupervisorId = 11
                },
            };

            foreach (var crumember in crumembers)
            {
                if (userManager.FindByName(crumember.UserName) == null)
                {
                    userManager.Create(crumember, "crum123");
                }

                var usertemp = userManager.FindByName(crumember.UserName);
                if (!userManager.IsInRole(usertemp.Id, roles[7]))
                {
                    userManager.AddToRole(usertemp.Id, roles[7]);
                }
            }


            //// Add Requesters to the database.
            var requesters = new List <Requester>
            {
                new Requester {
                    UserName    = "******", Email = "*****@*****.**", FirstName = "Ramy", LastName = "REQLN",
                    PhoneNumber = "0541236985", Country = EmployeeCountry.SaudiArabia, City = EmployeeCity.Madina,
                    Department  = Department.RD, Position = "Vice President of Research and Development", Type = EmployeeType.Requester
                },
                new Requester {
                    UserName    = "******", Email = "*****@*****.**", FirstName = "George", LastName = "Khalifa",
                    PhoneNumber = "0509689789", Country = EmployeeCountry.SaudiArabia, City = EmployeeCity.Jeddah,
                    Department  = Department.Production, Position = "Assisstant Production Supervisor", Type = EmployeeType.Requester
                },
                new Requester {
                    UserName    = "******", Email = "*****@*****.**", FirstName = "Tony", LastName = "Taleed",
                    PhoneNumber = "0509637019", Country = EmployeeCountry.SaudiArabia, City = EmployeeCity.Riyadh,
                    Department  = Department.QAQC, Position = "Quality Assurance Head", Type = EmployeeType.Requester
                },
                new Requester {
                    UserName    = "******", Email = "*****@*****.**", FirstName = "Sami", LastName = "Shahid",
                    PhoneNumber = "0509685789", Country = EmployeeCountry.SaudiArabia, City = EmployeeCity.Dammam,
                    Department  = Department.Sales, Position = "Regional Sales Supervisor", Type = EmployeeType.Requester
                },
            };

            foreach (var requester in requesters)
            {
                if (userManager.FindByName(requester.UserName) == null)
                {
                    userManager.Create(requester, "req123");
                }

                var usertemp = userManager.FindByName(requester.UserName);
                if (!userManager.IsInRole(usertemp.Id, roles[3]))
                {
                    userManager.AddToRole(usertemp.Id, roles[3]);
                }
            }

            // Add CPT Requests from Requesters to the database.
            var requests = new List <CPTRequest>
            {
                new CPTRequest {
                    RequestTitle    = "Feminine Care Product Campaign", RequestStatus = RequestStatus.BMRequestApproval,
                    Justification   = "We need some market research in the western regions on the perfomance of feminine care products.",
                    ProductDivision = BrandManagerProductDivision.FeminineCare, RequestDate = new DateTime(2018, 1, 5), SubmittedById = 15, LocationId = 1, BReviewRequest = 6
                },

                new CPTRequest {
                    RequestTitle    = "Bambi Jumbo Launch", RequestStatus = RequestStatus.BMRequestApproval, SubmittedById = 15,
                    Justification   = "We need to get national feedback on the regular Bambi performance to evaluate any neccessary changes.",
                    ProductDivision = BrandManagerProductDivision.BabyCare, RequestDate = new DateTime(2018, 02, 10), LocationId = 2, BReviewRequest = 8
                },

                new CPTRequest {
                    RequestTitle    = "Competition Analysis", RequestStatus = RequestStatus.BMRequestApproval,
                    Justification   = "We want to see how Orenex is performaing in the market, particularly within the Eastern region.",
                    ProductDivision = BrandManagerProductDivision.HouseholdItems, RequestDate = new DateTime(2018, 01, 21), SubmittedById = 17, LocationId = 3, BReviewRequest = 7
                },

                new CPTRequest {
                    RequestTitle    = "Sanita Tissue Annual Assessment", RequestStatus = RequestStatus.BMRequestApproval,
                    Justification   = "The annual performance on the Sanita tissue product needs to be assessed for quality purposes.",
                    ProductDivision = BrandManagerProductDivision.FamilyCare, RequestDate = new DateTime(2018, 03, 15), SubmittedById = 16, LocationId = 4, BReviewRequest = 5
                }
            };

            requests.ForEach(s => context.CPTRequests.AddOrUpdate(p => p.RequestTitle, s));
            context.SaveChanges();


            // Add CPT Requests from Brand Managers to the database.
            var BMrequests = new List <CPTRequest>
            {
                new CPTRequest {
                    RequestTitle    = "Feminine Care Market Positioning", RequestStatus = RequestStatus.MDRequestApproval,
                    Justification   = "We need some market research in the western regions on the perfomance of feminine care products.",
                    ProductDivision = BrandManagerProductDivision.FeminineCare, RequestDate = new DateTime(2018, 1, 5), SubmittedById = 6, LocationId = 1, BReview = Review.Approved, BReviewRequest = 6
                },

                new CPTRequest {
                    RequestTitle    = "Bambi Market Analysis", RequestStatus = RequestStatus.MDRequestApproval,
                    Justification   = "We need to get national feedback on the regular Bambi performance to evaluate any neccessary changes.",
                    ProductDivision = BrandManagerProductDivision.BabyCare, RequestDate = new DateTime(2018, 2, 10), SubmittedById = 8, LocationId = 1, BReview = Review.Approved, BReviewRequest = 8
                },

                new CPTRequest {
                    RequestTitle    = "Tracking Tests for new Sanita Aluminum", RequestStatus = RequestStatus.MDRequestApproval,
                    Justification   = "We want to see how Orenex is performing in the market, particularly within the Eastern region.",
                    ProductDivision = BrandManagerProductDivision.HouseholdItems, RequestDate = new DateTime(2018, 1, 21), SubmittedById = 7, LocationId = 7, BReview = Review.Approved, BReviewRequest = 7
                },

                new CPTRequest {
                    RequestTitle    = "Sanita Market Positioning", RequestStatus = RequestStatus.MDRequestApproval,
                    Justification   = "The annual performance on the Sanita tissue product needs to be assessed for quality purposes.",
                    ProductDivision = BrandManagerProductDivision.FamilyCare, RequestDate = new DateTime(2018, 3, 15), SubmittedById = 5, LocationId = 5, BReview = Review.Approved, BReviewRequest = 5
                },

                // Add CPT Requests for CPT Coordinator Index.
                new CPTRequest {
                    RequestTitle = "Sanita Giant Tissues Performance", RequestStatus = RequestStatus.QuestionnaireCreation, Justification = "We need to assess the performance and likability of the Giant Tissues in order to adjust product accordingly.", ProductDivision = BrandManagerProductDivision.FamilyCare, RequestDate = new DateTime(2018, 3, 28), SubmittedById = 15, LocationId = 5, BReview = Review.Approved, BReviewRequest = 5, MReviewRequest = 2, MReview = Review.Approved
                },

                new CPTRequest {
                    RequestTitle = "Bi-Annual Private Assessment", RequestStatus = RequestStatus.QuestionnaireCreation, Justification = "We need updated information on the product line's performance.", ProductDivision = BrandManagerProductDivision.FeminineCare, RequestDate = new DateTime(2018, 2, 28), SubmittedById = 17, LocationId = 1, BReview = Review.Approved, BReviewRequest = 6, MReviewRequest = 2, MReview = Review.Approved
                },

                new CPTRequest {
                    RequestTitle = "New Product Market Research", RequestStatus = RequestStatus.QuestionnaireCreation, Justification = "We need some preliminary research on the market's acceptance of the new product line.", ProductDivision = BrandManagerProductDivision.FeminineCare, RequestDate = new DateTime(2018, 4, 28), SubmittedById = 15, LocationId = 1, BReview = Review.Approved, BReviewRequest = 6, MReviewRequest = 2, MReview = Review.Approved
                },
            };

            BMrequests.ForEach(s => context.CPTRequests.AddOrUpdate(p => p.RequestTitle, s));
            context.SaveChanges();


            // Add questionnaire types.
            var questionnairetypes = new List <QuestionnaireType>
            {
                new QuestionnaireType {
                    QuestionnaireTypeName = "Performance Tracking"
                },
                new QuestionnaireType {
                    QuestionnaireTypeName = "Product Development"
                },
                new QuestionnaireType {
                    QuestionnaireTypeName = "Tracking Tests"
                },
                new QuestionnaireType {
                    QuestionnaireTypeName = "Product Assessment"
                }
            };

            questionnairetypes.ForEach(s => context.QuestionnaireTypes.AddOrUpdate(p => p.QuestionnaireTypeName, s));
            context.SaveChanges();

            // Add questions.
            var questions = new List <Question>
            {
                new Question {
                    QuestionText = "Did the product cause any rashes or discomforts?"
                },
                new Question {
                    QuestionText = "Are you willing to spend a higher price than the standard for this product?"
                },
                new Question {
                    QuestionText = "Are you likely to purchase a competing product?",
                },
                new Question {
                    QuestionText = "Is price is an important factor when making your decision.",
                },
                new Question {
                    QuestionText = "Is quality is an important factor when purchasing a product like this?"
                },

                new Question {
                    QuestionText = "Do you use NAPCO products often? "
                },
                new Question {
                    QuestionText = "Would you say you are satisfied with your experience with the product?"
                },
                new Question {
                    QuestionText = "Do you purchase NAPCO Products frequently?"
                },
                new Question {
                    QuestionText = "How likely is it that you would recommend us to a friend/colleague?"
                },
                new Question {
                    QuestionText = "Was your impression positive of the product after the trial period?"
                },

                new Question {
                    QuestionText = "Have you used this product?"
                },
                new Question {
                    QuestionText = "How willing would you be to try a new product?"
                },
                new Question {
                    QuestionText = "Do sales and discounts affect your purchase of a particular product?"
                },
                new Question {
                    QuestionText = "Have you used this product?"
                },
                new Question {
                    QuestionText = "Are you willing to pay more for higher quality products?"
                },
            };

            questions.ForEach(s => context.Questions.AddOrUpdate(p => p.QuestionText, s));
            context.SaveChanges();


            // Add questions to question types.
            var questiontypes = new List <QuestionType>
            {
                new QuestionType {
                    QuestionID = 1, QuestionnaireTypeID = 3
                },
                new QuestionType {
                    QuestionID = 1, QuestionnaireTypeID = 4
                },
                new QuestionType {
                    QuestionID = 2, QuestionnaireTypeID = 2
                },
                new QuestionType {
                    QuestionID = 2, QuestionnaireTypeID = 4
                },
                new QuestionType {
                    QuestionID = 3, QuestionnaireTypeID = 1
                },
                new QuestionType {
                    QuestionID = 3, QuestionnaireTypeID = 2
                },

                new QuestionType {
                    QuestionID = 4, QuestionnaireTypeID = 1
                },
                new QuestionType {
                    QuestionID = 4, QuestionnaireTypeID = 4
                },
                new QuestionType {
                    QuestionID = 5, QuestionnaireTypeID = 1
                },
                new QuestionType {
                    QuestionID = 5, QuestionnaireTypeID = 4
                },

                new QuestionType {
                    QuestionID = 6, QuestionnaireTypeID = 2
                },
                new QuestionType {
                    QuestionID = 6, QuestionnaireTypeID = 4
                },
                new QuestionType {
                    QuestionID = 7, QuestionnaireTypeID = 1
                },
                new QuestionType {
                    QuestionID = 7, QuestionnaireTypeID = 2
                },
                new QuestionType {
                    QuestionID = 7, QuestionnaireTypeID = 3
                },
                new QuestionType {
                    QuestionID = 7, QuestionnaireTypeID = 4
                },

                new QuestionType {
                    QuestionID = 8, QuestionnaireTypeID = 1
                },
                new QuestionType {
                    QuestionID = 8, QuestionnaireTypeID = 2
                },
                new QuestionType {
                    QuestionID = 8, QuestionnaireTypeID = 3
                },
                new QuestionType {
                    QuestionID = 8, QuestionnaireTypeID = 4
                },

                new QuestionType {
                    QuestionID = 9, QuestionnaireTypeID = 1
                },
                new QuestionType {
                    QuestionID = 9, QuestionnaireTypeID = 2
                },
                new QuestionType {
                    QuestionID = 9, QuestionnaireTypeID = 3
                },
                new QuestionType {
                    QuestionID = 9, QuestionnaireTypeID = 4
                },
                new QuestionType {
                    QuestionID = 10, QuestionnaireTypeID = 3
                },

                new QuestionType {
                    QuestionID = 11, QuestionnaireTypeID = 1
                },
                new QuestionType {
                    QuestionID = 11, QuestionnaireTypeID = 4
                },
                new QuestionType {
                    QuestionID = 12, QuestionnaireTypeID = 3
                },
                new QuestionType {
                    QuestionID = 12, QuestionnaireTypeID = 2
                },
                new QuestionType {
                    QuestionID = 13, QuestionnaireTypeID = 2
                },

                new QuestionType {
                    QuestionID = 13, QuestionnaireTypeID = 4
                },
                new QuestionType {
                    QuestionID = 14, QuestionnaireTypeID = 1
                },
                new QuestionType {
                    QuestionID = 14, QuestionnaireTypeID = 4
                },
                new QuestionType {
                    QuestionID = 15, QuestionnaireTypeID = 2
                },
                new QuestionType {
                    QuestionID = 15, QuestionnaireTypeID = 4
                }
            };

            questiontypes.ForEach(s => context.QuestionTypes.AddOrUpdate(p => new { p.QuestionID, p.QuestionnaireTypeID }, s));
            context.SaveChanges();


            // Add Additional CRU Members to the database.
            var crumembers2 = new List <CRUMember>
            {
                new CRUMember {
                    UserName    = "******", Email = "*****@*****.**", FirstName = "Hana", LastName = "Mohammed",
                    PhoneNumber = "0509637789", Country = EmployeeCountry.SaudiArabia, City = EmployeeCity.Jeddah,
                    Region      = SupervisorRegion.WesternRegion, Type = EmployeeType.CRUMember, CRUSupervisorId = 9
                },
                new CRUMember {
                    UserName    = "******", Email = "*****@*****.**", FirstName = "Layla", LastName = "Hani",
                    PhoneNumber = "0508547789", Country = EmployeeCountry.SaudiArabia, City = EmployeeCity.Jeddah,
                    Region      = SupervisorRegion.WesternRegion, Type = EmployeeType.CRUMember, CRUSupervisorId = 9
                },
                new CRUMember {
                    UserName    = "******", Email = "*****@*****.**", FirstName = "Sara", LastName = "Ahmed",
                    PhoneNumber = "0589047789", Country = EmployeeCountry.SaudiArabia, City = EmployeeCity.Riyadh,
                    Region      = SupervisorRegion.CentralRegion, Type = EmployeeType.CRUMember, CRUSupervisorId = 11
                },
            };

            foreach (var crumember in crumembers2)
            {
                if (userManager.FindByName(crumember.UserName) == null)
                {
                    userManager.Create(crumember, "crum123");
                }

                var usertemp = userManager.FindByName(crumember.UserName);
                if (!userManager.IsInRole(usertemp.Id, roles[7]))
                {
                    userManager.AddToRole(usertemp.Id, roles[7]);
                }
            }


            //// Add questionnaires for CPT Requests.
            //var questionnaires = new List<Questionnaire>
            //{
            //    new Questionnaire { StartDate = new DateTime (2018,4,30), EndDate = new DateTime(2018,6,20) , ResponseQuantityRequired = 250, QuestionnaireTypeId = 3, Status = QuestionnaireStatus.BMQuestionnaireApproval},

            //    new Questionnaire { StartDate = new DateTime (2018,5,10), EndDate = new DateTime(2018,5,30) , ResponseQuantityRequired = 150, QuestionnaireTypeId = 1, Status = QuestionnaireStatus.BMQuestionnaireApproval},

            //};
            //questionnaires.ForEach(p => context.Questionnaires.AddOrUpdate(q => q.StartDate, p));
            //context.SaveChanges();

            ////Add select questionnaires to link questionnaires to requests.

            //var selectquestionnaires = new List<SelectQuestionnaire>
            //{
            //     new SelectQuestionnaire { RequestID = 11, QuestionnaireID = 1, CPTEmployeeID = 3},

            //     new SelectQuestionnaire { RequestID = 9, QuestionnaireID = 2, CPTEmployeeID = 3}
            //};

            //selectquestionnaires.ForEach(p => context.SelectQuestionnaires.AddOrUpdate(q => q.RequestID, p));
            //context.SaveChanges();

            //// Update requests with questionnaire information.
            //var request9 = requests.Where(r => r.RequestID == 9).First();
            //request9.QuestionnaireId = 2;
            //request9.QuestionnaireExist = true;
            //request9.RequestStatus = RequestStatus.BMQuestionnaireApproval;
            //context.SaveChanges();

            //var request11 = requests.Where(r => r.RequestID == 11).First();
            //request11.QuestionnaireId = 1;
            //request11.QuestionnaireExist = true;
            //request11.RequestStatus = RequestStatus.BMQuestionnaireApproval;
            //context.SaveChanges();
        }
Esempio n. 5
0
        protected override void Seed(ApplicationDbContext context)
        {
            //  Definition of user roles
            string[] roles = { "HRAssociate", "DepartmentHead", "LineManager", "ProbationaryColleague" };

            string adminEmail    = "*****@*****.**";
            string adminUserName = "******";
            string adminPassword = "******";

            // Creation of roles
            var roleStore   = new CustomRoleStore(context);
            var roleManager = new RoleManager <CustomRole, int>(roleStore);

            foreach (var role in roles)
            {
                if (!roleManager.RoleExists(role))
                {
                    roleManager.Create(new CustomRole {
                        Name = role
                    });
                }
            }

            //  Define admin user
            var userStore   = new CustomUserStore(context);
            var userManager = new ApplicationUserManager(userStore);

            // Changing the type of admin user
            var admin = new ApplicationUser
            {
                UserName       = adminUserName,
                Email          = adminEmail,
                EmailConfirmed = true,
                LockoutEnabled = false
            };

            //  Create admin user
            if (userManager.FindByName(admin.UserName) == null)
            {
                userManager.Create(admin, adminPassword);
            }

            //  Add admin user to admin role
            // roles[0] is "HRAssociate"
            var user = userManager.FindByName(admin.UserName);

            if (!userManager.IsInRole(user.Id, roles[0]))
            {
                userManager.AddToRole(admin.Id, roles[0]);
            }


            var departments = new List <Department>
            {
                new Department {
                    DepartmentName = "People's Team"
                },
                new Department {
                    DepartmentName = "Marketing"
                },
                new Department {
                    DepartmentName = "Quality"
                }
            };

            departments.ForEach(s => context.Departments.AddOrUpdate(p => p.DepartmentName, s));
            context.SaveChanges();

            var competencies = new List <Competency>
            {
                new Competency {
                    CompetencyName = "Social Responsibility"
                },
                new Competency {
                    CompetencyName = "Knowledge"
                },
                new Competency {
                    CompetencyName = "Time Management"
                },
                new Competency {
                    CompetencyName = "Taking Initiative"
                },
                new Competency {
                    CompetencyName = "Empathy"
                },
                new Competency {
                    CompetencyName = "Dedication"
                }
            };

            competencies.ForEach(c => context.Competencies.AddOrUpdate(p => p.CompetencyName, c));
            context.SaveChanges();

            //var assignments = new List<Assignment>
            //{
            //         new Assignment { HRAssignId = 2, LMAssignId = 6, PCId = 8, AssignmentStatus = Assignment.AssignStatus.Approved, AssignmentDate = null, AssignmentInspectionDate = null},
            //         new Assignment { HRAssignId = 2, LMAssignId = 7, PCId = 9, AssignmentStatus = Assignment.AssignStatus.Pending, AssignmentDate = null, AssignmentInspectionDate = null},
            //};

            //assignments.ForEach(c => context.Assignments.AddOrUpdate(p => p.AssignmentId.ToString(), c));
            //context.SaveChanges();
            var probationaryColleagues = new List <ProbationaryColleague>
            {
                new ProbationaryColleague {
                    UserName = "******", Email = "*****@*****.**", FirstName = "Probationary", LastName = "Colleague1", ColleagueType = ColleagueType.ProbationaryColleague, EmploymentType = EmploymentType.FullTimer, ColleagueRegion = ColleagueRegion.Jeddah, ProbationType = ProbationaryColleague.ProbationTypes.Mandatory, DOB = null, City = " ", Country = " ", HomeNumber = " ", PhoneNumber = " ", Position = " ", CityOfProbation = ProbationaryColleague.Cities.Jeddah, Level = ProbationaryColleague.Levels.First, JoinDate = null, LeaveDate = null, Nationality = " ", Gender = Gender.Female, DepartmentId = 1,
                },

                new ProbationaryColleague {
                    UserName = "******", Email = "*****@*****.**", FirstName = "Probationary", LastName = "Colleague2", ColleagueType = ColleagueType.ProbationaryColleague, EmploymentType = EmploymentType.FullTimer, ColleagueRegion = ColleagueRegion.Makkah, ProbationType = ProbationaryColleague.ProbationTypes.Mandatory, DOB = null, City = " ", Country = " ", HomeNumber = " ", PhoneNumber = " ", Position = " ", CityOfProbation = ProbationaryColleague.Cities.Jeddah, Level = ProbationaryColleague.Levels.Third, JoinDate = null, LeaveDate = null, Nationality = " ", Gender = Gender.Male, DepartmentId = 2,
                },
            };

            foreach (var ProbationaryColleague in probationaryColleagues)
            {
                if (userManager.FindByName(ProbationaryColleague.UserName) == null)
                {
                    userManager.Create(ProbationaryColleague, "qwe123");
                }

                var usertemp = userManager.FindByName(ProbationaryColleague.UserName);
                if (!userManager.IsInRole(usertemp.Id, roles[3]))
                {
                    userManager.AddToRole(usertemp.Id, roles[3]);
                }
            }

            var LineManagers = new List <Colleague>
            {
                new Colleague {
                    UserName = "******", Email = "*****@*****.**", FirstName = "Line", LastName = "Manager1", ColleagueType = ColleagueType.LineManager, EmploymentType = EmploymentType.FullTimer, ColleagueRegion = ColleagueRegion.Jeddah, DOB = null, City = " ", Country = " ", HomeNumber = " ", PhoneNumber = " ", Position = " ", Nationality = " ", Gender = Gender.Male, DepartmentId = 1,
                },

                new Colleague {
                    UserName = "******", Email = "*****@*****.**", FirstName = "Line", LastName = "Manager2", ColleagueType = ColleagueType.LineManager, EmploymentType = EmploymentType.FullTimer, ColleagueRegion = ColleagueRegion.Makkah, DOB = null, City = " ", Country = " ", HomeNumber = " ", PhoneNumber = " ", Position = " ", Nationality = " ", Gender = Gender.Female, DepartmentId = 2,
                },
            };

            foreach (var Colleague in LineManagers)
            {
                if (userManager.FindByName(Colleague.UserName) == null)
                {
                    userManager.Create(Colleague, "qwe123");
                }

                var usertemp = userManager.FindByName(Colleague.UserName);
                if (!userManager.IsInRole(usertemp.Id, roles[2]))
                {
                    userManager.AddToRole(usertemp.Id, roles[2]);
                }
            }

            var extensions = new List <ExtensionRequest>
            {
                new ExtensionRequest {
                    ExtReason = "Colleague performance is unsatisfactory in this month.", ExtNumber = ProbationaryColleague.Levels.Five, ExtRequestStatus = ExtensionRequest.RequestStatus.Pending, ExtendedPCId = 2, LMSubmitId = 2, ExtRequestAuditDate = null, ExtRequestSubmissionDate = null
                },
                new ExtensionRequest {
                    ExtReason = "Colleague performance is unsatisfactory in this month.", ExtNumber = ProbationaryColleague.Levels.Third, ExtRequestStatus = ExtensionRequest.RequestStatus.Approved, ExtendedPCId = 2, LMSubmitId = 2, ExtRequestAuditDate = null, ExtRequestSubmissionDate = null
                },
            };

            extensions.ForEach(c => context.ExtensionRequests.AddOrUpdate(p => p.ExtReason, c));
            context.SaveChanges();

            var HRAssociates = new List <Colleague>
            {
                new Colleague {
                    UserName = "******", Email = "*****@*****.**", FirstName = "HR", LastName = "Associate1", ColleagueType = ColleagueType.HRAssociate, EmploymentType = EmploymentType.FullTimer, ColleagueRegion = ColleagueRegion.Jeddah, DOB = null, City = " ", Country = " ", HomeNumber = " ", PhoneNumber = " ", Position = " ", Nationality = " ", Gender = Gender.Male, DepartmentId = 1,
                },

                new Colleague {
                    UserName = "******", Email = "*****@*****.**", FirstName = "HR", LastName = "Associate2", ColleagueType = ColleagueType.HRAssociate, EmploymentType = EmploymentType.FullTimer, ColleagueRegion = ColleagueRegion.Makkah, DOB = null, City = " ", Country = " ", HomeNumber = " ", PhoneNumber = " ", Position = " ", Nationality = " ", Gender = Gender.Female, DepartmentId = 1,
                },
            };

            foreach (var Colleague in HRAssociates)
            {
                if (userManager.FindByName(Colleague.UserName) == null)
                {
                    userManager.Create(Colleague, "qwe123");
                }

                var usertemp = userManager.FindByName(Colleague.UserName);
                if (!userManager.IsInRole(usertemp.Id, roles[0]))
                {
                    userManager.AddToRole(usertemp.Id, roles[0]);
                }
            }

            var DepartmentHeads = new List <Colleague>
            {
                new Colleague {
                    UserName = "******", Email = "*****@*****.**", FirstName = "Department", LastName = "Head1", ColleagueType = ColleagueType.DepartmentHead, EmploymentType = EmploymentType.FullTimer, ColleagueRegion = ColleagueRegion.Jeddah, DOB = null, City = " ", Country = " ", HomeNumber = " ", PhoneNumber = " ", Position = " ", Nationality = " ", Gender = Gender.Female, DepartmentId = 1,
                },

                new Colleague {
                    UserName = "******", Email = "*****@*****.**", FirstName = "Department", LastName = "Head2", ColleagueType = ColleagueType.DepartmentHead, EmploymentType = EmploymentType.FullTimer, ColleagueRegion = ColleagueRegion.Makkah, DOB = null, City = " ", Country = " ", HomeNumber = " ", PhoneNumber = " ", Position = " ", Nationality = " ", Gender = Gender.Male, DepartmentId = 2,
                },
            };

            foreach (var Colleague in DepartmentHeads)
            {
                if (userManager.FindByName(Colleague.UserName) == null)
                {
                    userManager.Create(Colleague, "qwe123");
                }

                var usertemp = userManager.FindByName(Colleague.UserName);
                if (!userManager.IsInRole(usertemp.Id, roles[1]))
                {
                    userManager.AddToRole(usertemp.Id, roles[1]);
                }
            }
        }
        protected override void Seed(ApplicationDbContext context)

        {
            // Roles
            string[] roles = { "Admin", "Instructor", "Student" };

            // Admin user login information

            string adminEmail = "*****@*****.**";

            string adminUserName = "******";

            string adminPassword = "******";

            // Create roles
            var roleStore   = new CustomRoleStore(context);
            var roleManager = new RoleManager <CustomRole, int>(roleStore);

            foreach (var role in roles)
            {
                if (!roleManager.RoleExists(role))
                {
                    roleManager.Create(new CustomRole {
                        Name = role
                    });
                }
            }

            // Define admin user
            var userStore   = new CustomUserStore(context);
            var userManager = new ApplicationUserManager(userStore);

            // Type of the admin user

            var admin = new ApplicationUser
            {
                UserName       = adminUserName,
                Email          = adminEmail,
                EmailConfirmed = true,
                LockoutEnabled = false
            };

            // Create admin user
            if (userManager.FindByName(admin.UserName) == null)
            {
                userManager.Create(admin, adminPassword);
            }

            // Add admin user to admin role
            // roles[0] is "Admin"

            var user = userManager.FindByName(admin.UserName);

            if (!userManager.IsInRole(user.Id, roles[0]))
            {
                userManager.AddToRole(admin.Id, roles[0]);
            }

            //Add example of admin employees
            //var employees = new List<Employee>
            //    {
            //          new Employee {
            //              Id = 10,
            //              UserName = "******",
            //              //PasswordHash = "m123123",
            //              EmployeeUniversityId = "2012",
            //              FirstName = "Mervat",
            //              LastName = "Ismail",
            //              Office = "370",
            //              Email = "*****@*****.**",
            //              Phone = "6000012",
            //              Extension = "64",
            //              Mobile = "0543222210",

            //          },
            //    };

            // Add examples of Instructors
            var instructors = new List <Instructor>
            {
                new Instructor
                {
                    Id       = 20,
                    UserName = "******",
                    //PasswordHash = "h123123",
                    EmployeeUniversityId = "1234",
                    FirstName            = "Huda",
                    LastName             = "Saied",
                    Office     = "301",
                    Email      = "*****@*****.**",
                    Phone      = "6000012",
                    Extension  = "55",
                    Mobile     = "0555432123",
                    Department = Department.BusinessAndLaw
                },
                new Instructor
                {
                    Id                   = 21,
                    UserName             = "******",
                    EmployeeUniversityId = "2345",
                    FirstName            = "Salma",
                    LastName             = "Nasif",
                    Office               = "064",
                    Email                = "*****@*****.**",
                    Phone                = "6000012",
                    Extension            = "23",
                    Mobile               = "0543243215",
                    Department           = Department.BusinessAndLaw
                },
                new Instructor
                {
                    Id                   = 22,
                    UserName             = "******",
                    EmployeeUniversityId = "5678",
                    FirstName            = "Hanaa",
                    LastName             = "Haitham",
                    Office               = "211",
                    Email                = "*****@*****.**",
                    Phone                = "6000012",
                    Extension            = "70",
                    Mobile               = "0598734503",
                    Department           = Department.DesignAndArchitecture
                },
                new Instructor
                {
                    Id                   = 23,
                    UserName             = "******",
                    EmployeeUniversityId = "1223",
                    FirstName            = "Samar",
                    LastName             = "Alafan",
                    Office               = "332",
                    Email                = "*****@*****.**",
                    Phone                = "6000012",
                    Extension            = "35",
                    Mobile               = "0543211298",
                    Department           = Department.DesignAndArchitecture
                },
                new Instructor
                {
                    Id                   = 24,
                    UserName             = "******",
                    EmployeeUniversityId = "4503",
                    FirstName            = "Amal",
                    LastName             = "Alsamad",
                    Office               = "119",
                    Email                = "*****@*****.**",
                    Phone                = "6000012",
                    Extension            = "88",
                    Mobile               = "0500054321",
                    Department           = Department.BusinessAndLaw
                }
            };

            string instructorPassword = "******";

            // Instructors user employee login password.

            foreach (var instructor in instructors)
            {
                if (userManager.FindByName(instructor.UserName) == null)
                {
                    userManager.Create(instructor, instructorPassword);
                }

                var usertemp = userManager.FindByName(instructor.UserName);
                if (!userManager.IsInRole(usertemp.Id, roles[1]))
                {
                    userManager.AddToRole(usertemp.Id, roles[1]);
                }
            }

            // Add examples of announceements
            var announcements = new List <Announcement>
            {
                new Announcement {
                    Subject          = "Graphic Design Student Needed",
                    AnnouncementDate = new DateTime(2018, 2, 3),
                    Description      = "Internship opportunity for graphic design students, three students needed, send your portfolio"
                },
                new Announcement {
                    Subject          = "HR Internship opportunity",
                    AnnouncementDate = new DateTime(2018, 2, 11),
                    Description      = "Internhsip student majored in HR needed, three months internship program"
                },
                new Announcement {
                    Subject          = "Coop Program for MIS",
                    AnnouncementDate = new DateTime(2018, 3, 4),
                    Description      = "Savola is offering a trained coop program for MIS students"
                },
                new Announcement {
                    Subject          = "STEAM Challenge",
                    AnnouncementDate = new DateTime(2018, 3, 7),
                    Description      = "Limited opportunity for all student to joing the challenge"
                }
            };

            announcements.ForEach(c => context.Announcements.AddOrUpdate(m => m.Subject, c));
            context.SaveChanges();

            //Add examples of complains
            var complains = new List <Complain>
            {
                new Complain {
                    Title          = "Work place is not friendly",
                    CreationDate   = new DateTime(2018, 3, 20),
                    Description    = "Supervisor has not guid me through the company",
                    ComplainStatus = ComplainStatus.Submitted
                },
                new Complain {
                    Title          = "No place to work",
                    CreationDate   = new DateTime(2018, 3, 17),
                    Description    = "Supervisor has not provide me with an office or desk or a place to work",
                    ComplainStatus = ComplainStatus.InProgress
                },
                new Complain {
                    Title          = "Uncomfortable work environment",
                    CreationDate   = new DateTime(2018, 3, 26),
                    Description    = "The office is crowded with people all the time",
                    ComplainStatus = ComplainStatus.Viewed
                },
            };

            complains.ForEach(c => context.Complains.AddOrUpdate(m => m.Title, c));
            context.SaveChanges();

            // Add examples of firms
            var firms = new List <Firm>
            {
                new Firm {
                    FirmName        = "Unilever",
                    FirmDescription = "Be part of the world’s most successful, purpose-led business. " +
                                      "Work with brands that are well-loved around the world, that improve the lives " +
                                      "of our consumers and the communities around us.",
                    Address           = "8770 King Abdulaziz Branch Rd, Ash Shati, Jeddah 23514-3261",
                    MapLink           = "https://goo.gl/maps/XdUEEe8v4zS2",
                    NumberOfVacencies = 10,
                    IndustryField     = "Consumer Goods",
                    //Supervisors = Supervisor.s
                },
                new Firm {
                    FirmName        = "NCB",
                    FirmDescription = "NCB Capital was launched in 2007 as the investment banking arm of " +
                                      "The National Commercial Bank, the largest bank in Saudi Arabia, " +
                                      "to provide investment banking services to individual, " +
                                      "institutional and corporate clients in the Kingdom.",
                    Address           = "Al Shaty, Jeddah 23513 ",
                    MapLink           = "https://goo.gl/maps/Hs5rjJgj6NA2",
                    NumberOfVacencies = 9,
                    IndustryField     = "Banking and Finance",
                    //Supervisors = Supervisor
                },
                new Firm {
                    FirmName        = "Savola Group",
                    FirmDescription = "With 5.34 billion Saudi Riyals and over 30 thousand employees, " +
                                      "Savola shined as the biggest investment holding group in the Middle East and North Africa, " +
                                      "specialized in foods and retail.",
                    Address           = "Prince Faisal Bin Fahd, Ash Shati, Jeddah 23513",
                    MapLink           = "https://goo.gl/maps/7FyRoS3NSLw",
                    NumberOfVacencies = 2,
                    IndustryField     = "Investment Management",
                },
                new Firm {
                    FirmName        = "Milk Design Studio",
                    FirmDescription = "Milk is a jeddah-based design studio with a global mindset, local assets. " +
                                      "We are focused on brining companies into new challenges to help setting them apart from competitors." +
                                      "Milk studio offers a complete repertoire of marketing communication services; branding, retail branding, " +
                                      "corporate identity design, naming, stationary, packaging, signage, brochures, posters and websites",
                    Address           = "6457 King Abdul Aziz Rd, Al Basatin District, Jeddah 23719",
                    MapLink           = "https://goo.gl/maps/b6ys37Jmvnv",
                    NumberOfVacencies = 8,
                    IndustryField     = "Design",
                },
            };

            firms.ForEach(c => context.Firms.AddOrUpdate(m => m.FirmName, c));
            context.SaveChanges();

            // Add examples of internship courses
            var internshipCourses = new List <InternshipCourse>
            {
                new InternshipCourse {
                    InternshipCourseId = 1,
                    CourseCode         = "BBIS 4403",
                    CourseName         = "Internship: Business Information System",
                    Description        = "Internship course for BIS students.",
                    Credits            = 3,
                },
                new InternshipCourse {
                    InternshipCourseId = 2,
                    CourseCode         = "FINC 4303",
                    CourseName         = "Internship: Banking and finance",
                    Description        = "Internship course for Banking and finance students.",
                    Credits            = 3,
                },
                new InternshipCourse {
                    InternshipCourseId = 3,
                    CourseCode         = "VLCD 3305",
                    CourseName         = "Internship: Visual Communication",
                    Description        = "Internship course for graphic and motion graphic students.",
                    Credits            = 3,
                }
            };

            internshipCourses.ForEach(c => context.InternshipCourses.AddOrUpdate(m => m.CourseName, c));
            context.SaveChanges();

            //Add examples of Sections
            var sections = new List <Section>
            {
                new Section {
                    SectionId          = 1,
                    SectionNumber      = "1",
                    Semester           = Semester.SummerI,
                    Year               = 2018,
                    Capacity           = 20,
                    IntrenshipCourseId = 1,
                },
                new Section {
                    SectionId          = 2,
                    SectionNumber      = "1",
                    Semester           = Semester.Fall,
                    Year               = 2019,
                    Capacity           = 20,
                    IntrenshipCourseId = 2,
                },
                new Section {
                    SectionId          = 3,
                    SectionNumber      = "2",
                    Semester           = Semester.Fall,
                    Year               = 2019,
                    Capacity           = 15,
                    IntrenshipCourseId = 1,
                },
                new Section {
                    SectionId          = 4,
                    SectionNumber      = "2",
                    Semester           = Semester.Spring,
                    Year               = 2019,
                    Capacity           = 10,
                    IntrenshipCourseId = 2,
                }
            };

            sections.ForEach(c => context.Sections.AddOrUpdate(m => m.Semester, c));
            context.SaveChanges();

            // Add examples of students
            var students = new List <Student>
            {
                new Student {
                    Id                  = 50,
                    UserName            = "******",
                    FirstName           = "Abeer",
                    LastName            = "Mohammed",
                    StudentUniversityId = "1510987",
                    Email               = "*****@*****.**",
                    Mobile              = "0555543444",
                    Department          = Department.BusinessAndLaw,
                    Major               = "Marketing",
                    SectionId           = 1,
                },
                new Student {
                    Id                  = 51,
                    UserName            = "******",
                    FirstName           = "Hind",
                    LastName            = "Sameh",
                    StudentUniversityId = "1610098",
                    Email               = "*****@*****.**",
                    Mobile              = "0544432345",
                    Department          = Department.BusinessAndLaw,
                    Major               = "Banking and Finance",
                    SectionId           = 2,
                },
                new Student {
                    Id                  = 52,
                    UserName            = "******",
                    FirstName           = "Doaa",
                    LastName            = "Salamah",
                    StudentUniversityId = "1710989",
                    Email               = "*****@*****.**",
                    Mobile              = "0541231111",
                    Department          = Department.BusinessAndLaw,
                    Major               = "Human Resources",
                    SectionId           = 3,
                },
                new Student {
                    Id                  = 53,
                    UserName            = "******",
                    FirstName           = "Dina",
                    LastName            = "Zamil",
                    StudentUniversityId = "1610009",
                    Email               = "*****@*****.**",
                    Mobile              = "0556777789",
                    Department          = Department.DesignAndArchitecture,
                    Major               = "Interior Design",
                    SectionId           = 1,
                },
                new Student {
                    Id                  = 54,
                    UserName            = "******",
                    FirstName           = "Rola",
                    LastName            = "Samman",
                    StudentUniversityId = "1310000",
                    Email               = "*****@*****.**",
                    Mobile              = "0568868888",
                    Department          = Department.BusinessAndLaw,
                    Major               = "Management Information System",
                    SectionId           = 1,
                },
            };

            string studentPassword = "******";

            foreach (var student in students)
            {
                // Create student user
                if (userManager.FindByName(student.UserName) == null)
                {
                    userManager.Create(student, studentPassword);
                }

                var usertemp = userManager.FindByName(student.UserName);
                if (!userManager.IsInRole(usertemp.Id, roles[2]))
                {
                    userManager.AddToRole(usertemp.Id, roles[2]);
                }
            }

            // Add examples of attendances
            var attendances = new List <Attendance>
            {
                new Attendance {
                    AttendanceId   = 1,
                    AttendanceDate = new DateTime(2018, 2, 3),
                    TimeIn         = new TimeSpan(8, 30, 0),
                    TimeOut        = new TimeSpan(16, 30, 0),
                    Description    = "Observing and learning about the work environment",
                    //StudentId = 50,
                    //FirmId = 1
                },
                new Attendance {
                    AttendanceId   = 2,
                    AttendanceDate = new DateTime(2018, 2, 4),
                    TimeIn         = new TimeSpan(9, 0, 0),
                    TimeOut        = new TimeSpan(17, 0, 0),
                    Description    = "Meeting with the employees and asking them questions",
                    //StudentId = 50,
                    //FirmId = 2
                },
                new Attendance {
                    AttendanceId   = 3,
                    AttendanceDate = new DateTime(2018, 2, 20),
                    TimeIn         = new TimeSpan(8, 0, 0),
                    TimeOut        = new TimeSpan(16, 0, 0),
                    Description    = "Reviewing assigned tasks with the supervisor",
                    //StudentId = 51,
                    //FirmId = 3
                },
                new Attendance {
                    AttendanceId   = 4,
                    AttendanceDate = new DateTime(2018, 2, 21),
                    TimeIn         = new TimeSpan(8, 0, 0),
                    TimeOut        = new TimeSpan(16, 0, 0),
                    Description    = "Discuss next week tasks",
                    //StudentId = 52,
                    //FirmId = 3
                },
            };

            attendances.ForEach(c => context.Attendances.AddOrUpdate(m => m.AttendanceDate, c));
            context.SaveChanges();

            // Add examples of Supervisors
            var supervisors = new List <Supervisor>
            {
                new Supervisor {
                    FirstName  = "Amal",
                    LastName   = "Al-Nahdi",
                    Email      = "*****@*****.**",
                    Phone      = "0126789009",
                    Mobile     = "0566665678",
                    Department = "Human Resources",
                    FirmId     = 1
                },
                new Supervisor {
                    FirstName  = "Zainab",
                    LastName   = "Bin Mahfoz",
                    Email      = "*****@*****.**",
                    Phone      = "0126654321",
                    Mobile     = "0554321234",
                    Department = "Human Resources",
                    FirmId     = 2
                },
                new Supervisor {
                    FirstName  = "Ahmad",
                    LastName   = "Abdulrahman",
                    Email      = "*****@*****.**",
                    Phone      = "01267890000",
                    Mobile     = "0542222212",
                    Department = "Human Resources",
                    FirmId     = 3
                },
            };

            supervisors.ForEach(c => context.Supervisors.AddOrUpdate(m => m.Email, c));
            context.SaveChanges();

            // Add examples of Supervisors
            var visitOnSites = new List <VisitOnSite>
            {
                new VisitOnSite {
                    VisitDate = new DateTime(2018, 3, 3),
                    StartTime = new TimeSpan(8, 30, 0),
                    EndTime   = new TimeSpan(10, 30, 0),
                    Feedback  = "Discussed student progress"
                },
                new VisitOnSite {
                    VisitDate = new DateTime(2018, 3, 6),
                    StartTime = new TimeSpan(10, 0, 0),
                    EndTime   = new TimeSpan(11, 30, 0),
                    Feedback  = "Introduction and dicuss student learning outcome"
                },
                new VisitOnSite {
                    VisitDate = new DateTime(2018, 3, 7),
                    StartTime = new TimeSpan(9, 30, 0),
                    EndTime   = new TimeSpan(11, 0, 0),
                    Feedback  = "Checking student positioning and settlment"
                }
            };

            visitOnSites.ForEach(c => context.VisitOnSites.AddOrUpdate(m => m.VisitDate, c));
            context.SaveChanges();

            // Add Questions in the Supervisor Criterion
            //var supervisorCriterions = new List<SupervisorCriterion>
            //{
            //        new SupervisorCriterion {
            //            SupervisorCriterionId = 1,
            //            Question = "Personal Appearance",
            //        },
            //         new SupervisorCriterion {
            //            SupervisorCriterionId = 2,
            //            Question = "Attendance",
            //        },
            //          new SupervisorCriterion {
            //            SupervisorCriterionId = 3,
            //            Question = "Cooperation",
            //        },
            //          new SupervisorCriterion {
            //            SupervisorCriterionId = 4,
            //            Question = "Sincerity & Dependability",
            //        },
            //          new SupervisorCriterion {
            //            SupervisorCriterionId = 5,
            //            Question = "Interest & Attitude",
            //        },
            //          new SupervisorCriterion {
            //            SupervisorCriterionId = 6,
            //            Question = "Courtesy & Tact",
            //        },
            //          new SupervisorCriterion {
            //            SupervisorCriterionId = 7,
            //            Question = "Self-Confidence",
            //        },
            //          new SupervisorCriterion {
            //            SupervisorCriterionId = 8,
            //            Question = "Enthusiasm",
            //        },
            //          new SupervisorCriterion {
            //            SupervisorCriterionId = 9,
            //            Question = "Judgment",
            //        },
            //          new SupervisorCriterion {
            //            SupervisorCriterionId = 10,
            //            Question = "What traits of the trainee need improvement?",
            //        },
            //          new SupervisorCriterion {
            //            SupervisorCriterionId = 11,
            //            Question = "Speed & Amount of Work",
            //        },
            //          new SupervisorCriterion {
            //            SupervisorCriterionId = 12,
            //            Question = "Follow Directions",
            //        },
            //          new SupervisorCriterion {
            //            SupervisorCriterionId = 13,
            //            Question = "Getting Along with Other Employees",
            //        },
            //          new SupervisorCriterion {
            //            SupervisorCriterionId = 14,
            //            Question = "Work Without Supervision",
            //        },
            //          new SupervisorCriterion {
            //            SupervisorCriterionId = 15,
            //            Question = "Takes Suggestions",
            //        },
            //          new SupervisorCriterion {
            //            SupervisorCriterionId = 16,
            //            Question = "General Knowledge of Work Procedures",
            //        },
            //          new SupervisorCriterion {
            //            SupervisorCriterionId = 17,
            //            Question = "Accuracy of Work",
            //        },
            //          new SupervisorCriterion {
            //            SupervisorCriterionId = 18,
            //            Question = "Neatness of Work",
            //        },
            //          new SupervisorCriterion {
            //            SupervisorCriterionId = 19,
            //            Question = "Other?",
            //        },
            //          new SupervisorCriterion {
            //            SupervisorCriterionId = 20,
            //            Question = "What work habits or abilities of the trainee needs improvement?",
            //        },
            //          new SupervisorCriterion {
            //            SupervisorCriterionId = 21,
            //            Question = "In what respect the student shown improvement?",
            //        },
            //          new SupervisorCriterion {
            //            SupervisorCriterionId = 22,
            //            Question = "Days absent from work:",
            //        },
            //          new SupervisorCriterion {
            //            SupervisorCriterionId = 23,
            //            Question = "Reason:",
            //        },
            //          new SupervisorCriterion {
            //            SupervisorCriterionId = 24,
            //            Question = "Times late for work:",
            //        },
            //          new SupervisorCriterion {
            //            SupervisorCriterionId = 25,
            //            Question = "Reason:",
            //        },
            //          new SupervisorCriterion {
            //            SupervisorCriterionId = 26,
            //            Question = "How does this person compare with other employees added to your staff during this period? (Check one)",
            //        },
            //          new SupervisorCriterion {
            //            SupervisorCriterionId = 27,
            //            Question = "At what position level does this student show potential?",
            //        },
            //          new SupervisorCriterion {
            //            SupervisorCriterionId = 28,
            //            Question = "Confidential remarks and additional comments?",
            //        },
            //};

            //supervisorCriterions.ForEach(c => context.SupervisorCriterions.AddOrUpdate(m => m.Question, c));
            //context.SaveChanges();

            //// Add Questions in the Internship Criterion
            //var internshipCriterions = new List<InternshipCriterion>
            //{
            //        new InternshipCriterion {
            //            InternshipCriterionId = 1,
            //            Question = "Identify the three most important goals that you had set for improving your skills when entering the intern program. (3)",
            //        },
            //        new InternshipCriterion {
            //            InternshipCriterionId = 2,
            //            Question = "List the activities that allowed you to accomplish your goals.",
            //        },
            //        new InternshipCriterion {
            //            InternshipCriterionId = 3,
            //            Question = "Identify the specific types of experiences you encountered that will enhance your employability in your chosen field.",
            //        },
            //        new InternshipCriterion {
            //            InternshipCriterionId = 4,
            //            Question = "Give examples of how your supervisor provided educational leadership, which helped you to grow in your professional development.",
            //        },
            //        new InternshipCriterion {
            //            InternshipCriterionId = 5,
            //            Question = "List the three most positive benefits you derived from the internship experience. (3)",
            //        },
            //        new InternshipCriterion {
            //            InternshipCriterionId = 6,
            //            Question = "List the negative aspects of your internship experience (if any)",
            //        },
            //        new InternshipCriterion {
            //            InternshipCriterionId = 7,
            //            Question = "Would you recommend this internship site to another student?",
            //        },
            //        new InternshipCriterion {
            //            InternshipCriterionId = 8,
            //            Question = "My internship experience was: (please check one)",
            //        },

            //};

            //internshipCriterions.ForEach(c => context.InternshipCriterions.AddOrUpdate(m => m.Question, c));
            //context.SaveChanges();
        }
Esempio n. 7
0
        protected override void Seed(MyDbContext db)
        {
            // Seed roles
            if (!db.Roles.Any(r => r.Name == "admin"))
            {
                var store   = new CustomRoleStore(db);
                var manager = new ApplicationRoleManager(store);
                var role    = new CustomRole("admin");
                manager.Create(role);
            }
            if (!db.Roles.Any(r => r.Name == "user"))
            {
                var store   = new CustomRoleStore(db);
                var manager = new ApplicationRoleManager(store);
                var role    = new CustomRole("user");
                manager.Create(role);
            }
            // Seed admin
            if (!db.Users.Any(u => u.Email == "*****@*****.**"))
            {
                var store   = new CustomUserStore(db);
                var manager = new ApplicationUserManager(store);
                var user    = new ApplicationUser()
                {
                    UserName = "******", Email = "*****@*****.**"
                };
                manager.Create(user, "123123");
                manager.AddToRole(user.Id, "admin");
                //manager.AddToRole(user.Id, "admin");
            }
            // Seed 2 hotels
            Hotel hotel1 = new Hotel {
                Id         = new Guid("2db76e87-a92d-4c43-a3d5-e0671d8fc894"),
                HotelName  = "Hotel #1",
                HotelStars = HotelStars.FiveStarHotel
            };
            Hotel hotel2 = new Hotel
            {
                Id         = new Guid("2db76e87-a92d-4c43-a3d5-e0671d8fc895"),
                HotelName  = "Hotel #2",
                HotelStars = HotelStars.FourStarHotel
            };
            // Seed 2 rooms to the 1st hotel
            Room room1 = new Room
            {
                Id        = new Guid("1d759e1a-b865-4b57-8845-2c7a4cb08e80"),
                HotelId   = hotel1.Id,
                RoomPrice = 201,
                RoomType  = RoomType.Studio
            };
            Room room2 = new Room
            {
                Id        = new Guid("1d759e1a-b865-4b57-8845-2c7a4cb08e81"),
                HotelId   = hotel1.Id,
                RoomPrice = 202,
                RoomType  = RoomType.DeluxeRoom
            };
            // Seed 1 room to the 2nd hotel
            Room room3 = new Room
            {
                Id        = new Guid("1d759e1a-b865-4b57-8845-2c7a4cb08e82"),
                HotelId   = hotel2.Id,
                RoomPrice = 203,
                RoomType  = RoomType.DeluxeRoom
            };

            db.Hotels.AddOrUpdate(hotel1);
            db.Hotels.AddOrUpdate(hotel2);
            db.Rooms.AddOrUpdate(room1);
            db.Rooms.AddOrUpdate(room2);
            db.Rooms.AddOrUpdate(room3);

            db.SaveChanges();
        }
Esempio n. 8
0
        protected override void Seed(WorkflowManagementSystem.Models.ApplicationDbContext context)
        {
            //These are the roles included in the application.
            string[] roles = { "Admin", "CEO", "Event Planner", "Client Service Employee", "Production Employee", "Finance Employee", "Creative Employee" };

            // Admin user login information
            string adminEmail    = "*****@*****.**";
            string adminUserName = "******";
            string adminPassword = "******";

            var roleStore   = new CustomRoleStore(context);
            var roleManager = new RoleManager <CustomRole, int>(roleStore);

            foreach (var role in roles)
            {
                if (!roleManager.RoleExists(role))
                {
                    roleManager.Create(new CustomRole {
                        Name = role
                    });
                }
            }

            // Define admin user
            var userStore   = new CustomUserStore(context);
            var userManager = new ApplicationUserManager(userStore);

            //TODO Change the type of the admin user
            var admin = new ApplicationUser
            {
                UserName       = adminUserName,
                Email          = adminEmail,
                EmailConfirmed = true,
                LockoutEnabled = false
            };

            // Create admin user
            if (userManager.FindByName(admin.UserName) == null)
            {
                userManager.Create(admin, adminPassword);
            }

            // Add admin user to admin role
            // roles[0] is "Admin"
            var user = userManager.FindByName(admin.UserName);

            if (!userManager.IsInRole(user.Id, roles[0]))
            {
                userManager.AddToRole(admin.Id, roles[0]);
            }

            // Add item examples
            var items = new List <Item>
            {
                new Item {
                    Name = "Chair", Description = "Normal sitting chair", UnitCost = 20
                },
                new Item {
                    Name = "Table-Circle", Description = "Circular table", UnitCost = 200
                },
                new Item {
                    Name = "Table-Round", Description = "Rectangular table", UnitCost = 250
                },
                new Item {
                    Name = "Stage", Description = "4 by 4 white stage", UnitCost = 1000
                },
                new Item {
                    Name = "Monitor", Description = "6-inch monitor", UnitCost = 1500
                },
                new Item {
                    Name = "Spotlight", Description = null, UnitCost = 250
                }
            };

            items.ForEach(s => context.Items.AddOrUpdate(p => p.Name, s));
            context.SaveChanges();

            // Add client service employee examples
            var clientServiceEmployees = new List <Employee>
            {
                new Employee {
                    UserName   = "******", Email = "*****@*****.**", FirstName = "Badr",
                    LastName   = "Alsharif", PhoneNumber = "0552323909", JobTitle = EmployeeJobTitle.Director,
                    Department = Department.ClientService, EmployeeType = EmployeeType.ClientService
                },

                new Employee {
                    UserName   = "******", Email = "*****@*****.**", FirstName = "Moneer",
                    LastName   = "Ghalib", PhoneNumber = "0504444442", JobTitle = EmployeeJobTitle.Assistant,
                    Department = Department.ClientService, EmployeeType = EmployeeType.ClientService
                },
            };

            foreach (var employee in clientServiceEmployees)
            {
                if (userManager.FindByName(employee.UserName) == null)
                {
                    userManager.Create(employee, "user123");
                }

                var usertemp = userManager.FindByName(employee.UserName);
                if (!userManager.IsInRole(usertemp.Id, roles[3]))
                {
                    userManager.AddToRole(usertemp.Id, roles[3]);
                }
            }
            // Add production employee examples
            var productionEmployees = new List <Employee>
            {
                new Employee {
                    UserName   = "******", Email = "*****@*****.**", FirstName = "Hamza",
                    LastName   = "Zamil", PhoneNumber = "0500303000", JobTitle = EmployeeJobTitle.Director,
                    Department = Department.Production, EmployeeType = EmployeeType.Production
                },

                new Employee {
                    UserName   = "******", Email = "*****@*****.**", FirstName = "Hashim",
                    LastName   = "Bakr", PhoneNumber = "0500303234", JobTitle = EmployeeJobTitle.Assistant,
                    Department = Department.Production, EmployeeType = EmployeeType.Production
                },
            };

            foreach (var employee in productionEmployees)
            {
                if (userManager.FindByName(employee.UserName) == null)
                {
                    userManager.Create(employee, "user123");
                }

                var usertemp = userManager.FindByName(employee.UserName);
                if (!userManager.IsInRole(usertemp.Id, roles[4]))
                {
                    userManager.AddToRole(usertemp.Id, roles[4]);
                }
            }

            // Add finance employee examples
            var financeEmployees = new List <Employee>
            {
                new Employee {
                    UserName   = "******", Email = "*****@*****.**", FirstName = "Abdullah",
                    LastName   = "Ismail", PhoneNumber = "0505280001", JobTitle = EmployeeJobTitle.Director,
                    Department = Department.Finance, EmployeeType = EmployeeType.Finance
                },

                new Employee {
                    UserName   = "******", Email = "*****@*****.**", FirstName = "Abdulrahman",
                    LastName   = "Qurashi", PhoneNumber = "0505288888", JobTitle = EmployeeJobTitle.Accountant,
                    Department = Department.Finance, EmployeeType = EmployeeType.Finance
                },
            };

            foreach (var employee in financeEmployees)
            {
                if (userManager.FindByName(employee.UserName) == null)
                {
                    userManager.Create(employee, "user123");
                }

                var usertemp = userManager.FindByName(employee.UserName);
                if (!userManager.IsInRole(usertemp.Id, roles[5]))
                {
                    userManager.AddToRole(usertemp.Id, roles[5]);
                }
            }

            // Add creative employee examples
            var creativeEmployees = new List <Employee>
            {
                new Employee {
                    UserName   = "******", Email = "*****@*****.**", FirstName = "Khalid",
                    LastName   = "Madani", PhoneNumber = "0505282232", JobTitle = EmployeeJobTitle.Director,
                    Department = Department.Creative, EmployeeType = EmployeeType.Creative
                },

                new Employee {
                    UserName   = "******", Email = "*****@*****.**", FirstName = "Ali",
                    LastName   = "Amoudi", PhoneNumber = "0555444342", JobTitle = EmployeeJobTitle.Designer,
                    Department = Department.Creative, EmployeeType = EmployeeType.Creative
                },
            };

            foreach (var employee in creativeEmployees)
            {
                if (userManager.FindByName(employee.UserName) == null)
                {
                    userManager.Create(employee, "user123");
                }

                var usertemp = userManager.FindByName(employee.UserName);
                if (!userManager.IsInRole(usertemp.Id, roles[6]))
                {
                    userManager.AddToRole(usertemp.Id, roles[6]);
                }
            }

            // Add CEO example
            var CEOEmployees = new List <Employee>
            {
                new Employee {
                    UserName   = "******", Email = "*****@*****.**", FirstName = "Omar",
                    LastName   = "Mohamed", PhoneNumber = "0505282232", JobTitle = EmployeeJobTitle.Director,
                    Department = null, EmployeeType = EmployeeType.CEO
                },
            };

            foreach (var employee in CEOEmployees)
            {
                if (userManager.FindByName(employee.UserName) == null)
                {
                    userManager.Create(employee, "user123");
                }

                var usertemp = userManager.FindByName(employee.UserName);
                if (!userManager.IsInRole(usertemp.Id, roles[1]))
                {
                    userManager.AddToRole(usertemp.Id, roles[1]);
                }
            }

            // Add language examples
            var languages = new List <Language>
            {
                new Language {
                    Name = "English"
                },
                new Language {
                    Name = "Arabic"
                }
            };

            languages.ForEach(s => context.Languages.AddOrUpdate(p => p.Name, s));
            context.SaveChanges();

            // Add usher examples
            var ushers = new List <Usher>
            {
                new Usher {
                    FirstName  = "Basem", LastName = "Helmi", MobileNumber = "0551212900", DateOfBirth = new DateTime(1996, 12, 2),
                    Gender     = UsherGender.Male, Nationality = "Saudi", City = "Jeddah",
                    LanguageId = languages.Single(d => d.Name == "English").Id, CarAvailability = true, MedicalCard = null
                },

                new Usher {
                    FirstName  = "Layal", LastName = "Attas", MobileNumber = "0501211911", DateOfBirth = new DateTime(1997, 7, 7),
                    Gender     = UsherGender.Female, Nationality = "Saudi", City = "Riyadh",
                    LanguageId = languages.Single(d => d.Name == "Arabic").Id, CarAvailability = true, MedicalCard = null
                },

                new Usher {
                    FirstName  = "Omar", LastName = "Gamdi", MobileNumber = "0500088981", DateOfBirth = new DateTime(1993, 10, 10),
                    Gender     = UsherGender.Male, Nationality = "Saudi", City = "Jeddah",
                    LanguageId = languages.Single(d => d.Name == "English").Id, CarAvailability = true, MedicalCard = null
                },

                new Usher {
                    FirstName  = "Yaser", LastName = "Ghalib", MobileNumber = "0599988999", DateOfBirth = new DateTime(1996, 2, 3),
                    Gender     = UsherGender.Male, Nationality = "Saudi", City = "Jeddah",
                    LanguageId = languages.Single(d => d.Name == "English").Id, CarAvailability = true, MedicalCard = null
                },

                new Usher {
                    FirstName  = "Yara", LastName = "Zamil", MobileNumber = "0500088981", DateOfBirth = new DateTime(1995, 1, 9),
                    Gender     = UsherGender.Female, Nationality = "Saudi", City = "Jeddah",
                    LanguageId = languages.Single(d => d.Name == "English").Id, CarAvailability = true, MedicalCard = null
                },

                new Usher {
                    FirstName  = "Husam", LastName = "Madani", MobileNumber = "0551122281", DateOfBirth = new DateTime(1996, 3, 4),
                    Gender     = UsherGender.Male, Nationality = "Saudi", City = "Riyadh",
                    LanguageId = languages.Single(d => d.Name == "Arabic").Id, CarAvailability = false, MedicalCard = null
                }
            };

            ushers.ForEach(s => context.Ushers.AddOrUpdate(p => p.FirstName, s));
            context.SaveChanges();

            // Add client examples
            var clients = new List <Client>
            {
                new Client {
                    FirstName = "STC", LastName = null, Email = "*****@*****.**", MobileNumber = "0550002000",
                    Street    = "Malik Rd", District = "Shatea", City = "Jeddah"
                },

                new Client {
                    FirstName = "Abdullah", LastName = "Sharif", Email = "*****@*****.**", MobileNumber = "0550001023",
                    Street    = "Malik Rd", District = "Zahraa", City = "Jeddah"
                },

                new Client {
                    FirstName = "Souq Okaz", LastName = null, Email = "*****@*****.**", MobileNumber = "0557707055",
                    Street    = "Al Hamra St.", District = "Al Hamra Dist.", City = "Jeddah"
                },

                new Client {
                    FirstName = "MBC", LastName = null, Email = "*****@*****.**", MobileNumber = "0553303035",
                    Street    = "Al Wasl St.", District = "Al Badaa Dist.", City = "Dubai"
                },

                new Client {
                    FirstName = "Amal", LastName = "khatib", Email = "*****@*****.**", MobileNumber = "0589589897",
                    Street    = "Malik Rd.", District = "Shatea Dist.", City = "Jeddah"
                },
            };

            clients.ForEach(s => context.Clients.AddOrUpdate(p => p.FirstName, s));
            context.SaveChanges();

            // Add event project examples
            var eventprojects = new List <EventProject>
            {
                new EventProject {
                    Name        = "Food festival", EventType = EventProjectType.Festival,
                    Brief       = "The client wants the event to consist of 12 booths(all providing food), a stage with a screen needs to be in the entrance.There should be high security. It is for families.",
                    Street      = "Malik Rd", District = "AlShati Dist", City = "Jeddah", Status = ProjectStatus.Approved,
                    DateCreated = new DateTime(2018, 12, 4), ClientServiceEmployeeId = 2, ClientId = 1
                },

                new EventProject {
                    Name        = "Kids birthday party", EventType = EventProjectType.Birthday,
                    Brief       = "The client wants a theme of superheroes. Tables with games and seats. Should accommodate 20 children and adults.",
                    Street      = "King Abdullah St.", District = "Khaldya Dist.", City = "Dubai", Status = ProjectStatus.Approved,
                    DateCreated = new DateTime(2018, 12, 4), ClientServiceEmployeeId = 2, ClientId = 2
                },

                new EventProject {
                    Name        = "Jeddah Youth Ceremony", EventType = EventProjectType.AwardCeremony,
                    Brief       = "Client requests stage with screen. A table with all awards should be in the center of the stage. Tables and chairs that accommodates 100 people.",
                    Street      = "Prince Naif St.", District = "Murjan Dist.", City = "Jeddah", Status = ProjectStatus.Pending,
                    DateCreated = new DateTime(2018, 12, 4), ClientServiceEmployeeId = 2, ClientId = 4
                },

                new EventProject {
                    Name        = "Artsy", EventType = EventProjectType.Exhibition,
                    Brief       = "The client wants the layout of the event to portray a maze and the design should be colorful. Each section will include an artist who will be displaying his/her artworks. 5 booths serving any kinds of food is required. The entrance should include a table for selling tickets.",
                    Street      = "Madina Rd.", District = "Musaadya Dist.", City = "Jeddah", Status = ProjectStatus.Pending,
                    DateCreated = new DateTime(2018, 12, 4), ClientServiceEmployeeId = 2, ClientId = 4
                },

                new EventProject {
                    Name        = "Makkah Youth Forum", EventType = EventProjectType.AwardCeremony,
                    Brief       = "The client requires a stage in the center with a screen behind the speaker. The hall should accommodate up to 40 people; the front row should have tables in front of the chairs.",
                    Street      = "Om AlQura St.", District = "Muala Dist.", City = "Makkah", Status = ProjectStatus.Pending,
                    DateCreated = new DateTime(2018, 12, 4), ClientServiceEmployeeId = 2, ClientId = 3
                },

                new EventProject {
                    Name        = "Wedding", EventType = EventProjectType.Wedding,
                    Brief       = "The client requests round tables each with 10 chairs. A stage in the center with flowers.",
                    Street      = "Malik Rd.", District = "Shati Dist.", City = "Jeddah", Status = ProjectStatus.Approved,
                    DateCreated = new DateTime(2018, 12, 4), ClientServiceEmployeeId = 2, ClientId = 5
                }
            };

            eventprojects.ForEach(s => context.EventProjects.AddOrUpdate(p => p.Name, s));
            context.SaveChanges();

            // Add project schedule examples
            var projectSchedules = new List <ProjectSchedule>
            {
                new ProjectSchedule {
                    Date = DateTime.Now.AddDays(40), StartTime = TimeSpan.Parse("9:30:00"), EndTime = TimeSpan.Parse("10:30:00"), EventProjectId = 1
                },
                new ProjectSchedule {
                    Date = DateTime.Now.AddDays(41), StartTime = TimeSpan.Parse("9:00:00"), EndTime = TimeSpan.Parse("10:30:00"), EventProjectId = 1
                },
                new ProjectSchedule {
                    Date = DateTime.Now.AddDays(55), StartTime = TimeSpan.Parse("11:00:00"), EndTime = TimeSpan.Parse("17:30:00"), EventProjectId = 2
                },
                new ProjectSchedule {
                    Date = DateTime.Now.AddDays(80), StartTime = TimeSpan.Parse("17:00:00"), EndTime = TimeSpan.Parse("20:30:00"), EventProjectId = 4
                },
                new ProjectSchedule {
                    Date = DateTime.Now.AddDays(81), StartTime = TimeSpan.Parse("18:00:00"), EndTime = TimeSpan.Parse("20:30:00"), EventProjectId = 4
                },
                new ProjectSchedule {
                    Date = DateTime.Now.AddDays(100), StartTime = TimeSpan.Parse("18:00:00"), EndTime = TimeSpan.Parse("23:30:00"), EventProjectId = 3
                },
                new ProjectSchedule {
                    Date = DateTime.Now.AddDays(50), StartTime = TimeSpan.Parse("18:00:00"), EndTime = TimeSpan.Parse("23:30:00"), EventProjectId = 6
                },
            };

            projectSchedules.ForEach(s => context.ProjectSchedules.AddOrUpdate(p => p.Date, s));
            context.SaveChanges();

            //Add usher appointed examples
            var usherAppointeds = new List <UsherAppointed>
            {
                new UsherAppointed {
                    DateAppointed = DateTime.Now, UsherId = 1, EventProjectId = 4, ProductionEmployeeId = 3
                },
                new UsherAppointed {
                    DateAppointed = new DateTime(2018, 4, 3), UsherId = 5, EventProjectId = 4, ProductionEmployeeId = 3
                },
                new UsherAppointed {
                    DateAppointed = new DateTime(2018, 4, 4), UsherId = 2, EventProjectId = 4, ProductionEmployeeId = 3
                },
                new UsherAppointed {
                    DateAppointed = new DateTime(2018, 2, 1), UsherId = 3, EventProjectId = 1, ProductionEmployeeId = 3
                },
                new UsherAppointed {
                    DateAppointed = new DateTime(2018, 2, 2), UsherId = 4, EventProjectId = 1, ProductionEmployeeId = 3
                },
                new UsherAppointed {
                    DateAppointed = new DateTime(2018, 1, 8), UsherId = 5, EventProjectId = 2, ProductionEmployeeId = 3
                },
                new UsherAppointed {
                    DateAppointed = new DateTime(2018, 1, 10), UsherId = 6, EventProjectId = 2, ProductionEmployeeId = 3
                },
                //new UsherAppointed {DateAppointed = new DateTime(2018, 1, 11), UsherId = 7, EventProjectId = 2, ProductionEmployeeId = 3},
                //new UsherAppointed {DateAppointed = new DateTime(2018, 3, 4), UsherId = 6, EventProjectId = 3, ProductionEmployeeId = 3},
                //new UsherAppointed {DateAppointed = new DateTime(2018, 3, 5), UsherId = 1, EventProjectId = 3, ProductionEmployeeId = 3},
                //new UsherAppointed {DateAppointed = new DateTime(2018, 2, 4), UsherId = 6, EventProjectId = 4, ProductionEmployeeId = 3},
            };

            usherAppointeds.ForEach(s => context.UsherAppointeds.AddOrUpdate(p => p.DateAppointed, s));
            context.SaveChanges();

            // Add task assignments examples
            var taskAssignments = new List <TaskAssignment>
            {
                new TaskAssignment {
                    EventProjectId = 4, TaskName = "Add presentation", Description = null, EmployeeId = 2,
                    Deadline       = DateTime.Now.AddDays(20), Priority = TaskAssignment.TaskPriority.Medium,
                    Status         = TaskAssignment.TaskStatus.Pending, AssignmentDate = DateTime.Now, ClientServiceEmployeeId = 2
                },
                new TaskAssignment {
                    EventProjectId = 4, TaskName = "Add Quotation", Description = null, EmployeeId = 6,
                    Deadline       = DateTime.Now.AddDays(30), Priority = TaskAssignment.TaskPriority.High,
                    Status         = TaskAssignment.TaskStatus.Pending, AssignmentDate = DateTime.Now, ClientServiceEmployeeId = 2
                },
                new TaskAssignment {
                    EventProjectId = 4, TaskName = "Add Invoice", Description = null, EmployeeId = 6,
                    Deadline       = DateTime.Now.AddDays(40), Priority = TaskAssignment.TaskPriority.High,
                    Status         = TaskAssignment.TaskStatus.Pending, AssignmentDate = DateTime.Now, ClientServiceEmployeeId = 2
                },
                new TaskAssignment {
                    EventProjectId = 1, TaskName = "Meet with client", Description = null, EmployeeId = 3,
                    Deadline       = DateTime.Now.AddDays(28), Priority = TaskAssignment.TaskPriority.High,
                    Status         = TaskAssignment.TaskStatus.Pending, AssignmentDate = DateTime.Now, ClientServiceEmployeeId = 2
                },
                new TaskAssignment {
                    EventProjectId = 5, TaskName = "Add Event Report Template", Description = null, EmployeeId = 8,
                    Deadline       = DateTime.Now.AddDays(30), Priority = TaskAssignment.TaskPriority.Medium,
                    Status         = TaskAssignment.TaskStatus.Pending, AssignmentDate = DateTime.Now, ClientServiceEmployeeId = 2
                },
                new TaskAssignment {
                    EventProjectId = 5, TaskName = "Add Event Report", Description = null, EmployeeId = 3,
                    Deadline       = DateTime.Now.AddDays(40), Priority = TaskAssignment.TaskPriority.Low,
                    Status         = TaskAssignment.TaskStatus.Pending, AssignmentDate = DateTime.Now, ClientServiceEmployeeId = 2
                },
                new TaskAssignment {
                    EventProjectId = 2, TaskName = "Create Cost Sheet", Description = null, EmployeeId = 4,
                    Deadline       = DateTime.Now.AddDays(40), Priority = TaskAssignment.TaskPriority.High,
                    Status         = TaskAssignment.TaskStatus.Pending, AssignmentDate = DateTime.Now, ClientServiceEmployeeId = 2
                },
                new TaskAssignment {
                    EventProjectId = 2, TaskName = "Assign ushers", Description = null, EmployeeId = 4,
                    Deadline       = DateTime.Now.AddDays(40), Priority = TaskAssignment.TaskPriority.High,
                    Status         = TaskAssignment.TaskStatus.Pending, AssignmentDate = DateTime.Now, ClientServiceEmployeeId = 2
                },
                new TaskAssignment {
                    EventProjectId = 6, TaskName = "Add cost sheet", Description = null, EmployeeId = 4,
                    Deadline       = DateTime.Now.AddDays(100), Priority = TaskAssignment.TaskPriority.Low,
                    Status         = TaskAssignment.TaskStatus.Pending, AssignmentDate = DateTime.Now, ClientServiceEmployeeId = 2
                },
                new TaskAssignment {
                    EventProjectId = 2, TaskName = "Meeting", Description = null, EmployeeId = 4,
                    Deadline       = DateTime.Now.AddDays(5), Priority = TaskAssignment.TaskPriority.High,
                    Status         = TaskAssignment.TaskStatus.Pending, AssignmentDate = DateTime.Now, ClientServiceEmployeeId = 2
                },
            };

            taskAssignments.ForEach(s => context.TaskAssignments.AddOrUpdate(p => p.TaskName, s));
            context.SaveChanges();

            // criterion examples
            var criteria = new List <Criterion>
            {
                new Criterion {
                    Name = "Quality of Work", Description = "The quality of the work or service is up to high standards."
                },
                new Criterion {
                    Name = "Communication", Description = "The level of communication and interaction."
                },
                new Criterion {
                    Name = "Performance", Description = null
                },
                new Criterion {
                    Name = "Overall satisfactory level", Description = "The satisfactory level of the overall result and service."
                },
            };

            criteria.ForEach(s => context.Criteria.AddOrUpdate(p => p.Name, s));
            context.SaveChanges();

            // criterion examples
            var documents = new List <Document>
            {
                new Document {
                    Name = "Quotation", FilePath = "File path", EventProjectId = 4,
                },
                new Document {
                    Name = "Quotation-1", FilePath = "File path", EventProjectId = 1,
                },
                new Document {
                    Name = "Invoice", FilePath = "File path", EventProjectId = 4,
                },
                new Document {
                    Name = "Invoice-1", FilePath = "File path", EventProjectId = 1,
                },
                new Document {
                    Name = "Quotation-2", FilePath = "File path", EventProjectId = 6,
                },
            };

            documents.ForEach(s => context.Documents.AddOrUpdate(p => p.Name, s));
            context.SaveChanges();
        }
        protected override void Seed(ApplicationDbContext context)
        {
            string[] roles = { "Admin", "CEO" };

            string adminEmail    = "*****@*****.**";
            string adminUserName = "******";
            string adminPassword = "******";

            // Create roles
            var roleStore   = new CustomRoleStore(context);
            var roleManager = new RoleManager <CustomRole, int>(roleStore);

            foreach (var role in roles)
            {
                if (!roleManager.RoleExists(role))
                {
                    roleManager.Create(new CustomRole {
                        Name = role
                    });
                }
            }

            // Define admin user
            var userStore   = new CustomUserStore(context);
            var userManager = new ApplicationUserManager(userStore);

            var admin = new ApplicationUser
            {
                UserName       = adminUserName,
                Email          = adminEmail,
                EmailConfirmed = true,
                LockoutEnabled = false
            };

            // Create admin user
            if (userManager.FindByName(admin.UserName) == null)
            {
                userManager.Create(admin, adminPassword);
            }

            // Add admin user to admin role
            // roles[0] is "Admin"
            var user = userManager.FindByName(admin.UserName);

            if (!userManager.IsInRole(user.Id, roles[0]))
            {
                userManager.AddToRole(admin.Id, roles[0]);
            }

            // Create Employee.
            var TM1 = new Employee
            {
                UserName          = "******",
                Email             = "*****@*****.**",
                FirstName         = "Layla",
                MiddleName        = "M.",
                LastName          = "Adam",
                EmployeeType      = EmployeeType.TeamMember,
                HiredDate         = new DateTime(2015, 6, 20),
                NationalIqamaID   = 1231231,
                BankAccountNumber = "1",
                Nationality       = "A",
                DateOfBirth       = new DateTime(2016, 8, 6),
            };

            userManager.Create(TM1, "123123");

            var ceo = userManager.FindByName(TM1.UserName);

            if (!userManager.IsInRole(ceo.Id, roles[1]))
            {
                userManager.AddToRole(ceo.Id, roles[1]);
            }

            var TM2 = new Employee
            {
                UserName          = "******",
                Email             = "*****@*****.**",
                FirstName         = "Sami",
                MiddleName        = "K.",
                LastName          = "Palm",
                EmployeeType      = EmployeeType.TeamMember,
                HiredDate         = new DateTime(2014, 1, 1),
                NationalIqamaID   = 1231231,
                BankAccountNumber = "1",
                Nationality       = "Saudi Arabia",
                DateOfBirth       = new DateTime(2018, 6, 6),
            };

            userManager.Create(TM2, "123123");

            var TM3 = new Employee
            {
                UserName          = "******",
                Email             = "*****@*****.**",
                FirstName         = "Carmen",
                MiddleName        = "B.",
                LastName          = "Inican",
                EmployeeType      = EmployeeType.TeamMember,
                HiredDate         = new DateTime(2017, 9, 10),
                NationalIqamaID   = 1231231,
                BankAccountNumber = "1",
                Nationality       = "Dominican Republic",
                DateOfBirth       = new DateTime(2016, 11, 1),
            };

            userManager.Create(TM3, "123123");

            var TM4 = new Employee
            {
                UserName          = "******",
                Email             = "*****@*****.**",
                FirstName         = "Ahmad",
                MiddleName        = "M.",
                LastName          = "Mali",
                EmployeeType      = EmployeeType.TeamMember,
                HiredDate         = new DateTime(2016, 9, 10),
                NationalIqamaID   = 1231231,
                BankAccountNumber = "1",
                Nationality       = "Dominican Republic",
                DateOfBirth       = new DateTime(2016, 11, 1),
            };

            userManager.Create(TM4, "123123");

            //Achievement
            var achievements = new List <Achievement>
            {
                new Achievement
                {
                    AchievementType = AchievementType.Business,
                    Discription     = "Presented the company at the KMPUL conference",
                    EmployeeId      = context.Employees.Single(c => c.UserName == "member1").Id
                },

                new Achievement
                {
                    AchievementType = AchievementType.NonProfit,
                    Discription     = "Fundraiser for orphans",
                    EmployeeId      = context.Employees.Single(c => c.UserName == "member2").Id
                },

                new Achievement
                {
                    AchievementType = AchievementType.Business,
                    Discription     = "Trained 10 new employees",
                    EmployeeId      = context.Employees.Single(c => c.UserName == "member3").Id
                },

                new Achievement
                {
                    AchievementType = AchievementType.Personal,
                    Discription     = "Wrote a book",
                    EmployeeId      = context.Employees.Single(c => c.UserName == "member4").Id
                }
            };

            achievements.ForEach(s => context.Achievements.AddOrUpdate(m => m.AchievementId, s));
            context.SaveChanges();

            //Experience
            var experiences = new List <Experience>
            {
                new Experience
                {
                    EmploymentPlace = "Google",
                    EmploymentType  = "Manager",
                    StartDate       = new DateTime(2016, 6, 6),
                    EndDate         = new DateTime(2018, 6, 6),
                    Description     = "Managed sales employees.",
                    OrgnizationType = OrgnizationType.Corporate,
                    EmployeeId      = context.Employees.Single(c => c.UserName == "member1").Id
                },

                new Experience
                {
                    EmploymentPlace = "Dah",
                    EmploymentType  = "TA",
                    StartDate       = new DateTime(2015, 7, 6),
                    EndDate         = new DateTime(2016, 9, 1),
                    Description     = "Teaching assestant for MIS major.",
                    OrgnizationType = OrgnizationType.Corporate,
                    EmployeeId      = context.Employees.Single(c => c.UserName == "member2").Id
                },

                new Experience
                {
                    EmploymentPlace = "MIT",
                    EmploymentType  = "Techicnition",
                    StartDate       = new DateTime(2011, 7, 6),
                    EndDate         = new DateTime(2016, 9, 1),
                    Description     = "IT Techicnition.",
                    OrgnizationType = OrgnizationType.Corporate,
                    EmployeeId      = context.Employees.Single(c => c.UserName == "member3").Id
                },

                new Experience
                {
                    EmploymentPlace = "Dah",
                    EmploymentType  = "Manager",
                    StartDate       = new DateTime(2015, 7, 6),
                    EndDate         = new DateTime(2016, 9, 1),
                    Description     = "IT department manager",
                    OrgnizationType = OrgnizationType.Corporate,
                    EmployeeId      = context.Employees.Single(c => c.UserName == "member4").Id
                },
            };

            experiences.ForEach(s => context.Experiences.AddOrUpdate(m => m.ExperienceId, s));
            context.SaveChanges();

            //CommunicationSkill
            var communicationSkills = new List <CommunicationSkill>
            {
                new CommunicationSkill
                {
                    SkillType  = "English",
                    SkillLevel = SkillLevel.Basic,
                    EmployeeId = context.Employees.Single(c => c.UserName == "member1").Id
                },

                new CommunicationSkill
                {
                    SkillType  = "Arabic",
                    SkillLevel = SkillLevel.Professional,
                    EmployeeId = context.Employees.Single(c => c.UserName == "member1").Id
                },

                new CommunicationSkill
                {
                    SkillType  = "Arabic",
                    SkillLevel = SkillLevel.Professional,
                    EmployeeId = context.Employees.Single(c => c.UserName == "member2").Id
                },

                new CommunicationSkill
                {
                    SkillType  = "English",
                    SkillLevel = SkillLevel.Professional,
                    EmployeeId = context.Employees.Single(c => c.UserName == "member2").Id
                },


                new CommunicationSkill
                {
                    SkillType  = "German",
                    SkillLevel = SkillLevel.Intermediate,
                    EmployeeId = context.Employees.Single(c => c.UserName == "member3").Id
                },

                new CommunicationSkill
                {
                    SkillType  = "English",
                    SkillLevel = SkillLevel.Professional,
                    EmployeeId = context.Employees.Single(c => c.UserName == "member3").Id
                },


                new CommunicationSkill
                {
                    SkillType  = "Arabic",
                    SkillLevel = SkillLevel.Professional,
                    EmployeeId = context.Employees.Single(c => c.UserName == "member3").Id
                },

                new CommunicationSkill
                {
                    SkillType  = "German",
                    SkillLevel = SkillLevel.Intermediate,
                    EmployeeId = context.Employees.Single(c => c.UserName == "member3").Id
                },

                new CommunicationSkill
                {
                    SkillType  = "English",
                    SkillLevel = SkillLevel.Professional,
                    EmployeeId = context.Employees.Single(c => c.UserName == "member4").Id
                }
            };

            communicationSkills.ForEach(s => context.CommunicationSkills.AddOrUpdate(m => m.CommunicationSkillId, s));
            context.SaveChanges();

            //Attendance
            var attendances = new List <Attendance>
            {
                new Attendance
                {
                    StartDate            = new DateTime(2017, 1, 1),
                    EndDate              = new DateTime(2014, 6, 6),
                    TargetWorkingHours   = 30,
                    PresentDays          = 30,
                    AbsentDays           = 1,
                    EmployeeWorkingHours = 30,
                    FeedBack             = "",
                    EmployeeId           = context.Employees.Single(c => c.UserName == "member1").Id
                },

                new Attendance
                {
                    StartDate            = new DateTime(2017, 1, 2),
                    EndDate              = new DateTime(2014, 6, 6),
                    TargetWorkingHours   = 30,
                    PresentDays          = 30,
                    AbsentDays           = 1,
                    EmployeeWorkingHours = 30,
                    FeedBack             = "",
                    EmployeeId           = context.Employees.Single(c => c.UserName == "member1").Id
                },


                new Attendance
                {
                    StartDate            = new DateTime(2017, 1, 3),
                    EndDate              = new DateTime(2014, 6, 6),
                    TargetWorkingHours   = 30,
                    PresentDays          = 30,
                    AbsentDays           = 1,
                    EmployeeWorkingHours = 30,
                    FeedBack             = "",
                    EmployeeId           = context.Employees.Single(c => c.UserName == "member1").Id
                },

                new Attendance
                {
                    StartDate            = new DateTime(2016, 6, 7),
                    EndDate              = new DateTime(2016, 6, 6),
                    TargetWorkingHours   = 30,
                    PresentDays          = 30,
                    AbsentDays           = 1,
                    EmployeeWorkingHours = 30,
                    FeedBack             = "",
                    EmployeeId           = context.Employees.Single(c => c.UserName == "member2").Id
                }
            };

            attendances.ForEach(s => context.Attendances.AddOrUpdate(m => m.AttendanceId, s));
            context.SaveChanges();

            //Network
            var networks = new List <Network>
            {
                new Network
                {
                    PlatformType   = PlatformType.Instagram,
                    ContactsNumber = 300,
                    EmployeeId     = context.Employees.Single(c => c.UserName == "member1").Id
                },

                new Network
                {
                    PlatformType   = PlatformType.Instagram,
                    ContactsNumber = 3000,
                    EmployeeId     = context.Employees.Single(c => c.UserName == "member2").Id
                },

                new Network
                {
                    PlatformType   = PlatformType.Facebook,
                    ContactsNumber = 5620,
                    EmployeeId     = context.Employees.Single(c => c.UserName == "member2").Id
                },

                new Network
                {
                    PlatformType   = PlatformType.Twitter,
                    ContactsNumber = 7923,
                    EmployeeId     = context.Employees.Single(c => c.UserName == "member2").Id
                }
            };

            networks.ForEach(s => context.Networks.AddOrUpdate(m => m.NetworkId, s));
            context.SaveChanges();

            // Performances
            var performances = new List <Performance>
            {
                new Performance
                {
                    KPI          = 66,
                    Discipline   = 100,
                    Status       = "",
                    IssueDate    = new DateTime(2018, 1, 1),
                    Comment      = "",
                    Decision     = Decision.Approved,
                    CreationDate = new DateTime(2016, 6, 6),
                    EmployeeId   = context.Employees.Single(c => c.UserName == "member1").Id
                },

                new Performance
                {
                    KPI          = 90,
                    Discipline   = 75,
                    Status       = "",
                    IssueDate    = new DateTime(2018, 2, 1),
                    Comment      = "",
                    Decision     = Decision.Approved,
                    CreationDate = new DateTime(2016, 6, 6),
                    EmployeeId   = context.Employees.Single(c => c.UserName == "member2").Id
                },

                new Performance
                {
                    KPI          = 60,
                    Discipline   = 75,
                    Status       = "",
                    IssueDate    = new DateTime(2018, 2, 1),
                    Comment      = "",
                    Decision     = Decision.Approved,
                    CreationDate = new DateTime(2016, 6, 6),
                    EmployeeId   = context.Employees.Single(c => c.UserName == "member3").Id
                },

                new Performance
                {
                    KPI          = 50,
                    Discipline   = 100,
                    Status       = "",
                    IssueDate    = new DateTime(2018, 2, 1),
                    Comment      = "",
                    Decision     = Decision.Approved,
                    CreationDate = new DateTime(2016, 6, 6),
                    EmployeeId   = context.Employees.Single(c => c.UserName == "member4").Id
                }
            };

            performances.ForEach(s => context.Performances.AddOrUpdate(m => m.PerformanceId, s));
            context.SaveChanges();

            // Certifications
            var certifications = new List <Certification>
            {
                new Certification
                {
                    StartDate       = new DateTime(2004, 9, 6),
                    EndDate         = new DateTime(2008, 1, 1),
                    UniversityRank  = 654,
                    Major           = "MIS",
                    GPA             = 3.5M,
                    Extracurricular = "Astronomy Club",
                    EmployeeId      = context.Employees.Single(c => c.UserName == "member1").Id
                },

                new Certification
                {
                    StartDate       = new DateTime(2004, 9, 6),
                    EndDate         = new DateTime(2008, 1, 1),
                    UniversityRank  = 654,
                    Major           = "MIS",
                    GPA             = 4.0M,
                    Extracurricular = "Astronomy Club",
                    EmployeeId      = context.Employees.Single(c => c.UserName == "member2").Id
                },

                new Certification
                {
                    StartDate       = new DateTime(2006, 1, 1),
                    EndDate         = new DateTime(2010, 1, 1),
                    UniversityRank  = 1000,
                    Major           = "CS",
                    GPA             = 3.9M,
                    Extracurricular = "Literature Club",
                    EmployeeId      = context.Employees.Single(c => c.UserName == "member3").Id
                },

                new Certification
                {
                    StartDate       = new DateTime(2004, 9, 6),
                    EndDate         = new DateTime(2008, 1, 1),
                    UniversityRank  = 1,
                    Major           = "Marketing",
                    GPA             = 4.5M,
                    Extracurricular = "Peer Tutoring",
                    EmployeeId      = context.Employees.Single(c => c.UserName == "member4").Id
                },
            };

            certifications.ForEach(s => context.Certifications.AddOrUpdate(m => m.CertificationId, s));
            context.SaveChanges();

            // Criteria
            var criteria = new List <Criterion>
            {
                new Criterion {
                    Criteria = "(Proactivity) Positive Energy"
                },
                new Criterion {
                    Criteria = "(Proactivity) Taking Initiatives "
                },
                new Criterion {
                    Criteria = "(Proactivity) Action "
                },
                new Criterion {
                    Criteria = "(Organized) Project Managment"
                },
                new Criterion {
                    Criteria = "(Organized) Time Management "
                },
                new Criterion {
                    Criteria = "(Support Others) Functionally"
                },
                new Criterion {
                    Criteria = "(Support Others) Personally"
                },
                new Criterion {
                    Criteria = "(Communication) Listening Skills"
                },
                new Criterion {
                    Criteria = "(Communication) Skills"
                },
                new Criterion {
                    Criteria = "(Development) Knowladge "
                },
                new Criterion {
                    Criteria = "(Dedication) Attitudes "
                },
                new Criterion {
                    Criteria = "(Dedication) Doing their best"
                },
                new Criterion {
                    Criteria = "(Leadership) Having a vision"
                },
                new Criterion {
                    Criteria = "(Leadership) Moving others"
                },
                new Criterion {
                    Criteria = "(Creativity) Doning Something deferent"
                }
            };

            criteria.ForEach(s => context.Criteria.AddOrUpdate(m => m.Criteria, s));
            context.SaveChanges();
        }
Esempio n. 10
0
        protected override void Seed(ApplicationDbContext context)
        {
            //TODO Define roles to add to your app, keep the Admin role first
            string[] roles = { "Admin", "Faculty", "Staff" };

            //TODO Change admin user login information
            string adminEmail    = "*****@*****.**";
            string adminUserName = "******";
            string adminPassword = "******";


            // Create roles
            var roleStore   = new CustomRoleStore(context);
            var roleManager = new RoleManager <CustomRole, int>(roleStore);

            foreach (var role in roles)
            {
                if (!roleManager.RoleExists(role))
                {
                    roleManager.Create(new CustomRole {
                        Name = role
                    });
                }
            }

            // Define admin user
            var userStore   = new CustomUserStore(context);
            var userManager = new ApplicationUserManager(userStore);

            var admin = new Employee
            {
                UserName             = adminUserName,
                Email                = adminEmail,
                EmailConfirmed       = true,
                LockoutEnabled       = false,
                FirstName            = "Admin",
                LastName             = "Admin",
                PhoneNumber          = "0123456789",
                PhoneNumberConfirmed = true,
            };

            // Create admin user
            if (userManager.FindByName(admin.UserName) == null)
            {
                userManager.Create(admin, adminPassword);
            }

            // Add admin user to admin role
            // roles[0] is "Admin"
            var user = userManager.FindByName(admin.UserName);

            if (!userManager.IsInRole(user.Id, roles[0]))
            {
                userManager.AddToRole(admin.Id, roles[0]);
            }

            // Add examples of departments
            var departments = new List <Department>
            {
                new Department {
                    Name = "CS", CreationDate = new DateTime(2018, 1, 13)
                },
                new Department {
                    Name = "MIS", CreationDate = new DateTime(2017, 2, 24)
                },
                new Department {
                    Name = "HR", CreationDate = new DateTime(2017, 3, 30)
                },
                new Department {
                    Name = "IT", CreationDate = new DateTime(2016, 4, 18)
                }
            };

            departments.ForEach(s => context.Departments.AddOrUpdate(p => p.Name, s));
            context.SaveChanges();

            // Add examples of employees
            var employees = new List <Employee>
            {
                new Employee {
                    UserName = "******", Email = "*****@*****.**", FirstName = "Emp1", LastName = "Emp11"
                },
                new Employee {
                    UserName = "******", Email = "*****@*****.**", FirstName = "Emp2", LastName = "Emp22"
                },
                new Employee {
                    UserName = "******", Email = "*****@*****.**", FirstName = "Emp3", LastName = "Emp33"
                },
                new Employee {
                    UserName = "******", Email = "*****@*****.**", FirstName = "Emp4", LastName = "Emp33"
                },
            };

            foreach (var employee in employees)
            {
                if (userManager.FindByName(employee.UserName) == null)
                {
                    userManager.Create(employee, "emp123");
                }

                // Employees are not added to any role
            }

            // Add examples of faculties
            var faculties = new List <Faculty>
            {
                new Faculty {
                    UserName     = "******", Email = "*****@*****.**", FirstName = "Fac1", LastName = "Fac11",
                    Speciality   = "Database", Level = FacultyLevel.Lecturer,
                    DepartmentId = departments.Single(d => d.Name == "CS").Id
                },
                new Faculty {
                    UserName     = "******", Email = "*****@*****.**", FirstName = "Fac2", LastName = "Fac22",
                    Speciality   = "Information Systems", Level = FacultyLevel.AssitantProfessor,
                    DepartmentId = departments.Single(d => d.Name == "MIS").Id
                },
                new Faculty {
                    UserName     = "******", Email = "*****@*****.**", FirstName = "Fac3", LastName = "Fac33",
                    Speciality   = "Networks", Level = FacultyLevel.Lecturer,
                    DepartmentId = departments.Single(d => d.Name == "IT").Id
                },
                new Faculty {
                    UserName     = "******", Email = "*****@*****.**", FirstName = "Fac4", LastName = "Fac44",
                    Speciality   = "Big Data", Level = FacultyLevel.Professor,
                    DepartmentId = departments.Single(d => d.Name == "IT").Id
                },
            };

            foreach (var faculty in faculties)
            {
                if (userManager.FindByName(faculty.UserName) == null)
                {
                    userManager.Create(faculty, "fac123");
                }

                var usertemp = userManager.FindByName(faculty.UserName);
                if (!userManager.IsInRole(usertemp.Id, roles[1]))
                {
                    userManager.AddToRole(usertemp.Id, roles[1]);
                }
            }

            // Add examples of courses
            // NOTE: Check how to initialize a property of type collection: Faculties
            var courses = new List <Course>
            {
                new Course {
                    Code = "BBIS101", Title = "Intro to Computers", Faculties = new List <Faculty>()
                },
                new Course {
                    Code = "BBIS102", Title = "Programming 1", Faculties = new List <Faculty>()
                },
                new Course {
                    Code = "BBIS103", Title = "Data Structures", Faculties = new List <Faculty>()
                },
                new Course {
                    Code = "BBIS201", Title = "Programming 2", Faculties = new List <Faculty>()
                },
                new Course {
                    Code = "BBIS301", Title = "Operating Systems", Faculties = new List <Faculty>()
                },
                new Course {
                    Code = "BBIS401", Title = "Software Engineering", Faculties = new List <Faculty>()
                }
            };

            courses.ForEach(s => context.Courses.AddOrUpdate(p => p.Code, s));
            context.SaveChanges();

            // Assign faculties to courses
            AssignFacultyToCourse(context, courseCode: "BBIS101", facultyLastName: "Fac11"); // Example of named parameters
            AssignFacultyToCourse(context, "BBIS101", "Fac22");
            AssignFacultyToCourse(context, "BBIS102", "Fac11");
            AssignFacultyToCourse(context, "BBIS103", "Fac22");
            AssignFacultyToCourse(context, "BBIS301", "Fac33");

            context.SaveChanges();
        }
Esempio n. 11
0
        protected override void Seed(ApplicationDbContext context)
        {
            var userStore   = new CustomUserStore(context);
            var userManager = new ApplicationUserManager(userStore);

            userManager.UserValidator = new UserValidator <ApplicationUser, int>(userManager)
            {
                AllowOnlyAlphanumericUserNames = false
            };

            if (!context.Roles.Any(role => role.Name.Equals("Admin")))
            {
                var roleStore   = new CustomRoleStore(context);
                var roleManager = new  RoleManager <CustomRole, int>(roleStore);
                var adminRole   = new CustomRole("Admin");

                roleManager.Create(adminRole);
            }

            if (!context.Users.Any(user => user.Email.Equals("*****@*****.**")))
            {
                var first = new ApplicationUser()
                {
                    FullName       = "Example User",
                    Email          = "*****@*****.**",
                    UserName       = "******",
                    EmailConfirmed = true
                };

                userManager.Create(first, "foobar");
                userManager.AddToRole(first.Id, "Admin");
            }

            for (int i = 0; i < 99; i++)
            {
                var          name     = Name.FullName();
                var          email    = $"example-{i + 1}@railstutorial.org";
                const string password = "******";

                var newUser = new ApplicationUser()
                {
                    FullName       = name,
                    Email          = email,
                    UserName       = email,
                    EmailConfirmed = true
                };

                if (!context.Users.Any(user => user.Email.Equals(email)))
                {
                    var result = userManager.Create(newUser, password);
                    if (!result.Succeeded)
                    {
                        throw new Exception(string.Join("\n", result.Errors));
                    }
                }
            }
            var allUsers = context.Users.OrderBy(user => user.Id).ToList();
            var users    = allUsers.Take(6).ToList();

            for (int i = 0; i < 50; i++)
            {
                var content = Lorem.Sentence(5);
                foreach (var user in users)
                {
                    Micropost m = new Micropost {
                        Content = content, User = user, CreatedAt = DateTime.Now
                    };
                    user.Microposts.Add(m);
                }
            }

            var mainUser  = allUsers.First();
            var following = allUsers.Where((user, index) => index > 0 && index < 50);
            var followers = allUsers.Where((user, index) => index > 1 && index < 40);

            foreach (var user in following)
            {
                mainUser.Follow(user);
            }
            foreach (var user in followers)
            {
                user.Follow(mainUser);
            }
        }