Example #1
0
        public async Task <IActionResult> PutHaandvaerker(int id, Haandvaerker haandvaerker)
        {
            if (id != haandvaerker.HaandvaerkerId)
            {
                return(BadRequest());
            }

            _context.Entry(haandvaerker).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!HaandvaerkerExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <IActionResult> PutVaerktoej(long id, Vaerktoej vaerktoej)
        {
            if (id != vaerktoej.VTId)
            {
                return(BadRequest());
            }

            _context.Entry(vaerktoej).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!VaerktoejExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Example #3
0
        private async Task 建立訂單紀錄Async(Random random, List <Product> products)
        {
            for (int i = 0; i < 3; i++)
            {
                OrderMaster order = new OrderMaster()
                {
                    Name         = $"Order{i}",
                    OrderDate    = DateTime.Now.AddDays(random.Next(30)),
                    RequiredDate = DateTime.Now.AddDays(random.Next(30)),
                    ShippedDate  = DateTime.Now.AddDays(random.Next(30)),
                };
                context.Add(order);
                await context.SaveChangesAsync();

                var total = random.Next(1, 6);
                for (int j = 0; j < total; j++)
                {
                    OrderItem orderItem = new OrderItem()
                    {
                        Name          = $"OrderItem{j}",
                        OrderMasterId = order.Id,
                        ProductId     = products[j].Id,
                        Quantity      = 3,
                        ListPrice     = 168,
                    };
                    context.Add(orderItem);
                }
                await context.SaveChangesAsync();
            }
            CleanTrackingHelper.Clean <Product>(context);
            CleanTrackingHelper.Clean <OrderMaster>(context);
            CleanTrackingHelper.Clean <OrderItem>(context);
        }
        public async Task <VerifyRecordResult> AddAsync(TravelExpenseAdapterModel paraObject)
        {
            TravelExpense itemParameter = Mapper.Map <TravelExpense>(paraObject);

            CleanTrackingHelper.Clean <TravelExpense>(context);
            await context.TravelExpense
            .AddAsync(itemParameter);

            await context.SaveChangesAsync();

            CleanTrackingHelper.Clean <TravelExpense>(context);
            return(VerifyRecordResultFactory.Build(true));
        }
        public async Task <VerifyRecordResult> AddAsync(LeaveCategoryAdapterModel paraObject)
        {
            LeaveCategory itemParameter = Mapper.Map <LeaveCategory>(paraObject);

            CleanTrackingHelper.Clean <LeaveCategory>(context);
            await context.LeaveCategory
            .AddAsync(itemParameter);

            await context.SaveChangesAsync();

            CleanTrackingHelper.Clean <LeaveCategory>(context);
            return(VerifyRecordResultFactory.Build(true));
        }
Example #6
0
        public async Task <VerifyRecordResult> AddAsync(ProjectAdapterModel paraObject)
        {
            Project itemParameter = Mapper.Map <Project>(paraObject);

            CleanTrackingHelper.Clean <Project>(context);
            await context.Project
            .AddAsync(itemParameter);

            await context.SaveChangesAsync();

            CleanTrackingHelper.Clean <Project>(context);
            return(VerifyRecordResultFactory.Build(true));
        }
Example #7
0
        public async Task <VerifyRecordResult> AddAsync(OrderMasterAdapterModel paraObject)
        {
            CleanTrackingHelper.Clean <OrderMaster>(context);
            OrderMaster itemParameter = Mapper.Map <OrderMaster>(paraObject);

            CleanTrackingHelper.Clean <OrderMaster>(context);
            await context.OrderMaster
            .AddAsync(itemParameter);

            await context.SaveChangesAsync();

            CleanTrackingHelper.Clean <OrderMaster>(context);
            return(VerifyRecordResultFactory.Build(true));
        }
        public async Task <VerifyRecordResult> AddAsync(WorkingLogDetailAdapterModel paraObject)
        {
            WorkingLogDetail itemParameter = Mapper.Map <WorkingLogDetail>(paraObject);

            CleanTrackingHelper.Clean <WorkingLogDetail>(context);
            await context.WorkingLogDetail
            .AddAsync(itemParameter);

            await context.SaveChangesAsync();

            var id = itemParameter.WorkingLogId;

            CleanTrackingHelper.Clean <WorkingLogDetail>(context);
            await CountingWorkingHour(id);

            return(VerifyRecordResultFactory.Build(true));
        }
Example #9
0
        public async Task <VerifyRecordResult> AddAsync(ExceptionRecordAdapterModel paraObject)
        {
            ExceptionRecord itemParameter = Mapper.Map <ExceptionRecord>(paraObject);

            CleanTrackingHelper.Clean <ExceptionRecord>(context);
            try
            {
                await context.ExceptionRecord
                .AddAsync(itemParameter);

                await context.SaveChangesAsync();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            CleanTrackingHelper.Clean <ExceptionRecord>(context);
            return(VerifyRecordResultFactory.Build(true));
        }
        public async Task <VerifyRecordResult> AddAsync(MyUserAdapterModel paraObject)
        {
            try
            {
                MyUser itemParameter = Mapper.Map <MyUser>(paraObject);
                CleanTrackingHelper.Clean <MyUser>(context);
                await context.MyUser
                .AddAsync(itemParameter);

                await context.SaveChangesAsync();

                CleanTrackingHelper.Clean <MyUser>(context);
                return(VerifyRecordResultFactory.Build(true));
            }
            catch (Exception ex)
            {
                Logger.LogError(ex, "新增記錄發生例外異常");
                return(VerifyRecordResultFactory.Build(false, "新增記錄發生例外異常", ex));
            }
        }
Example #11
0
        public async Task ChangePassword(MyUserAdapterModel myUserAdapterModel, string newPassword)
        {
            string encodePassword =
                PasswordHelper.GetPasswordSHA(myUserAdapterModel.Salt, newPassword);

            myUserAdapterModel.Password = encodePassword;
            var myUser = Mapper.Map <MyUser>(myUserAdapterModel);

            CleanTrackingHelper.Clean <MyUser>(context);
            context.Entry(myUser).State = EntityState.Modified;
            await context.SaveChangesAsync();

            CleanTrackingHelper.Clean <MyUser>(context);
        }
        public static async Task SaveChangesWithIdentityInsertAsync <T>([NotNull] this BackendDBContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }
            await using var transaction = await context.Database.BeginTransactionAsync();

            await context.EnableIdentityInsertAsync <T>();

            await context.SaveChangesAsync();

            await context.EnableIdentityInsertAsync <T>();

            await transaction.CommitAsync();
        }
        public static async Task SaveChangesWithoutIdentityInsertAsync <T>([NotNull] this BackendDBContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }
            await using var transaction = await context.Database.BeginTransactionAsync();

            await context.EnableIdentityInsertAsync <T>();

            try
            {
                await context.SaveChangesAsync();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            await context.EnableIdentityInsertAsync <T>();

            await transaction.CommitAsync();
        }
        public async Task CheckPasswordAge(CancellationToken cancellationToken)
        {
            CleanTrackingHelper.Clean <AccountPolicy>(context);
            CleanTrackingHelper.Clean <MyUser>(context);

            AccountPolicy AccountPolicy = await context.AccountPolicy
                                          .OrderBy(x => x.Id)
                                          .FirstOrDefaultAsync();

            cancellationToken.ThrowIfCancellationRequested();
            List <MyUser> myUsers = await context.MyUser
                                    .ToListAsync();

            cancellationToken.ThrowIfCancellationRequested();

            var enableCheckPasswordAge = AccountPolicy.EnableCheckPasswordAge;
            var passwordAge            = AccountPolicy.PasswordAge;

            if (enableCheckPasswordAge == true)
            {
                foreach (var item in myUsers)
                {
                    cancellationToken.ThrowIfCancellationRequested();
                    if (DateTime.Now > item.ForceChangePasswordDatetime)
                    {
                        #region 該使用者已經達到要變更密碼的時間
                        item.ForceChangePasswordDatetime = DateTime.Now.AddDays(passwordAge);
                        item.ForceChangePassword         = true;
                        context.Update(item);
                        await context.SaveChangesAsync();

                        #endregion
                    }
                }
            }

            CleanTrackingHelper.Clean <MyUser>(context);
            CleanTrackingHelper.Clean <AccountPolicy>(context);
        }
Example #15
0
        async Task 建立片語分類與文字Async()
        {
            List <PhaseMessage> PhaseMessage = new List <PhaseMessage>();

            int cc = 10;

            #region 簽核表單使用的輸入片語
            var phaseCategory = new PhaseCategory()
            {
                Name         = "簽核表單使用的輸入片語",
                Enable       = true,
                OrderNumber  = cc++,
                PhaseMessage = new List <PhaseMessage>()
            };
            await context.PhaseCategory.AddAsync(phaseCategory);

            await context.SaveChangesAsync();

            PhaseMessage = new List <PhaseMessage>()
            {
                new PhaseMessage()
                {
                    Content         = "做得很好,繼續努力",
                    Enable          = true,
                    Code            = cc.ToString("D5"),
                    OrderNumber     = cc++,
                    PhaseCategoryId = phaseCategory.Id,
                },
                new PhaseMessage()
                {
                    Content         = "用來形容情緒不會表露出來的人",
                    Enable          = true,
                    Code            = cc.ToString("D5"),
                    OrderNumber     = cc++,
                    PhaseCategoryId = phaseCategory.Id,
                },
                new PhaseMessage()
                {
                    Content         = "像魚一樣的喝,表示喝很多,尤其指喝很多酒",
                    Enable          = true,
                    Code            = cc.ToString("D5"),
                    OrderNumber     = cc++,
                    PhaseCategoryId = phaseCategory.Id,
                },
                new PhaseMessage()
                {
                    Content         = "意指非常重要、有權力或是具有影響力的人",
                    Enable          = true,
                    Code            = cc.ToString("D5"),
                    OrderNumber     = cc++,
                    PhaseCategoryId = phaseCategory.Id,
                },
            };
            await context.BulkInsertAsync(PhaseMessage);

            #endregion
            #region 改善報告的輸入片語
            phaseCategory = new PhaseCategory()
            {
                Name         = "改善報告的輸入片語",
                Enable       = true,
                OrderNumber  = cc++,
                PhaseMessage = new List <PhaseMessage>()
            };
            await context.PhaseCategory.AddAsync(phaseCategory);

            await context.SaveChangesAsync();

            PhaseMessage = new List <PhaseMessage>()
            {
                new PhaseMessage()
                {
                    Content         = "加速意見溝通",
                    Enable          = true,
                    Code            = cc.ToString("D5"),
                    OrderNumber     = cc++,
                    PhaseCategoryId = phaseCategory.Id,
                },
                new PhaseMessage()
                {
                    Content         = "○○○○案,簽會意見綜合說明如下,請鑒核",
                    Enable          = true,
                    Code            = cc.ToString("D5"),
                    OrderNumber     = cc++,
                    PhaseCategoryId = phaseCategory.Id,
                },
                new PhaseMessage()
                {
                    Content         = "會簽意見一略以,○○○○○○○○○…",
                    Enable          = true,
                    Code            = cc.ToString("D5"),
                    OrderNumber     = cc++,
                    PhaseCategoryId = phaseCategory.Id,
                },
                new PhaseMessage()
                {
                    Content         = "會簽意見二略以,○○○○○○○○○…",
                    Enable          = true,
                    Code            = cc.ToString("D5"),
                    OrderNumber     = cc++,
                    PhaseCategoryId = phaseCategory.Id,
                },
                new PhaseMessage()
                {
                    Content         = "「是否允當」?",
                    Enable          = true,
                    Code            = cc.ToString("D5"),
                    OrderNumber     = cc++,
                    PhaseCategoryId = phaseCategory.Id,
                },
                new PhaseMessage()
                {
                    Content         = "……因故不克擔任…,予以改派…",
                    Enable          = true,
                    Code            = cc.ToString("D5"),
                    OrderNumber     = cc++,
                    PhaseCategoryId = phaseCategory.Id,
                },
            };
            await context.BulkInsertAsync(PhaseMessage);

            #endregion
            #region 雜項輸入片語
            phaseCategory = new PhaseCategory()
            {
                Name         = "雜項輸入片語",
                Enable       = true,
                OrderNumber  = cc++,
                PhaseMessage = new List <PhaseMessage>()
            };
            await context.PhaseCategory.AddAsync(phaseCategory);

            await context.SaveChangesAsync();

            PhaseMessage = new List <PhaseMessage>()
            {
                new PhaseMessage()
                {
                    Content         = "可以嗎?",
                    Enable          = true,
                    Code            = cc.ToString("D5"),
                    OrderNumber     = cc++,
                    PhaseCategoryId = phaseCategory.Id,
                },
                new PhaseMessage()
                {
                    Content         = "有關本校進修部學生向 鈞部「部長信箱」反映課程標準一案,本校已查明原委,謹檢陳查核報告乙份(如附件),敬請 鑒核。",
                    Enable          = true,
                    Code            = cc.ToString("D5"),
                    OrderNumber     = cc++,
                    PhaseCategoryId = phaseCategory.Id,
                },
            };
            await context.BulkInsertAsync(PhaseMessage);

            #endregion
        }
        public async Task <VerifyRecordResult> AddAsync(FlowMasterAdapterModel paraObject)
        {
            try
            {
                CleanTrackingHelper.Clean <FlowMaster>(context);
                CleanTrackingHelper.Clean <FlowUser>(context);
                CleanTrackingHelper.Clean <FlowHistory>(context);
                CleanTrackingHelper.Clean <MyUser>(context);
                FlowMaster itemParameter = Mapper.Map <FlowMaster>(paraObject);
                CleanTrackingHelper.Clean <FlowMaster>(context);
                await context.FlowMaster
                .AddAsync(itemParameter);

                await context.SaveChangesAsync();

                #region 產生要審核的使用者清單
                var user = await context.MyUser
                           .FirstOrDefaultAsync(x => x.Id == itemParameter.MyUserId);

                FlowUser auditUser = new FlowUser()
                {
                    MyUserId     = itemParameter.MyUserId,
                    FlowMasterId = itemParameter.Id,
                    Enable       = true,
                    Level        = 0,
                    OnlyCC       = false,
                    Name         = "發文者",
                };
                await context.FlowUser.AddAsync(auditUser);

                var policyDetails = await context.PolicyDetail
                                    .Where(x => x.PolicyHeaderId == paraObject.PolicyHeaderId)
                                    .OrderBy(x => x.Level)
                                    .ToListAsync();

                foreach (var item in policyDetails)
                {
                    if (item.Enable == false)
                    {
                        continue;
                    }
                    auditUser = new FlowUser()
                    {
                        MyUserId     = item.MyUserId,
                        FlowMasterId = itemParameter.Id,
                        Enable       = true,
                        Level        = item.Level,
                        OnlyCC       = item.OnlyCC,
                        Name         = item.Name,
                    };
                    await context.FlowUser.AddAsync(auditUser);
                }

                itemParameter.NextMyUserName = user.Name;
                context.FlowMaster.Update(itemParameter);
                await context.SaveChangesAsync();

                #endregion

                #region 增加簽核流程歷史紀錄 - 建立簽核表單
                FlowHistory history = new FlowHistory()
                {
                    FlowMasterId = itemParameter.Id,
                    MyUserId     = itemParameter.MyUserId,
                    Approve      = true,
                    Summary      = $"{user.Account} / {user.Name} 建立簽核表單",
                    Comment      = $"簽核單草稿",
                    Updatetime   = DateTime.Now,
                };
                await context.FlowHistory.AddAsync(history);

                await context.SaveChangesAsync();

                #endregion

                CleanTrackingHelper.Clean <FlowMaster>(context);
                CleanTrackingHelper.Clean <FlowUser>(context);
                CleanTrackingHelper.Clean <FlowHistory>(context);
                CleanTrackingHelper.Clean <MyUser>(context);
                return(VerifyRecordResultFactory.Build(true));
            }
            catch (Exception ex)
            {
                Logger.LogError(ex, "新增記錄發生例外異常");
                return(VerifyRecordResultFactory.Build(false, "新增記錄發生例外異常", ex));
            }
        }
Example #17
0
        private async Task 建立使用者紀錄Async(string InitializationMode)
        {
            #region 建立使用者紀錄

            CleanTrackingHelper.Clean <MyUser>(context);
            #region 取得各種需要的角色
            var menuRole開發者 = await context.MenuRole
                              .AsNoTracking()
                              .FirstOrDefaultAsync(x => x.Name == MagicHelper.開發者功能表角色);

            var menuRole系統管理員 = await context.MenuRole
                                .AsNoTracking()
                                .FirstOrDefaultAsync(x => x.Name == MagicHelper.系統管理員功能表角色);

            var menuRole使用者 = await context.MenuRole
                              .AsNoTracking()
                              .FirstOrDefaultAsync(x => x.Name == MagicHelper.使用者功能表角色);

            #endregion

            #region 建立 開發者
            var myUser = new MyUser()
            {
                Account                     = $"god",
                Name                        = $"開發者",
                MenuRoleId                  = menuRole開發者.Id,
                Status                      = true,
                Salt                        = Guid.NewGuid().ToString(),
                ForceLogoutDatetime         = DateTime.Now.AddDays(-1),
                ForceChangePassword         = false,
                ForceChangePasswordDatetime = DateTime.Now.AddDays(42),
                LoginFailTimes              = 0,
                LoginFailUnlockDatetime     = DateTime.Now.AddDays(-1),
                LastLoginDatetime           = DateTime.Now,
                Email                       = "*****@*****.**",
            };

            myUser.Salt     = Guid.NewGuid().ToString();
            myUser.Password =
                PasswordHelper.GetPasswordSHA(myUser.Salt + "Vulcan", "abc");

            context.Add(myUser);
            await context.SaveChangesAsync();

            CleanTrackingHelper.Clean <MyUser>(context);
            #endregion

            #region 建立 系統管理員
            var adminMyUser = new MyUser()
            {
                Account                     = $"{MagicHelper.系統管理員帳號}",
                Name                        = $"系統管理員 {MagicHelper.系統管理員帳號}",
                MenuRoleId                  = menuRole系統管理員.Id,
                Status                      = true,
                Salt                        = Guid.NewGuid().ToString(),
                ForceLogoutDatetime         = DateTime.Now.AddDays(-1),
                ForceChangePassword         = false,
                ForceChangePasswordDatetime = DateTime.Now.AddDays(42),
                LoginFailTimes              = 0,
                LoginFailUnlockDatetime     = DateTime.Now.AddDays(-1),
                LastLoginDatetime           = DateTime.Now,
                Email                       = "*****@*****.**",
            };
            var adminRawPassword = "******";
            adminMyUser.Password =
                PasswordHelper.GetPasswordSHA(adminMyUser.Salt, adminRawPassword);

            context.Add(adminMyUser);
            await context.SaveChangesAsync();

            CleanTrackingHelper.Clean <MyUser>(context);
            #endregion

            if (InitializationMode == "開發模式")
            {
                #region 建立 使用者
                foreach (var item in MagicHelper.使用者帳號)
                {
                    var itemMyUser = await context.MyUser
                                     .AsNoTracking()
                                     .FirstOrDefaultAsync(x => x.Name == item);

                    if (itemMyUser == null)
                    {
                        itemMyUser = new MyUser()
                        {
                            Account                     = $"{item}",
                            Name                        = $"使用者 {item}",
                            MenuRoleId                  = menuRole使用者.Id,
                            Status                      = true,
                            Salt                        = Guid.NewGuid().ToString(),
                            ForceLogoutDatetime         = DateTime.Now.AddDays(-1),
                            ForceChangePassword         = false,
                            ForceChangePasswordDatetime = DateTime.Now.AddDays(42),
                            LoginFailTimes              = 0,
                            LoginFailUnlockDatetime     = DateTime.Now.AddDays(-1),
                            LastLoginDatetime           = DateTime.Now,
                            Email                       = "*****@*****.**",
                        };
                        var userRawPassword = "******";
                        itemMyUser.Password =
                            PasswordHelper.GetPasswordSHA(itemMyUser.Salt, userRawPassword);

                        context.Add(itemMyUser);
                        await context.SaveChangesAsync();

                        CleanTrackingHelper.Clean <MyUser>(context);
                    }
                }
                #endregion
            }
            #endregion
        }
Example #18
0
        public async Task ChangePassword(MyUserAdapterModel myUserAdapterModel, string newPassword,
                                         string ip)
        {
            CleanTrackingHelper.Clean <SystemEnvironment>(context);
            CleanTrackingHelper.Clean <MyUserPasswordHistory>(context);
            SystemEnvironment systemEnvironment = await context.SystemEnvironment
                                                  .OrderBy(x => x.Id)
                                                  .FirstOrDefaultAsync();

            string encodePassword =
                PasswordHelper.GetPasswordSHA(myUserAdapterModel.Salt, newPassword);

            myUserAdapterModel.Password = encodePassword;
            var myUser = Mapper.Map <MyUser>(myUserAdapterModel);

            CleanTrackingHelper.Clean <MyUser>(context);

            #region 更新下次要變更密碼的時間
            if (systemEnvironment.EnableCheckPasswordAge)
            {
                myUser.ForceChangePasswordDatetime = DateTime.Now
                                                     .AddDays(systemEnvironment.PasswordAge);
            }
            myUser.ForceChangePassword = false;
            #endregion

            context.Entry(myUser).State = EntityState.Modified;
            await context.SaveChangesAsync();

            if (systemEnvironment.EnablePasswordHistory == true)
            {
                MyUserPasswordHistory myUserPasswordHistory = new MyUserPasswordHistory()
                {
                    MyUserId = myUser.Id,
                    IP       = ip,
                    Password = myUser.Password,
                    ChangePasswordDatetime = DateTime.Now,
                };

                await context.AddAsync(myUserPasswordHistory);

                await context.SaveChangesAsync();

                while (true)
                {
                    #region 只會記錄下系統指定的變更密碼數量 systemEnvironment.PasswordHistory
                    var myUserPasswordHistories = await context.MyUserPasswordHistory
                                                  .Where(x => x.MyUserId == myUser.Id)
                                                  .OrderBy(x => x.ChangePasswordDatetime)
                                                  .ToListAsync();

                    if (myUserPasswordHistories.Count > systemEnvironment.PasswordHistory)
                    {
                        var first = myUserPasswordHistories.First();
                        context.Remove(first);
                        await context.SaveChangesAsync();

                        continue;
                    }
                    else
                    {
                        break;
                    }
                    #endregion
                }
            }
            CleanTrackingHelper.Clean <SystemEnvironment>(context);
            CleanTrackingHelper.Clean <MyUser>(context);
            CleanTrackingHelper.Clean <MyUserPasswordHistory>(context);
        }
        private async Task 建立系統定義參數Async()
        {
            #region 建立系統定義參數

            CleanTrackingHelper.Clean <AccountPolicy>(context);
            #region 新增系統定義紀錄
            AccountPolicy AccountPolicy = new AccountPolicy()
            {
                EnableLoginFailDetection  = true,
                LoginFailMaxTimes         = 3,
                LoginFailTimesLockMinutes = 5,
                MinimumPasswordLength     = 3,
                PasswordAge            = 42,
                PasswordComplexity     = 3, // PasswordStrength.Medium
                PasswordHistory        = 20,
                EnableCheckPasswordAge = true,
            };

            context.AccountPolicy.Add(AccountPolicy);
            await context.SaveChangesAsync();

            CleanTrackingHelper.Clean <AccountPolicy>(context);
            #endregion
            #endregion
        }
        public async Task InitDataAsync()
        {
            Random random = new Random();

            #region 適用於 Code First ,刪除資料庫與移除資料庫
            await context.Database.EnsureDeletedAsync();

            await context.Database.EnsureCreatedAsync();

            #endregion

            #region 建立使用者紀錄
            var items = Get姓名();
            CleanTrackingHelper.Clean <MyUser>(context);
            int idx = 1;
            foreach (var item in items)
            {
                var itemMyUser = await context.MyUser
                                 .AsNoTracking()
                                 .FirstOrDefaultAsync(x => x.Name == item);

                if (itemMyUser == null)
                {
                    itemMyUser = new MyUser()
                    {
                        Account  = $"user{idx}",
                        Name     = $"{item}",
                        Password = "******",
                    };
                    if (idx == 9)
                    {
                        itemMyUser.IsManager = true;
                    }
                    context.Add(itemMyUser);
                    await context.SaveChangesAsync();

                    idx++;
                }
            }
            CleanTrackingHelper.Clean <MyUser>(context);
            #endregion

            #region 建立產品紀錄
            CleanTrackingHelper.Clean <Product>(context);
            CleanTrackingHelper.Clean <Order>(context);
            CleanTrackingHelper.Clean <OrderItem>(context);
            List <Product> products = new List <Product>();
            for (int i = 0; i < 10; i++)
            {
                Product product = new Product()
                {
                    Name = $"Product{i}"
                };
                products.Add(product);
                context.Add(product);
            }
            await context.SaveChangesAsync();

            #endregion

            #region 建立產品紀錄
            for (int i = 0; i < 3; i++)
            {
                Order order = new Order()
                {
                    Name         = $"Order{i}",
                    OrderDate    = DateTime.Now.AddDays(random.Next(30)),
                    RequiredDate = DateTime.Now.AddDays(random.Next(30)),
                    ShippedDate  = DateTime.Now.AddDays(random.Next(30)),
                };
                context.Add(order);
                await context.SaveChangesAsync();

                var total = random.Next(1, 6);
                for (int j = 0; j < total; j++)
                {
                    OrderItem orderItem = new OrderItem()
                    {
                        Name      = $"OrderItem{j}",
                        OrderId   = order.Id,
                        ProductId = products[j].Id,
                        Quantity  = 3,
                        ListPrice = 168,
                    };
                    context.Add(orderItem);
                }
                await context.SaveChangesAsync();
            }
            CleanTrackingHelper.Clean <Product>(context);
            CleanTrackingHelper.Clean <Order>(context);
            CleanTrackingHelper.Clean <OrderItem>(context);
            #endregion
        }