protected override void Seed(BugTracker.Models.ApplicationDbContext context)
        {
            var roleManager = new RoleManager <IdentityRole>(
                new RoleStore <IdentityRole>(context));

            //create Admin role
            if (!context.Roles.Any(r => r.Name == "Admin"))
            {
                roleManager.Create(new IdentityRole {
                    Name = "Admin"
                });
            }

            //create a Project Manager role
            if (!context.Roles.Any(r => r.Name == "Project Manager"))
            {
                roleManager.Create(new IdentityRole {
                    Name = "Project Manager"
                });
            }

            //create a Developer role
            if (!context.Roles.Any(r => r.Name == "Developer"))
            {
                roleManager.Create(new IdentityRole {
                    Name = "Developer"
                });
            }

            //create a Submitter role
            if (!context.Roles.Any(r => r.Name == "Submitter"))
            {
                roleManager.Create(new IdentityRole {
                    Name = "Submitter"
                });
            }

            //Seeded Roles for logins(Hardcoded)
            var userManager = new UserManager <ApplicationUser>(
                new UserStore <ApplicationUser>(context));

            if (!context.Users.Any(u => u.Email == "*****@*****.**"))
            {
                userManager.Create(new ApplicationUser
                {
                    UserName  = "******",
                    Email     = "*****@*****.**",
                    FirstName = "Asghar",
                    LastName  = "Khan",
                }, "Welcome@123");
            }

            if (!context.Users.Any(u => u.Email == "*****@*****.**"))
            {
                userManager.Create(new ApplicationUser
                {
                    UserName  = "******",
                    Email     = "*****@*****.**",
                    FirstName = "Mario",
                    LastName  = "Khan",
                }, "Welcome@123");
            }

            if (!context.Users.Any(u => u.Email == "*****@*****.**"))
            {
                userManager.Create(new ApplicationUser
                {
                    UserName  = "******",
                    Email     = "*****@*****.**",
                    FirstName = "AsgharDev",
                    LastName  = "Khan",
                }, "Welcome@123");
            }

            if (!context.Users.Any(u => u.Email == "*****@*****.**"))
            {
                userManager.Create(new ApplicationUser
                {
                    UserName  = "******",
                    Email     = "*****@*****.**",
                    FirstName = "AsgharSub",
                    LastName  = "Khan",
                }, "Welcome@123");
            }

            //set the users we created into the different roles
            var userId = userManager.FindByEmail("*****@*****.**").Id;

            userManager.AddToRole(userId, "Admin");

            var userId2 = userManager.FindByEmail("*****@*****.**").Id;

            userManager.AddToRole(userId2, "Project Manager");

            var userId3 = userManager.FindByEmail("*****@*****.**").Id;

            userManager.AddToRole(userId3, "Developer");

            var userId4 = userManager.FindByEmail("*****@*****.**").Id;

            userManager.AddToRole(userId4, "Submitter");

            //seed my ticket statuses, ticket priorities and ticket types
            List <string> statusList = new List <string> {
                "New", "Waiting for support", "Waiting for customer", "Resolved", "On hold"
            };

            foreach (var status in statusList)
            {
                if (!context.TicketStatuses.Any(r => r.Name == status))
                {
                    var ts = new TicketStatus();
                    ts.Name = status;
                    context.TicketStatuses.Add(ts);
                    context.SaveChanges();
                }
            }

            List <string> priorityList = new List <string> {
                "High", "Medium", "Low", "Critical"
            };

            foreach (var priority in priorityList)
            {
                if (!context.TicketPriorities.Any(r => r.Name == priority))
                {
                    var tp = new TicketPriority();
                    tp.Name = priority;
                    context.TicketPriorities.Add(tp);
                    context.SaveChanges();
                }
            }

            List <string> ticketTypes = new List <string> {
                "Error report", "Feature request", "Service request", "Other"
            };

            foreach (var type in ticketTypes)
            {
                if (!context.TicketTypes.Any(r => r.Name == type))
                {
                    var tt = new TicketType();
                    tt.Name = type;
                    context.TicketTypes.Add(tt);
                    context.SaveChanges();
                }
            }
        }
Exemple #2
0
        protected override void Seed(BugTracker.Models.ApplicationDbContext context)
        {
            //  This method will be called after migrating to the latest version.

            //  You can use the DbSet<T>.AddOrUpdate() helper extension method
            //  to avoid creating duplicate seed data.

            var roleManager =
                new RoleManager <IdentityRole>(
                    new RoleStore <IdentityRole>(context));

            var userManager =
                new UserManager <ApplicationUser>(
                    new UserStore <ApplicationUser>(context));

            if (!context.Roles.Any(user => user.Name == "Admin"))
            {
                var adminRole = new IdentityRole("Admin");
                roleManager.Create(adminRole);
            }

            if (!context.Roles.Any(user => user.Name == "Project Manager"))
            {
                var projectManagerRole = new IdentityRole("Project Manager");
                roleManager.Create(projectManagerRole);
            }

            if (!context.Roles.Any(user => user.Name == "Developer"))
            {
                var developerRole = new IdentityRole("Developer");
                roleManager.Create(developerRole);
            }

            if (!context.Roles.Any(user => user.Name == "Submitter"))
            {
                var submitterRole = new IdentityRole("Submitter");
                roleManager.Create(submitterRole);
            }

            ApplicationUser adminUser;

            if (!context.Users.Any(
                    user => user.UserName == "*****@*****.**"))
            {
                adminUser          = new ApplicationUser();
                adminUser.UserName = "******";
                adminUser.Email    = "*****@*****.**";
                userManager.Create(adminUser, "Password-1");
                userManager.AddToRole(adminUser.Id, "Admin");
            }
            else
            {
                adminUser = context
                            .Users
                            .First(user => user.UserName == "*****@*****.**");
            }

            if (!context.TicketTypes.Any(type => type.Name == "Bug"))
            {
                TicketType ticketTypeBug = new TicketType()
                {
                    Name = "Bug"
                };
                context.TicketTypes.Add(ticketTypeBug);
            }

            if (!context.TicketTypes.Any(type => type.Name == "Feature"))
            {
                TicketType ticketTypeFeature = new TicketType()
                {
                    Name = "Feature"
                };
                context.TicketTypes.Add(ticketTypeFeature);
            }

            if (!context.TicketTypes.Any(type => type.Name == "Database"))
            {
                TicketType ticketTypeDatabase = new TicketType()
                {
                    Name = "Database"
                };
                context.TicketTypes.Add(ticketTypeDatabase);
            }

            if (!context.TicketTypes.Any(type => type.Name == "Support"))
            {
                TicketType ticketTypeSupport = new TicketType()
                {
                    Name = "Support"
                };
                context.TicketTypes.Add(ticketTypeSupport);
            }

            if (!context.TicketPriorities.Any(priority => priority.Name == "Low"))
            {
                TicketPriority ticketPriorityLow = new TicketPriority()
                {
                    Name = "Low"
                };
                context.TicketPriorities.Add(ticketPriorityLow);
            }

            if (!context.TicketPriorities.Any(priority => priority.Name == "Medium"))
            {
                TicketPriority ticketPriorityMedium = new TicketPriority()
                {
                    Name = "Medium"
                };
                context.TicketPriorities.Add(ticketPriorityMedium);
            }

            if (!context.TicketPriorities.Any(priority => priority.Name == "High"))
            {
                TicketPriority ticketPriorityHigh = new TicketPriority()
                {
                    Name = "High"
                };
                context.TicketPriorities.Add(ticketPriorityHigh);
            }

            if (!context.TicketStatuses.Any(status => status.Name == "Open"))
            {
                TicketStatus ticketStatusOpen = new TicketStatus()
                {
                    Name = "Open"
                };
                context.TicketStatuses.Add(ticketStatusOpen);
            }

            if (!context.TicketStatuses.Any(status => status.Name == "Resolved"))
            {
                TicketStatus ticketStatusResolved = new TicketStatus()
                {
                    Name = "Resolved"
                };
                context.TicketStatuses.Add(ticketStatusResolved);
            }

            if (!context.TicketStatuses.Any(status => status.Name == "Rejected"))
            {
                TicketStatus ticketStatusRejected = new TicketStatus()
                {
                    Name = "Rejected"
                };
                context.TicketStatuses.Add(ticketStatusRejected);
            }

            // Creating Demo Users
            ApplicationUser adminDemoUser;

            if (!context.Users.Any(
                    user => user.UserName == "*****@*****.**"))
            {
                adminDemoUser          = new ApplicationUser();
                adminDemoUser.UserName = "******";
                adminDemoUser.Email    = "*****@*****.**";
                userManager.Create(adminDemoUser, "Password-1");
                userManager.AddToRole(adminDemoUser.Id, "Admin");
            }
            else
            {
                adminUser = context
                            .Users
                            .First(user => user.UserName == "*****@*****.**");
            }

            ApplicationUser projectManagerDemoUser;

            if (!context.Users.Any(
                    user => user.UserName == "*****@*****.**"))
            {
                projectManagerDemoUser          = new ApplicationUser();
                projectManagerDemoUser.UserName = "******";
                projectManagerDemoUser.Email    = "*****@*****.**";
                userManager.Create(projectManagerDemoUser, "Password-1");
                userManager.AddToRole(projectManagerDemoUser.Id, "Project Manager");
            }
            else
            {
                adminUser = context
                            .Users
                            .First(user => user.UserName == "*****@*****.**");
            }

            ApplicationUser developerDemoUser;

            if (!context.Users.Any(
                    user => user.UserName == "*****@*****.**"))
            {
                developerDemoUser          = new ApplicationUser();
                developerDemoUser.UserName = "******";
                developerDemoUser.Email    = "*****@*****.**";
                userManager.Create(developerDemoUser, "Password-1");
                userManager.AddToRole(developerDemoUser.Id, "Developer");
            }
            else
            {
                adminUser = context
                            .Users
                            .First(user => user.UserName == "*****@*****.**");
            }

            ApplicationUser submitterDemoUser;

            if (!context.Users.Any(
                    user => user.UserName == "*****@*****.**"))
            {
                submitterDemoUser          = new ApplicationUser();
                submitterDemoUser.UserName = "******";
                submitterDemoUser.Email    = "*****@*****.**";
                userManager.Create(submitterDemoUser, "Password-1");
                userManager.AddToRole(submitterDemoUser.Id, "Submitter");
            }
            else
            {
                adminUser = context
                            .Users
                            .First(user => user.UserName == "*****@*****.**");
            }
        }
        protected override void Seed(BugTracker.Models.ApplicationDbContext context)
        {
            //  This method will be called after migrating to the latest version.

            //  You can use the DbSet<T>.AddOrUpdate() helper extension method
            //  to avoid creating duplicate seed data.

            var roleManager =
                new RoleManager <IdentityRole>(
                    new RoleStore <IdentityRole>(context));

            var userManager =
                new UserManager <ApplicationUser>(
                    new UserStore <ApplicationUser>(context));

            if (!context.Roles.Any(p => p.Name == "Admin"))
            {
                var adminRole = new IdentityRole("Admin");
                roleManager.Create(adminRole);
            }

            ApplicationUser adminUser;

            if (!context.Users.Any(
                    p => p.UserName == "*****@*****.**"))
            {
                adminUser = new ApplicationUser
                {
                    UserName = "******",
                    Email    = "*****@*****.**"
                };

                userManager.Create(adminUser, "Password-1");
            }
            else
            {
                adminUser = context
                            .Users
                            .First(p => p.UserName == "*****@*****.**");
            }

            if (!userManager.IsInRole(adminUser.Id, "Admin"))
            {
                userManager.AddToRole(adminUser.Id, "Admin");
            }

            if (!context.Roles.Any(p => p.Name == "Project Manager"))
            {
                var projectManagerRole = new IdentityRole("Project Manager");
                roleManager.Create(projectManagerRole);
            }

            ApplicationUser projectManager;

            if (!context.Users.Any(
                    p => p.UserName == "*****@*****.**"))
            {
                projectManager = new ApplicationUser
                {
                    UserName = "******",
                    Email    = "*****@*****.**"
                };

                userManager.Create(projectManager, "Password-1");
            }
            else
            {
                projectManager = context
                                 .Users
                                 .First(p => p.UserName == "*****@*****.**");
            }

            if (!userManager.IsInRole(projectManager.Id, "Project Manager"))
            {
                userManager.AddToRole(projectManager.Id, "Project Manager");
            }

            if (!context.Roles.Any(p => p.Name == "Developer"))
            {
                var developerRole = new IdentityRole("Developer");
                roleManager.Create(developerRole);
            }

            ApplicationUser developer;

            if (!context.Users.Any(
                    p => p.UserName == "*****@*****.**"))
            {
                developer = new ApplicationUser
                {
                    UserName = "******",
                    Email    = "*****@*****.**"
                };

                userManager.Create(developer, "Password-1");
            }
            else
            {
                developer = context.Users
                            .First(p => p.UserName == "*****@*****.**");
            }

            if (!userManager.IsInRole(developer.Id, "Admin"))
            {
                userManager.AddToRole(developer.Id, "Admin");
            }

            if (!context.Roles.Any(p => p.Name == "Submitter"))
            {
                var submitterRole = new IdentityRole("Submitter");
                roleManager.Create(submitterRole);
            }

            ApplicationUser submitter;

            if (!context.Users.Any(
                    p => p.UserName == "*****@*****.**"))
            {
                submitter = new ApplicationUser
                {
                    UserName = "******",
                    Email    = "*****@*****.**"
                };

                userManager.Create(submitter, "Password-1");
            }
            else
            {
                submitter = context
                            .Users
                            .First(p => p.UserName == "*****@*****.**");
            }

            if (!userManager.IsInRole(submitter.Id, "Admin"))
            {
                userManager.AddToRole(submitter.Id, "Admin");
            }

            // Ticket Types
            if (!context.TicketTypes.Any(p => p.Name == "Bug"))
            {
                var bug = new TicketType
                {
                    Name = "Bug"
                };
                context.TicketTypes.Add(bug);
            }

            if (!context.TicketTypes.Any(p => p.Name == "Feature"))
            {
                var feature = new TicketType
                {
                    Name = "Feature"
                };
                context.TicketTypes.Add(feature);
            }

            if (!context.TicketTypes.Any(p => p.Name == "Database"))
            {
                var database = new TicketType
                {
                    Name = "Database"
                };
                context.TicketTypes.Add(database);
            }

            if (!context.TicketTypes.Any(p => p.Name == "Support"))
            {
                var support = new TicketType
                {
                    Name = "Support"
                };
                context.TicketTypes.Add(support);
            }

            // Ticket Priorities
            if (!context.TicketPriorities.Any(p => p.Name == "Low"))
            {
                var low = new TicketPriority
                {
                    Name = "Low"
                };
                context.TicketPriorities.Add(low);
            }

            if (!context.TicketPriorities.Any(p => p.Name == "Medium"))
            {
                var medium = new TicketPriority
                {
                    Name = "Medium"
                };
                context.TicketPriorities.Add(medium);
            }

            if (!context.TicketPriorities.Any(p => p.Name == "High"))
            {
                var high = new TicketPriority
                {
                    Name = "High"
                };
                context.TicketPriorities.Add(high);
            }

            // Ticket Statuses
            if (!context.TicketStatuses.Any(p => p.Name == "Open"))
            {
                var open = new TicketStatus
                {
                    Name = "Open"
                };
                context.TicketStatuses.Add(open);
            }

            if (!context.TicketStatuses.Any(p => p.Name == "Resolved"))
            {
                var resolved = new TicketStatus
                {
                    Name = "Resolved"
                };
                context.TicketStatuses.Add(resolved);
            }

            if (!context.TicketStatuses.Any(p => p.Name == "Rejected"))
            {
                var rejected = new TicketStatus
                {
                    Name = "Rejected"
                };
                context.TicketStatuses.Add(rejected);
            }
        }
        protected override void Seed(BugTracker.Models.ApplicationDbContext context)
        {
            //  This method will be called after migrating to the latest version.

            //  You can use the DbSet<T>.AddOrUpdate() helper extension method
            //  to avoid creating duplicate seed data.
            // Seeding Tickets' Types
            foreach (var type in ProjectConstants.AllowedTicketTypes)
            {
                TicketType ticketType = new TicketType();
                ticketType.Name = type;
                context.TicketTypes.AddOrUpdate(p => p.Name, ticketType);
            }
            // Seeding Tickets' Statuses
            foreach (var status in ProjectConstants.AllowedTicketStatuses)
            {
                TicketStatus ticketStatus = new TicketStatus();
                ticketStatus.Name = status;
                context.TicketStatuses.AddOrUpdate(p => p.Name, ticketStatus);
            }
            // Seeding Tickets' Priorities
            foreach (var priority in ProjectConstants.AllowedTicketPriorities)
            {
                TicketPriority ticketPriority = new TicketPriority();
                ticketPriority.Name = priority;
                context.TicketPriorities.AddOrUpdate(p => p.Name, ticketPriority);
            }
            // Seeding Users' Roles
            var Roles    = SeededRoles.CreateRolesList();
            var Accounts = SeededRoles.CreateAccountsList();

            foreach (var role in Roles)
            {
                var roleManager = new RoleManager <IdentityRole>(new RoleStore <IdentityRole>(context));

                if (!context.Roles.Any(p => p.Name == role))
                {
                    var roleToAdd = new IdentityRole(role);
                    roleManager.Create(roleToAdd);
                }
            }
            // Seeding Users
            foreach (var account in Accounts)
            {
                //Creating the user with their role
                var userManager = new ApplicationUserManager(new UserStore <ApplicationUser>(context));

                ApplicationUser userToCreate;

                if (!context.Users.Any(p => p.Email == account.Email))
                {
                    userToCreate             = new ApplicationUser();
                    userToCreate.UserName    = account.Email;
                    userToCreate.Email       = account.Email;
                    userToCreate.DisplayName = account.DisplayName;

                    userManager.Create(userToCreate, account.Password);
                }
                else
                {
                    userToCreate = context.Users.First(p => p.UserName == account.Email);
                }
                //Make sure the user is on its role
                if (!userManager.IsInRole(userToCreate.Id, account.Role))
                {
                    userManager.AddToRole(userToCreate.Id, account.Role);
                }
            }

            context.SaveChanges();
        }
        protected override void Seed(BugTracker.Models.ApplicationDbContext context)
        {
            var roleManager =
                new RoleManager <IdentityRole>(
                    new RoleStore <IdentityRole>(context));

            var userManager =
                new ApplicationUserManager(
                    new UserStore <ApplicationUser>(context));

            //If the app needs to create users with -on the name, we need to set the validator.
            userManager.UserValidator = new UserValidator <ApplicationUser>(userManager)
            {
                AllowOnlyAlphanumericUserNames = false,
                RequireUniqueEmail             = true
            };

            //Adding admin role if it doesn't exist.
            if (!context.Roles.Any(p => p.Name == "Admin"))
            {
                var adminRole = new IdentityRole("Admin");
                roleManager.Create(adminRole);
            }

            if (!context.Roles.Any(p => p.Name == "Project Manager"))
            {
                var projectManagerRole = new IdentityRole("Project Manager");
                roleManager.Create(projectManagerRole);
            }

            if (!context.Roles.Any(p => p.Name == "Developer"))
            {
                var developerRole = new IdentityRole("Developer");
                roleManager.Create(developerRole);
            }

            if (!context.Roles.Any(p => p.Name == "Submitter"))
            {
                var submitterRole = new IdentityRole("Submitter");
                roleManager.Create(submitterRole);
            }

            //Creating the adminuser
            ApplicationUser adminUser;


            if (!context.Users.Any(
                    p => p.UserName == "*****@*****.**"))
            {
                adminUser                = new ApplicationUser();
                adminUser.UserName       = "******";
                adminUser.Email          = "*****@*****.**";
                adminUser.EmailConfirmed = true;
                adminUser.NameOfUser     = "******";
                userManager.Create(adminUser, "Password-1");
            }
            else
            {
                adminUser = context
                            .Users
                            .First(p => p.UserName == "*****@*****.**");
            }

            //Make sure the user is on the admin role
            if (!userManager.IsInRole(adminUser.Id, "Admin"))
            {
                userManager.AddToRole(adminUser.Id, "Admin");
            }


            ApplicationUser demoAdmin;

            if (!context.Users.Any(
                    p => p.UserName == "*****@*****.**"))
            {
                demoAdmin                = new ApplicationUser();
                demoAdmin.UserName       = "******";
                demoAdmin.Email          = "*****@*****.**";
                demoAdmin.EmailConfirmed = true;
                demoAdmin.NameOfUser     = "******";
                userManager.Create(demoAdmin);
            }
            else
            {
                demoAdmin = context
                            .Users
                            .First(p => p.UserName == "*****@*****.**");
            }

            //Make sure the user is on the admin role
            if (!userManager.IsInRole(demoAdmin.Id, "Admin"))
            {
                userManager.AddToRole(demoAdmin.Id, "Admin");
            }


            ApplicationUser demoProjectManager;

            if (!context.Users.Any(
                    p => p.UserName == "*****@*****.**"))
            {
                demoProjectManager                = new ApplicationUser();
                demoProjectManager.UserName       = "******";
                demoProjectManager.Email          = "*****@*****.**";
                demoProjectManager.EmailConfirmed = true;
                demoProjectManager.NameOfUser     = "******";
                userManager.Create(demoProjectManager);
            }
            else
            {
                demoProjectManager = context
                                     .Users
                                     .First(p => p.UserName == "*****@*****.**");
            }

            //Make sure the user is on the admin role
            if (!userManager.IsInRole(demoProjectManager.Id, "Project Manager"))
            {
                userManager.AddToRole(demoProjectManager.Id, "Project Manager");
            }

            ApplicationUser demoDeveloper;

            if (!context.Users.Any(
                    p => p.UserName == "*****@*****.**"))
            {
                demoDeveloper                = new ApplicationUser();
                demoDeveloper.UserName       = "******";
                demoDeveloper.Email          = "*****@*****.**";
                demoDeveloper.EmailConfirmed = true;
                demoDeveloper.NameOfUser     = "******";
                userManager.Create(demoDeveloper);
            }
            else
            {
                demoDeveloper = context
                                .Users
                                .First(p => p.UserName == "*****@*****.**");
            }

            //Make sure the user is on the admin role
            if (!userManager.IsInRole(demoDeveloper.Id, "Developer"))
            {
                userManager.AddToRole(demoDeveloper.Id, "Developer");
            }

            ApplicationUser demoSubmitter;

            if (!context.Users.Any(
                    p => p.UserName == "*****@*****.**"))
            {
                demoSubmitter                = new ApplicationUser();
                demoSubmitter.UserName       = "******";
                demoSubmitter.Email          = "*****@*****.**";
                demoSubmitter.EmailConfirmed = true;
                demoSubmitter.NameOfUser     = "******";
                userManager.Create(demoSubmitter);
            }
            else
            {
                demoSubmitter = context
                                .Users
                                .First(p => p.UserName == "*****@*****.**");
            }

            //Make sure the user is on the admin role
            if (!userManager.IsInRole(demoSubmitter.Id, "Submitter"))
            {
                userManager.AddToRole(demoSubmitter.Id, "Submitter");
            }

            //Seeding ticket priorities
            TicketPriority ticketPriorityLow    = new TicketPriority();
            TicketPriority ticketPriorityMedium = new TicketPriority();
            TicketPriority ticketPriorityHigh   = new TicketPriority();


            ticketPriorityLow.PriorityLevel    = "Low";
            ticketPriorityMedium.PriorityLevel = "Medium";
            ticketPriorityHigh.PriorityLevel   = "High";


            context.TicketPriorities.AddOrUpdate(p => p.PriorityLevel, ticketPriorityLow);
            context.TicketPriorities.AddOrUpdate(p => p.PriorityLevel, ticketPriorityMedium);
            context.TicketPriorities.AddOrUpdate(p => p.PriorityLevel, ticketPriorityHigh);
            //Seeding of ticket priorities ends here

            //Seeding of ticket statuses starts here
            TicketStatus ticketStatusOpen     = new TicketStatus();
            TicketStatus ticketStatusResolved = new TicketStatus();
            TicketStatus ticketStatusRejected = new TicketStatus();

            ticketStatusOpen.StatusName     = "Open";
            ticketStatusResolved.StatusName = "Resolved";
            ticketStatusRejected.StatusName = "Rejected";

            context.TicketStatuses.AddOrUpdate(p => p.StatusName, ticketStatusOpen);
            context.TicketStatuses.AddOrUpdate(p => p.StatusName, ticketStatusResolved);
            context.TicketStatuses.AddOrUpdate(p => p.StatusName, ticketStatusRejected);
            //Seeding of ticket statuses ends here

            //Seeding of ticket types starts here
            TicketType ticketTypeBug      = new TicketType();
            TicketType ticketTypeFeature  = new TicketType();
            TicketType ticketTypeDatabase = new TicketType();
            TicketType ticketTypeSupport  = new TicketType();

            ticketTypeBug.TypeName      = "Bug";
            ticketTypeFeature.TypeName  = "Feature";
            ticketTypeDatabase.TypeName = "Database";
            ticketTypeSupport.TypeName  = "Support";

            context.TicketTypes.AddOrUpdate(p => p.TypeName, ticketTypeBug);
            context.TicketTypes.AddOrUpdate(p => p.TypeName, ticketTypeFeature);
            context.TicketTypes.AddOrUpdate(p => p.TypeName, ticketTypeDatabase);
            context.TicketTypes.AddOrUpdate(p => p.TypeName, ticketTypeSupport);
            //Seeding of ticket types ends here

            //Seeding of timetracker starts here
            TimeTracker timetracker = new TimeTracker();

            timetracker.Identifyer = "EmailTracker";
            context.TimeTrackers.AddOrUpdate(p => p.Id, timetracker);
            //Seeding of timetracker ends here

            context.SaveChanges();
        }
        protected override void Seed(BugTracker.Models.ApplicationDbContext context)
        {
            var roleManager = new RoleManager <IdentityRole>(new RoleStore <IdentityRole>(context));
            var userManager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(context));


            if (!context.Roles.Any(r => r.Name == "Admin"))
            {
                roleManager.Create(new IdentityRole {
                    Name = "Admin"
                });
            }

            if (!context.Roles.Any(r => r.Name == "Project Manager"))
            {
                roleManager.Create(new IdentityRole {
                    Name = "Project Manager"
                });
            }

            if (!context.Roles.Any(r => r.Name == "Developer"))
            {
                roleManager.Create(new IdentityRole {
                    Name = "Developer"
                });
            }

            if (!context.Roles.Any(r => r.Name == "Submitter"))
            {
                roleManager.Create(new IdentityRole {
                    Name = "Submitter"
                });
            }


            ApplicationUser adminUser   = null;
            ApplicationUser managerUser = null;
            ApplicationUser devUser     = null;
            ApplicationUser subUser     = null;

            if (!context.Users.Any(p => p.UserName == "*****@*****.**"))
            {
                adminUser             = new ApplicationUser();
                adminUser.UserName    = "******";
                adminUser.Email       = "*****@*****.**";
                adminUser.FirstName   = "Admin";
                adminUser.LastName    = "User";
                adminUser.DisplayName = "Admin User";

                userManager.Create(adminUser, "Password-1");
            }
            else
            {
                adminUser = context.Users.Where(p => p.UserName == "*****@*****.**")
                            .FirstOrDefault();
            }


            if (!context.Users.Any(p => p.UserName == "*****@*****.**"))
            {
                managerUser             = new ApplicationUser();
                managerUser.UserName    = "******";
                managerUser.Email       = "*****@*****.**";
                managerUser.FirstName   = "Project";
                managerUser.LastName    = "Manager";
                managerUser.DisplayName = "Project Manager";

                userManager.Create(managerUser, "Password-2");
            }
            else
            {
                managerUser = context.Users.Where(p => p.UserName == "*****@*****.**")
                              .FirstOrDefault();
            }

            if (!context.Users.Any(p => p.UserName == "*****@*****.**"))
            {
                devUser             = new ApplicationUser();
                devUser.UserName    = "******";
                devUser.Email       = "*****@*****.**";
                devUser.FirstName   = "Web";
                devUser.LastName    = "Dev";
                devUser.DisplayName = "Developer";

                userManager.Create(devUser, "Password-3");
            }
            else
            {
                devUser = context.Users.Where(p => p.UserName == "*****@*****.**")
                          .FirstOrDefault();
            }
            if (!context.Users.Any(p => p.UserName == "*****@*****.**"))
            {
                subUser             = new ApplicationUser();
                subUser.UserName    = "******";
                subUser.Email       = "*****@*****.**";
                subUser.FirstName   = "Project";
                subUser.LastName    = "Submitter";
                subUser.DisplayName = "Submitter";

                userManager.Create(subUser, "Password-4");
            }
            else
            {
                subUser = context.Users.Where(p => p.UserName == "*****@*****.**")
                          .FirstOrDefault();
            }


            if (!userManager.IsInRole(adminUser.Id, "Admin"))
            {
                userManager.AddToRole(adminUser.Id, "Admin");
            }
            if (!userManager.IsInRole(managerUser.Id, "Project Manager"))
            {
                userManager.AddToRole(managerUser.Id, "Project Manager");
            }
            if (!userManager.IsInRole(devUser.Id, "Developer"))
            {
                userManager.AddToRole(devUser.Id, "Developer");
            }
            if (!userManager.IsInRole(subUser.Id, "Submitter"))
            {
                userManager.AddToRole(subUser.Id, "Submitter");
            }
            //Ticket Priority
            var lowPriority = new TicketPriority();

            lowPriority.Id   = 1;
            lowPriority.Name = "Low";
            context.TicketPriorities.AddOrUpdate(lowPriority);

            var medPriority = new TicketPriority();

            medPriority.Name = "Medium";
            medPriority.Id   = 2;
            context.TicketPriorities.AddOrUpdate(medPriority);

            var highPriority = new TicketPriority();

            highPriority.Name = "High";
            highPriority.Id   = 3;
            context.TicketPriorities.AddOrUpdate(highPriority);

            var urgentPriority = new TicketPriority();

            urgentPriority.Name = "Urgent";
            urgentPriority.Id   = 4;
            context.TicketPriorities.AddOrUpdate(urgentPriority);

            //Ticket Type
            var bugFix = new TicketType();

            bugFix.Name = "Bug Fix";
            bugFix.Id   = 1;
            context.TicketTypes.AddOrUpdate(bugFix);
            var softwareUpdate = new TicketType();

            softwareUpdate.Name = "Software Update";
            softwareUpdate.Id   = 2;
            context.TicketTypes.AddOrUpdate(softwareUpdate);

            //Ticket Status
            var notStarted = new TicketStatus();

            notStarted.Name = "Not Started";
            notStarted.Id   = 1;
            context.TicketStatuses.AddOrUpdate(notStarted);
            var inProgress = new TicketStatus();

            inProgress.Name = "In Progress";
            inProgress.Id   = 2;
            context.TicketStatuses.AddOrUpdate(inProgress);
            var onHold = new TicketStatus();

            onHold.Name = "On Hold";
            onHold.Id   = 3;
            context.TicketStatuses.AddOrUpdate(onHold);
            var completed = new TicketStatus();

            completed.Name = "Completed";
            completed.Id   = 4;
            context.TicketStatuses.AddOrUpdate(completed);
        }
Exemple #7
0
        protected override void Seed(ApplicationDbContext context)
        {
            RoleAndUserHelper.CreateUser("*****@*****.**");//Admin
            RoleAndUserHelper.CreateRole("Admin");
            RoleAndUserHelper.AddRoleToUser("*****@*****.**", "Admin");

            RoleAndUserHelper.CreateUser("*****@*****.**");//PM
            RoleAndUserHelper.CreateRole("Project Manager");
            RoleAndUserHelper.AddRoleToUser("*****@*****.**", "Project Manager");


            RoleAndUserHelper.CreateUser("*****@*****.**");//Developer
            RoleAndUserHelper.CreateRole("Developer");
            RoleAndUserHelper.AddRoleToUser("*****@*****.**", "Developer");

            RoleAndUserHelper.CreateUser("*****@*****.**");//Submitter
            RoleAndUserHelper.CreateRole("Submitter");
            RoleAndUserHelper.AddRoleToUser("*****@*****.**", "Submitter");

            TicketStatus ticketStatus = new TicketStatus()
            {
                Name = "Pending"
            };
            TicketStatus ticketStatus2 = new TicketStatus()
            {
                Name = "Assigned"
            };
            TicketStatus ticketStatus3 = new TicketStatus()
            {
                Name = "Updated"
            };
            TicketStatus ticketStatus4 = new TicketStatus()
            {
                Name = "Solved"
            };

            List <TicketStatus> tslist = new List <TicketStatus>()
            {
                ticketStatus, ticketStatus2, ticketStatus3, ticketStatus4
            };

            foreach (var status in tslist)
            {
                context.TicketStatus.Add(status);
                context.SaveChanges();
            }

            TicketType ticketType = new TicketType()
            {
                Name = "Bug"
            };
            TicketType ticketType1 = new TicketType()
            {
                Name = "FeatureRequest"
            };
            TicketType ticketType2 = new TicketType()
            {
                Name = "SalesQuestion"
            };
            TicketType ticketType3 = new TicketType()
            {
                Name = "HowTo"
            };
            TicketType ticketType4 = new TicketType()
            {
                Name = "TechnicalIssue"
            };
            TicketType ticketType5 = new TicketType()
            {
                Name = "Cancellation"
            };

            List <TicketType> ttlist = new List <TicketType>()
            {
                ticketType, ticketType1, ticketType2, ticketType3, ticketType4, ticketType5
            };

            foreach (var type in ttlist)
            {
                context.TicketTypes.Add(type);
                context.SaveChanges();
            }

            TicketPriority priority = new TicketPriority()
            {
                Name = "Urgent"
            };
            TicketPriority priority2 = new TicketPriority()
            {
                Name = "High"
            };
            TicketPriority priority3 = new TicketPriority()
            {
                Name = "Regular"
            };
            TicketPriority priority4 = new TicketPriority()
            {
                Name = "Low"
            };

            List <TicketPriority> priorities = new List <TicketPriority>()
            {
                priority, priority2, priority3, priority4
            };

            foreach (var ticketPriority in priorities)
            {
                context.TicketPriorities.Add(ticketPriority);
                context.SaveChanges();
            }
        }
Exemple #8
0
        protected override void Seed(ApplicationDbContext context)
        {
            // DEFAULT ROLE CREATION
            var roleManager = new RoleManager <IdentityRole>(
                new RoleStore <IdentityRole>(context));

            if (!context.Roles.Any(r => r.Name == "Admin"))
            {
                roleManager.Create(new IdentityRole {
                    Name = "Admin"
                });
            }
            if (!context.Roles.Any(r => r.Name == "SuperAdmin"))
            {
                roleManager.Create(new IdentityRole {
                    Name = "SuperAdmin"
                });
            }
            if (!context.Roles.Any(r => r.Name == "DemoAccount"))
            {
                roleManager.Create(new IdentityRole {
                    Name = "DemoAccount"
                });
            }
            if (!context.Roles.Any(r => r.Name == "ProjectManager"))
            {
                roleManager.Create(new IdentityRole {
                    Name = "ProjectManager"
                });
            }
            if (!context.Roles.Any(r => r.Name == "Developer"))
            {
                roleManager.Create(new IdentityRole {
                    Name = "Developer"
                });
            }
            if (!context.Roles.Any(r => r.Name == "Submitter"))
            {
                roleManager.Create(new IdentityRole {
                    Name = "Submitter"
                });
            }

            // DEFAULT USER CREATION
            var userManager = new UserManager <ApplicationUser>(
                new UserStore <ApplicationUser>(context));

            if (!context.Users.Any(u => u.Email == "*****@*****.**"))
            {
                userManager.Create(new ApplicationUser {
                    UserName  = "******",
                    FirstName = "Casey",
                    LastName  = "Jones",
                    Email     = "*****@*****.**",
                }, "CoderFoundry1!");
            }
            if (!context.Users.Any(u => u.Email == "*****@*****.**"))
            {
                userManager.Create(new ApplicationUser {
                    UserName  = "******",
                    FirstName = "Mark",
                    LastName  = "Jaang",
                    Email     = "*****@*****.**",
                }, "BugTracker8**");
            }
            if (!context.Users.Any(u => u.Email == "*****@*****.**"))
            {
                userManager.Create(new ApplicationUser {
                    UserName  = "******",
                    FirstName = "Ryan",
                    LastName  = "Chapman",
                    Email     = "*****@*****.**",
                }, "BugTracker8**");
            }
            if (!context.Users.Any(u => u.Email == "*****@*****.**"))
            {
                userManager.Create(new ApplicationUser {
                    UserName  = "******",
                    FirstName = "Demo",
                    LastName  = "Admin",
                    Email     = "*****@*****.**",
                }, "BugTracker8**");
            }
            if (!context.Users.Any(u => u.Email == "*****@*****.**"))
            {
                userManager.Create(new ApplicationUser {
                    UserName  = "******",
                    FirstName = "Demo",
                    LastName  = "ProjectManager",
                    Email     = "*****@*****.**",
                }, "BugTracker8**");
            }
            if (!context.Users.Any(u => u.Email == "*****@*****.**"))
            {
                userManager.Create(new ApplicationUser {
                    UserName  = "******",
                    FirstName = "Demo",
                    LastName  = "Developer",
                    Email     = "*****@*****.**",
                }, "BugTracker8**");
            }
            if (!context.Users.Any(u => u.Email == "*****@*****.**"))
            {
                userManager.Create(new ApplicationUser {
                    UserName  = "******",
                    FirstName = "Demo",
                    LastName  = "Submitter",
                    Email     = "*****@*****.**",
                }, "BugTracker8**");
            }


            // ASSIGNMENT OF ROLES TO EACH INITIAL USER

            //Casey Jones
            var userID = userManager.FindByEmail("*****@*****.**").Id;

            userManager.AddToRole(userID, "Admin");
            userID = userManager.FindByEmail("*****@*****.**").Id;
            userManager.AddToRole(userID, "SuperAdmin");

            //Mark Jaang
            var userID2 = userManager.FindByEmail("*****@*****.**").Id;

            userManager.AddToRole(userID2, "Admin");
            //Ryan Chapman
            var userID3 = userManager.FindByEmail("*****@*****.**").Id;

            userManager.AddToRole(userID3, "Admin");

            // ASSIGNMENT OF DEMO USERS FOR EACH ROLE

            //DemoAdmin
            var userID4 = userManager.FindByEmail("*****@*****.**").Id;

            userManager.AddToRole(userID4, "Admin");
            userManager.AddToRole(userID4, "DemoAccount");

            //DemoProjectManager
            var userID5 = userManager.FindByEmail("*****@*****.**").Id;

            userManager.AddToRole(userID5, "ProjectManager");
            userManager.AddToRole(userID5, "DemoAccount");

            //DemoDeveloper
            var userID6 = userManager.FindByEmail("*****@*****.**").Id;

            userManager.AddToRole(userID6, "Developer");
            userManager.AddToRole(userID6, "DemoAccount");

            //DemoSubmitter
            var userID7 = userManager.FindByEmail("*****@*****.**").Id;

            userManager.AddToRole(userID7, "Submitter");
            userManager.AddToRole(userID7, "DemoAccount");


            //TICKET STATUS SEEDS
            if (!context.TicketStatuses.Any(p => p.Name == "Submitted"))
            {
                var status = new TicketStatus();
                status.Name = "Submitted";
                context.TicketStatuses.Add(status);
            }
            if (!context.TicketStatuses.Any(p => p.Name == "Assigned"))
            {
                var status = new TicketStatus();
                status.Name = "Assigned";
                context.TicketStatuses.Add(status);
            }
            if (!context.TicketStatuses.Any(p => p.Name == "In Progress"))
            {
                var status = new TicketStatus();
                status.Name = "In Progress";
                context.TicketStatuses.Add(status);
            }
            if (!context.TicketStatuses.Any(p => p.Name == "Pending"))
            {
                var status = new TicketStatus();
                status.Name = "Pending";
                context.TicketStatuses.Add(status);
            }
            if (!context.TicketStatuses.Any(p => p.Name == "Resolved"))
            {
                var status = new TicketStatus();
                status.Name = "Resolved";
                context.TicketStatuses.Add(status);
            }
            if (!context.TicketStatuses.Any(p => p.Name == "Closed"))
            {
                var status = new TicketStatus();
                status.Name = "Closed";
                context.TicketStatuses.Add(status);
            }
            if (!context.TicketStatuses.Any(p => p.Name == "Cancelled"))
            {
                var status = new TicketStatus();
                status.Name = "Cancelled";
                context.TicketStatuses.Add(status);
            }

            //TICKET TYPE SEEDS
            if (!context.TicketTypes.Any(p => p.Name == "Hardware"))
            {
                var type = new TicketType();
                type.Name = "Hardware";
                context.TicketTypes.Add(type);
            }
            if (!context.TicketTypes.Any(p => p.Name == "Software"))
            {
                var type = new TicketType();
                type.Name = "Software";
                context.TicketTypes.Add(type);
            }
            if (!context.TicketTypes.Any(p => p.Name == "Network"))
            {
                var type = new TicketType();
                type.Name = "Network";
                context.TicketTypes.Add(type);
            }

            //TICKET PRIORITY SEEDS
            if (!context.TicketPriorities.Any(p => p.Name == "Project"))
            {
                var priority = new TicketPriority();
                priority.Name = "Project";
                context.TicketPriorities.Add(priority);
            }
            if (!context.TicketPriorities.Any(p => p.Name == "Low"))
            {
                var priority = new TicketPriority();
                priority.Name = "Low";
                context.TicketPriorities.Add(priority);
            }
            if (!context.TicketPriorities.Any(p => p.Name == "Medium"))
            {
                var priority = new TicketPriority();
                priority.Name = "Medium";
                context.TicketPriorities.Add(priority);
            }
            if (!context.TicketPriorities.Any(p => p.Name == "High"))
            {
                var priority = new TicketPriority();
                priority.Name = "High";
                context.TicketPriorities.Add(priority);
            }
            if (!context.TicketPriorities.Any(p => p.Name == "Critical"))
            {
                var priority = new TicketPriority();
                priority.Name = "Critical";
                context.TicketPriorities.Add(priority);
            }
        }