Пример #1
0
        public static async Task SeedSupervisor(TmanagerServiceContext dbContext, UserManager <ApplicationUser> userManager)
        {
            var supervisorRoleString  = RoleValues.Supervisor.ToDescription();
            var supervisorClaimString = Claim.InsertRequest.ToDescription();

            foreach (var user in await DataValues.SupervisorDataAsync(dbContext, userManager))
            {
                if (await userManager.FindByNameAsync(user.UserName) == null)
                {
                    await userManager.CreateAsync(user, DataValues.default_user_password);

                    var userClaim = await userManager.GetClaimsAsync(user);

                    if (!await userManager.IsInRoleAsync(user, supervisorRoleString))
                    {
                        await userManager.AddToRoleAsync(user, supervisorRoleString);
                    }

                    if (!userClaim.Any(x => x.Type == supervisorClaimString))
                    {
                        await userManager.AddClaimAsync(user, new System.Security.Claims.Claim(supervisorClaimString, true.ToString()));
                    }
                }
            }
        }
Пример #2
0
        public static async Task SeedAdmin(TmanagerServiceContext dbContext, UserManager <ApplicationUser> userManager)
        {
            var adminRoleString  = RoleValues.Admin.ToDescription();
            var adminClaimString = Claim.CreateAccount.ToDescription();

            foreach (var admin in DataValues.AdminData(dbContext))
            {
                if (await userManager.FindByNameAsync(admin.UserName) == null)
                {
                    await userManager.CreateAsync(admin, DataValues.default_admin_password);

                    var adminClaim = await userManager.GetClaimsAsync(admin);

                    if (!await userManager.IsInRoleAsync(admin, adminRoleString))
                    {
                        await userManager.AddToRoleAsync(admin, adminRoleString);
                    }

                    if (!adminClaim.Any(x => x.Type == adminClaimString))
                    {
                        await userManager.AddClaimAsync(admin, new System.Security.Claims.Claim(adminClaimString, true.ToString()));
                    }
                }
            }
        }
Пример #3
0
 public static IEnumerable <ApplicationUser> AdminData(TmanagerServiceContext dbContext)
 {
     return(new List <ApplicationUser>()
     {
         new ApplicationUser {
             UserName = adminName01, Email = "*****@*****.**", SecurityStamp = Guid.NewGuid().ToString(),
             FirstName = "Quản", LastName = "Nguyễn Văn", EmailConfirmed = true, Address = "33 Nguyễn Thị Thập, Đà Nẵng",
             Role = RoleValues.Admin.ToDescription(), IsEnabled = true, Note = "Admin", Gender = Gender.Male.ToDescription(),
             DateOfBirth = DateTime.ParseExact("25/12/1965", "dd/MM/yyyy", ci), PhoneNumber = "0935846275",
             Avatar = "http://res.cloudinary.com/dj9j7j4sf/image/upload/v1541990231/gavt5iohsv8aose0zx5a.jpg"
         },
         new ApplicationUser {
             UserName = "******", Email = "*****@*****.**", SecurityStamp = Guid.NewGuid().ToString(),
             FirstName = "Trị", LastName = "Trần Thị", EmailConfirmed = true, Address = "63 Nguyễn Thị Thập, Đà Nẵng",
             Role = RoleValues.Admin.ToDescription(), IsEnabled = true, Note = "Admin", Gender = Gender.Female.ToDescription(),
             DateOfBirth = DateTime.ParseExact("25/12/1967", "dd/MM/yyyy", ci), PhoneNumber = "0968547213",
             Avatar = "http://res.cloudinary.com/dj9j7j4sf/image/upload/v1541990447/c3mygtlyhbf7vzhzocqs.jpg"
         }
     });
 }
Пример #4
0
        public static async Task <IEnumerable <Company> > CompanyDataAsync(TmanagerServiceContext dbContext, UserManager <ApplicationUser> userManager)
        {
            string adminId = (await userManager.FindByNameAsync(AdminData(dbContext).ToArray().FirstOrDefault().UserName)).Id;

            return(new List <Company>()
            {
                new Company {
                    AdminId = adminId, Name = companyName01, Address = "48 Cao Thắng, Đà Nẵng", Status = true, IsDepartmentOfConstruction = false,
                    Logo = "http://res.cloudinary.com/dj9j7j4sf/image/upload/v1541472243/cj8pkzjrj41abqcfo0kl.png"
                },
                new Company {
                    AdminId = adminId, Name = "Công ty xây dựng 2", Address = "138 Đống Đa, Đà Nẵng", Status = true, IsDepartmentOfConstruction = false,
                    Logo = "http://res.cloudinary.com/dj9j7j4sf/image/upload/v1541472244/uoslpdsifawv5gdzeor5.png"
                },
                new Company {
                    AdminId = adminId, Name = "Công ty xây dựng 3", Address = "55 Nguyễn Du, Đà Nẵng", Status = true, IsDepartmentOfConstruction = false,
                    Logo = "http://res.cloudinary.com/dj9j7j4sf/image/upload/v1541472245/klaupqhjuta8bsfjoygu.png"
                },
                new Company {
                    AdminId = adminId, Name = DepartmentOfConstruction, Address = "Tầng 12, tầng 13 - Trung tâm hành chính - 24 Trần Phú, quận Hải Châu, thành phố Đà Nẵng", Status = true, IsDepartmentOfConstruction = true,
                    Logo = "http://res.cloudinary.com/dj9j7j4sf/image/upload/v1541472603/fyx5d6frnnb2u5mvlvjp.jpg"
                }
            });
        }
Пример #5
0
        public static async Task SeedAsync(TmanagerServiceContext dbContext,
                                           UserManager <ApplicationUser> userManager,
                                           RoleManager <IdentityRole> roleManager,
                                           ILoggerFactory loggerFactory, int?retry = 0)
        {
            int retryForAvailability = retry.Value;

            try
            {
                dbContext.Database.Migrate();
                await AddData.SeedRolesAndClaims(userManager, roleManager);

                //Seed Admin
                await AddData.SeedAdmin(dbContext, userManager);

                //Seed AreaWorking
                //if (!dbContext.AreaWorkings.Any())
                //{
                //    dbContext.AreaWorkings.AddRange(await DataValues.AreaWorkingDataAsync(dbContext, userManager));

                //    await dbContext.SaveChangesAsync();
                //}

                //Seed Admin
                if (!dbContext.Companys.Any())
                {
                    dbContext.Companys.AddRange(await DataValues.CompanyDataAsync(dbContext, userManager));

                    await dbContext.SaveChangesAsync();
                }

                await AddData.SeedSupervisor(dbContext, userManager);

                await AddData.SeedRepairPerson(dbContext, userManager);

                ////add listAreaWorking for Admin01
                //ApplicationUser admin = await userManager.FindByNameAsync(DataValues.adminName01);
                //List<string> listAreaWorking = (from arW in dbContext.AreaWorkings
                //                                where arW.AdminId == admin.Id
                //                                select arW.Id).ToList();
                //admin.ListAreaWorkingId = String_List.ToString(listAreaWorking);
                //await userManager.UpdateAsync(admin);

                //await dbContext.SaveChangesAsync();

                //Seed Request
                if (!dbContext.Requests.Any())
                {
                    dbContext.Requests.AddRange(await DataValues.RequestDataAsync(dbContext, userManager));

                    await dbContext.SaveChangesAsync();
                }
            }
            catch (Exception ex)
            {
                if (retryForAvailability < 10)
                {
                    retryForAvailability++;
                    var log = loggerFactory.CreateLogger <TmanagerServiceContext>();
                    log.LogError(ex.Message);
                    await SeedAsync(dbContext, userManager, roleManager, loggerFactory, retryForAvailability);
                }
            }
        }
Пример #6
0
        //public static async Task<IEnumerable<AreaWorking>> AreaWorkingDataAsync(TmanagerServiceContext dbContext, UserManager<ApplicationUser> userManager)
        //{
        //    ApplicationUser admin = await userManager.FindByNameAsync(AdminData(dbContext).ToArray().FirstOrDefault().UserName);

        //    return new List<AreaWorking>()
        //    {
        //        new AreaWorking { AdminId = admin.Id, AreaName = areaWorkingName01, Status = true},
        //        new AreaWorking { AdminId = admin.Id, AreaName = "Cẩm Lệ, Đà Nẵng", Status = true},
        //        new AreaWorking { AdminId = admin.Id, AreaName = "Sơn Trà, Đà Nẵng", Status = true},
        //        new AreaWorking { AdminId = admin.Id, AreaName = "Liên Chiểu, Đà Nẵng", Status = false}
        //    };
        //}

        public static async Task <IEnumerable <ApplicationUser> > SupervisorDataAsync(TmanagerServiceContext dbContext, UserManager <ApplicationUser> userManager)
        {
            ApplicationUser admin = await userManager.FindByNameAsync(AdminData(dbContext).ToArray().FirstOrDefault().UserName);

            //AreaWorking[] areaWorkingData = dbContext.AreaWorkings.ToArray();
            Company departmentOfConstruction = dbContext.Companys.FirstOrDefault(c => c.Name == DepartmentOfConstruction);

            return(new List <ApplicationUser>()
            {
                new ApplicationUser {
                    UserName = "******", Email = "*****@*****.**", SecurityStamp = Guid.NewGuid().ToString(),
                    FirstName = "Thuần", LastName = "Hồ Đăng", EmailConfirmed = true, Address = "33 Tô Hiệu, Huế",
                    Role = RoleValues.Supervisor.ToDescription(), IsEnabled = true, Note = "Supervisor", Gender = Gender.Male.ToDescription(),
                    DateOfBirth = DateTime.ParseExact("18/08/1989", "dd/MM/yyyy", ci), PhoneNumber = "0965784235",
                    Avatar = "http://res.cloudinary.com/dj9j7j4sf/image/upload/v1541990232/jx4eptaytrv0yjz1ipkr.jpg",
                    AdminId = admin.Id, Company = departmentOfConstruction,
                },
                new ApplicationUser {
                    UserName = "******", Email = "*****@*****.**", SecurityStamp = Guid.NewGuid().ToString(),
                    FirstName = "Tấn", LastName = "Nguyễn Ngọc", EmailConfirmed = true, Address = "73 Tô Hiệu, Huế",
                    Role = RoleValues.Supervisor.ToDescription(), IsEnabled = true, Note = "Supervisor", Gender = Gender.Female.ToDescription(),
                    DateOfBirth = DateTime.ParseExact("18/08/1995", "dd/MM/yyyy", ci), PhoneNumber = "0986523475",
                    Avatar = "http://res.cloudinary.com/dj9j7j4sf/image/upload/v1541990232/fwegbvhw0adpwn0y2mii.jpg",
                    AdminId = admin.Id, Company = departmentOfConstruction,
                }
            });
        }
Пример #7
0
        public static async Task <IEnumerable <Request> > RequestDataAsync(TmanagerServiceContext dbContext, UserManager <ApplicationUser> userManager)
        {
            ApplicationUser admin = await userManager.FindByNameAsync(AdminData(dbContext).ToArray().FirstOrDefault().UserName);

            ApplicationUser supervisor01 = await userManager.FindByNameAsync((await SupervisorDataAsync(dbContext, userManager)).ToArray().ElementAt(0).UserName);

            ApplicationUser supervisor02 = await userManager.FindByNameAsync((await SupervisorDataAsync(dbContext, userManager)).ToArray().ElementAt(1).UserName);

            ApplicationUser repairPerson01 = await userManager.FindByNameAsync((await RepairPersonDataAsync(dbContext, userManager)).ToArray().ElementAt(0).UserName);

            ApplicationUser repairPerson02 = await userManager.FindByNameAsync((await RepairPersonDataAsync(dbContext, userManager)).ToArray().ElementAt(1).UserName);

            //AreaWorking areaWorking = dbContext.AreaWorkings.FirstOrDefault(a => a.AreaName == areaWorkingName01);
            //AreaWorking[] areaWorkingData = dbContext.AreaWorkings.ToArray();
            Company  company = dbContext.Companys.FirstOrDefault(c => c.Name == companyName01);
            DateTime now     = DateTime.Now;

            return(new List <Request>()
            {
                new Request {
                    Content = "ổ gà có trứng gà", PictureRequest = "http://res.cloudinary.com/dj9j7j4sf/image/upload/v1541144270/bbhvdqd1jz9xxrcvszc3.jpg,NStr~| http://res.cloudinary.com/dj9j7j4sf/image/upload/v1541144270/xpr0nra3lfk1fxtqhodz.jpg,NStr~| http://res.cloudinary.com/dj9j7j4sf/image/upload/v1541144271/dd8zsydl9hxhwt3qzcrl.jpg",
                    PictureFinish = "http://res.cloudinary.com/dj9j7j4sf/image/upload/v1541144224/np7rbqxwektldyxw1kat.jpg,NStr~| http://res.cloudinary.com/dj9j7j4sf/image/upload/v1541144225/sdapicoqbredxjrfdf5u.jpg",
                    Latlng_latitude = 16.047194, Latlng_longitude = 108.211754, Supervisor = supervisor01, RepairPerson = repairPerson01,
                    Address = "403 Đường Trưng Nữ Vương, Phường Hòa Thuận Tây, Quận Hải Châu, Thành Phố Đà Nẵng, Hòa Thuận Nam, Hải Châu, Đà Nẵng 550000, Việt Nam",
                    Status = RequestStatus.Approved.ToDescription(), Company = company,
                    TimeBeginRequest = now.AddSeconds(-2563125), TimeReceiveRequest = now.AddSeconds(-2043125),
                    TimeFinish = now.AddSeconds(-563425), TimeConfirm = now.AddSeconds(-253125)
                },

                new Request {
                    Content = "ổ vịt, ổ trâu, ổ khủng long", PictureRequest = "http://res.cloudinary.com/dj9j7j4sf/image/upload/v1541144161/bfdm3bknugvdfoh5u6ec.jpg",
                    PictureFinish = "http://res.cloudinary.com/dj9j7j4sf/image/upload/v1541144226/zotgb0n59b3qgpq8xour.jpg,NStr~| http://res.cloudinary.com/dj9j7j4sf/image/upload/v1541144226/bkdzmmsu3gbeny0egdbf.jpg",
                    Latlng_latitude = 16.041583, Latlng_longitude = 108.211631, Supervisor = supervisor01, RepairPerson = repairPerson01,
                    Address = "86-118 Lương Nhữ Hộc, Hoà Cường Bắc, Hải Châu, Đà Nẵng 550000, Việt Nam",
                    Status = RequestStatus.Done.ToDescription(), Company = company,
                    TimeBeginRequest = now.AddSeconds(-3563125), TimeReceiveRequest = now.AddSeconds(-3043125),
                    TimeFinish = now.AddSeconds(-1563425)
                },

                new Request {
                    Content = "ổ gà có trứng gà", PictureRequest = "http://res.cloudinary.com/dj9j7j4sf/image/upload/v1541144271/dd8zsydl9hxhwt3qzcrl.jpg",
                    PictureFinish = "http://res.cloudinary.com/dj9j7j4sf/image/upload/v1541144225/sdapicoqbredxjrfdf5u.jpg",
                    Latlng_latitude = 16.047194, Latlng_longitude = 108.211754, Supervisor = supervisor01, RepairPerson = repairPerson01,
                    Address = "403 Đường Trưng Nữ Vương, Phường Hòa Thuận Tây, Quận Hải Châu, Thành Phố Đà Nẵng, Hòa Thuận Nam, Hải Châu, Đà Nẵng 550000, Việt Nam",
                    Status = RequestStatus.ToDo.ToDescription(), Company = company,
                    TimeBeginRequest = now.AddSeconds(-2563125), TimeReceiveRequest = now.AddSeconds(-2043125),
                    TimeFinish = now.AddSeconds(-563425), TimeConfirm = now.AddSeconds(-253125)
                },

                new Request {
                    Content = "ổ vịt, ổ trâu, ổ khủng long", PictureRequest = "http://res.cloudinary.com/dj9j7j4sf/image/upload/v1541144160/yvswxuhbcbbzrba2ti10.jpg,NStr~| http://res.cloudinary.com/dj9j7j4sf/image/upload/v1541144161/bfdm3bknugvdfoh5u6ec.jpg",
                    PictureFinish = "http://res.cloudinary.com/dj9j7j4sf/image/upload/v1541144225/sdapicoqbredxjrfdf5u.jpg,NStr~| http://res.cloudinary.com/dj9j7j4sf/image/upload/v1541144226/zotgb0n59b3qgpq8xour.jpg,NStr~| http://res.cloudinary.com/dj9j7j4sf/image/upload/v1541144226/bkdzmmsu3gbeny0egdbf.jpg",
                    Latlng_latitude = 16.041583, Latlng_longitude = 108.211631, Supervisor = supervisor01, RepairPerson = repairPerson01,
                    Address = "86-118 Lương Nhữ Hộc, Hoà Cường Bắc, Hải Châu, Đà Nẵng 550000, Việt Nam",
                    Status = RequestStatus.ToDo.ToDescription(), Company = company,
                    TimeBeginRequest = now.AddSeconds(-3563125), TimeReceiveRequest = now.AddSeconds(-3043125),
                    TimeFinish = now.AddSeconds(-1563425)
                },



                new Request {
                    Content = "ổ gà có trứng gà", PictureRequest = "http://res.cloudinary.com/dj9j7j4sf/image/upload/v1541144270/bbhvdqd1jz9xxrcvszc3.jpg,NStr~| http://res.cloudinary.com/dj9j7j4sf/image/upload/v1541144270/xpr0nra3lfk1fxtqhodz.jpg,NStr~| http://res.cloudinary.com/dj9j7j4sf/image/upload/v1541144271/dd8zsydl9hxhwt3qzcrl.jpg",
                    PictureFinish = "http://res.cloudinary.com/dj9j7j4sf/image/upload/v1541144224/np7rbqxwektldyxw1kat.jpg,NStr~| http://res.cloudinary.com/dj9j7j4sf/image/upload/v1541144225/sdapicoqbredxjrfdf5u.jpg",
                    Latlng_latitude = 16.047194, Latlng_longitude = 108.211754, Supervisor = supervisor02, RepairPerson = repairPerson01,
                    Address = "403 Đường Trưng Nữ Vương, Phường Hòa Thuận Tây, Quận Hải Châu, Thành Phố Đà Nẵng, Hòa Thuận Nam, Hải Châu, Đà Nẵng 550000, Việt Nam",
                    Status = RequestStatus.Approved.ToDescription(), Company = company,
                    TimeBeginRequest = now.AddSeconds(-2563125), TimeReceiveRequest = now.AddSeconds(-2043125),
                    TimeFinish = now.AddSeconds(-563425), TimeConfirm = now.AddSeconds(-253125)
                },

                new Request {
                    Content = "ổ vịt, ổ trâu, ổ khủng long", PictureRequest = "http://res.cloudinary.com/dj9j7j4sf/image/upload/v1541144161/bfdm3bknugvdfoh5u6ec.jpg",
                    PictureFinish = "http://res.cloudinary.com/dj9j7j4sf/image/upload/v1541144226/zotgb0n59b3qgpq8xour.jpg,NStr~| http://res.cloudinary.com/dj9j7j4sf/image/upload/v1541144226/bkdzmmsu3gbeny0egdbf.jpg",
                    Latlng_latitude = 16.041583, Latlng_longitude = 108.211631, Supervisor = supervisor02, RepairPerson = repairPerson01,
                    Address = "86-118 Lương Nhữ Hộc, Hoà Cường Bắc, Hải Châu, Đà Nẵng 550000, Việt Nam",
                    Status = RequestStatus.Done.ToDescription(), Company = company,
                    TimeBeginRequest = now.AddSeconds(-3563125), TimeReceiveRequest = now.AddSeconds(-3043125),
                    TimeFinish = now.AddSeconds(-1563425)
                },

                new Request {
                    Content = "ổ gà có trứng gà", PictureRequest = "http://res.cloudinary.com/dj9j7j4sf/image/upload/v1541144271/dd8zsydl9hxhwt3qzcrl.jpg",
                    PictureFinish = "http://res.cloudinary.com/dj9j7j4sf/image/upload/v1541144225/sdapicoqbredxjrfdf5u.jpg",
                    Latlng_latitude = 16.047194, Latlng_longitude = 108.211754, Supervisor = supervisor02, RepairPerson = repairPerson01,
                    Address = "403 Đường Trưng Nữ Vương, Phường Hòa Thuận Tây, Quận Hải Châu, Thành Phố Đà Nẵng, Hòa Thuận Nam, Hải Châu, Đà Nẵng 550000, Việt Nam",
                    Status = RequestStatus.ToDo.ToDescription(), Company = company,
                    TimeBeginRequest = now.AddSeconds(-2563125), TimeReceiveRequest = now.AddSeconds(-2043125),
                    TimeFinish = now.AddSeconds(-563425), TimeConfirm = now.AddSeconds(-253125)
                },

                new Request {
                    Content = "ổ vịt, ổ trâu, ổ khủng long", PictureRequest = "http://res.cloudinary.com/dj9j7j4sf/image/upload/v1541144160/yvswxuhbcbbzrba2ti10.jpg,NStr~| http://res.cloudinary.com/dj9j7j4sf/image/upload/v1541144161/bfdm3bknugvdfoh5u6ec.jpg",
                    PictureFinish = "http://res.cloudinary.com/dj9j7j4sf/image/upload/v1541144225/sdapicoqbredxjrfdf5u.jpg,NStr~| http://res.cloudinary.com/dj9j7j4sf/image/upload/v1541144226/zotgb0n59b3qgpq8xour.jpg,NStr~| http://res.cloudinary.com/dj9j7j4sf/image/upload/v1541144226/bkdzmmsu3gbeny0egdbf.jpg",
                    Latlng_latitude = 16.041583, Latlng_longitude = 108.211631, Supervisor = supervisor02, RepairPerson = repairPerson01,
                    Address = "86-118 Lương Nhữ Hộc, Hoà Cường Bắc, Hải Châu, Đà Nẵng 550000, Việt Nam",
                    Status = RequestStatus.ToDo.ToDescription(), Company = company,
                    TimeBeginRequest = now.AddSeconds(-3563125), TimeReceiveRequest = now.AddSeconds(-3043125),
                    TimeFinish = now.AddSeconds(-1563425)
                }
            });
        }
Пример #8
0
        public static async Task <IEnumerable <ApplicationUser> > RepairPersonDataAsync(TmanagerServiceContext dbContext, UserManager <ApplicationUser> userManager)
        {
            ApplicationUser admin = await userManager.FindByNameAsync(AdminData(dbContext).ToArray().FirstOrDefault().UserName);

            Company company = dbContext.Companys.FirstOrDefault(c => c.Name == companyName01);

            return(new List <ApplicationUser>()
            {
                new ApplicationUser {
                    UserName = "******", Email = "*****@*****.**", SecurityStamp = Guid.NewGuid().ToString(),
                    FirstName = "Hiền", LastName = "Nguyễn Văn", EmailConfirmed = true, Address = "73 Tô Thất Tùng, Huế",
                    Role = RoleValues.RepairPerson.ToDescription(), IsEnabled = true, Note = "Repair Person", Gender = Gender.Female.ToDescription(),
                    DateOfBirth = DateTime.ParseExact("20/10/1995", "dd/MM/yyyy", ci), PhoneNumber = "0965847596",
                    Avatar = "http://res.cloudinary.com/dj9j7j4sf/image/upload/v1541990231/ilivdpzc54qdjomgggeo.jpg",
                    AdminId = admin.Id, Company = company
                },
                new ApplicationUser {
                    UserName = "******", Email = "*****@*****.**", SecurityStamp = Guid.NewGuid().ToString(),
                    FirstName = "Hậu", LastName = "Nguyễn Văn", EmailConfirmed = true, Address = "43 Tô Thất Tùng, Huế",
                    Role = RoleValues.RepairPerson.ToDescription(), IsEnabled = true, Note = "Repair Person", Gender = Gender.Male.ToDescription(),
                    DateOfBirth = DateTime.ParseExact("20/10/1994", "dd/MM/yyyy", ci), PhoneNumber = "0968572435",
                    Avatar = "http://res.cloudinary.com/dj9j7j4sf/image/upload/v1541990446/cincgj3ysgq69ijkb3ou.png",
                    AdminId = admin.Id, Company = company
                }
            });
        }