示例#1
0
        /// <summary>
        /// Initializes the ticket system with data
        /// </summary>
        /// <param name="context">context</param>
        /// <param name="userManager">admin</param>
        /// <param name="roleManager"></param>
        public static void Initialize(ServiceDeskContext context, UserManager <Technician> userManager, RoleManager <IdentityRole> roleManager)
        {
            context.Database.EnsureDeleted();
            context.Database.Migrate();

            var randGenerator = new Random();



            foreach (var employee in _employee)
            {
                employee.DateAdded = DateTime.Now.AddMonths(randGenerator.Next(-24, -12));
            }

            var role = roleManager.FindByNameAsync(DataConstants.AdministratorRole).Result;

            if (role == null)
            {
                roleManager.CreateAsync(new IdentityRole(DataConstants.AdministratorRole));
            }

            foreach (var technician in _technicians)
            {
                technician.DateAdded = DateTime.Now.AddMonths(randGenerator.Next(-36, -25));
                technician.UserName  = $"{technician.FirstName}.{technician.LastName}";
                userManager.CreateAsync(technician, "password").Wait();
                if (technician.IsAdmin)
                {
                    userManager.AddToRoleAsync(technician, DataConstants.AdministratorRole);
                }
            }

            context.Employees.AddRange(_employee);

            context.SaveChanges();

            foreach (var employee in context.Employees)
            {
                ///<summary>Random ticket Generation</summary>
                var ticketCount = randGenerator.Next(0, 15);
                for (var i = 0; i < ticketCount; i++)
                {
                    //Random generation for ticket description list
                    string[] ticketDescription =
                    {
                        "Network connection down",
                        "Cant Access login",
                        "Computer running slow",
                        "Sound not working",
                        "Computer wont power up",
                        "PC wont turn on",
                        "PC randomly shutting off"
                    };
                    int    dIndex           = randGenerator.Next(ticketDescription.Length);
                    string descriptionValue = ticketDescription[dIndex];
                    //Random generation for ticket description list
                    // Random generation for employee notes list on ticket
                    string[] employeeNotes =
                    {
                        "Employee is easy to work with.",
                        "Employee is technologically deficient",
                        "Employee is Karen, have boss ready",
                        "Problem is already being worked on",
                        "Employee has history not knowing how to power monitor on",
                        "Terrible Employee to work with"
                    };
                    int    nIndex     = randGenerator.Next(employeeNotes.Length);
                    string notesValue = employeeNotes[nIndex];
                    // Random generation for employee notes list on ticket

                    context.Tickets.Add(new Ticket
                    {
                        EmployeeId  = employee.Id,
                        Title       = $"{employee.Department}: Case {i}",
                        Description = descriptionValue,
                        Complexity  = i % 3 + 1,
                        IsUrgent    = randGenerator.Next(0, 5) == 0,
                        Notes       = notesValue,
                        Open        = randGenerator.Next(0, 2) == 0,
                        DateAdded   = DateTime.Now.AddMonths(randGenerator.Next(-24, -12))
                    });
                }
            }

            context.SaveChanges();


            foreach (var ticket in context.Tickets)
            {
                ///<summary>Time spent on ticket random generation</summary>
                var workTimesCount = randGenerator.Next(0, 10);
                for (var i = 0; i < workTimesCount; i++)
                {
                    var start = ticket.DateAdded.AddHours(randGenerator.Next(1, 60));
                    var end   = start.AddMinutes(randGenerator.Next(15, 60));
                    context.TechnicianTicketTimes.Add(new TechnicianTicketTime
                    {
                        Start        = start,
                        End          = end,
                        TechnicianId = context.Users.OrderBy(t => Guid.NewGuid()).Take(1).First().UserName,
                        TicketId     = ticket.Id
                    });
                }
            }

            context.SaveChanges();
        }
示例#2
0
        /// <summary>
        /// Initializes the ticket system with data
        /// </summary>
        /// <param name="context">context</param>
        /// <param name="userManager">admin</param>
        /// <param name="roleManager"></param>
        public static void Initialize(ServiceDeskContext context, UserManager <Technician> userManager, RoleManager <IdentityRole> roleManager)
        {
            context.Database.EnsureDeleted();
            context.Database.Migrate();

            var randGenerator = new Random();

            foreach (var employee in _employee)
            {
                employee.DateAdded = DateTime.Now.AddMonths(randGenerator.Next(-24, -12));
            }

            var role = roleManager.FindByNameAsync(DataConstants.AdministratorRole).Result;

            if (role == null)
            {
                roleManager.CreateAsync(new IdentityRole(DataConstants.AdministratorRole));
            }

            foreach (var technician in _technicians)
            {
                technician.DateAdded = DateTime.Now.AddMonths(randGenerator.Next(-36, -25));
                technician.UserName  = $"{technician.FirstName}.{technician.LastName}";
                userManager.CreateAsync(technician, "password").Wait();
                if (technician.IsAdmin)
                {
                    userManager.AddToRoleAsync(technician, DataConstants.AdministratorRole);
                }
            }

            context.Employee.AddRange(_employee);

            context.SaveChanges();

            foreach (var employee in context.Employee)
            {
                var ticketCount = randGenerator.Next(0, 15);
                for (var i = 0; i < ticketCount; i++)
                {
                    context.Ticket.Add(new Ticket
                    {
                        EmployeeId  = employee.Id,
                        Title       = $"{employee.Department}: Case {i}",
                        Description = $"Super awesome ticket {i}",
                        Complexity  = i % 3 + 1,
                        IsUrgent    = randGenerator.Next(0, 5) == 0,
                        Notes       = "Terrible Employee to work with",
                        Open        = randGenerator.Next(0, 2) == 0,
                        DateAdded   = DateTime.Now.AddMonths(randGenerator.Next(-24, -12))
                    });
                }
            }

            context.SaveChanges();

            foreach (var ticket in context.Ticket)
            {
                var workTimesCount = randGenerator.Next(0, 10);
                for (var i = 0; i < workTimesCount; i++)
                {
                    var start = ticket.DateAdded.AddHours(randGenerator.Next(1, 60));
                    var end   = start.AddMinutes(randGenerator.Next(15, 60));
                    context.TechnicianTicketTime.Add(new TechnicianTicketTime
                    {
                        Start        = start,
                        End          = end,
                        TechnicianId = context.Users.OrderBy(t => Guid.NewGuid()).Take(1).First().UserName,
                        TicketId     = ticket.Id
                    });
                }
            }

            context.SaveChanges();
        }