public SystemLogService(BackendDBContext context, IMapper mapper,
                         ILogger <SystemLogService> logger)
 {
     this.context = context;
     Mapper       = mapper;
     Logger       = logger;
 }
Exemplo n.º 2
0
 public MyUserPasswordHistoryService(BackendDBContext context, IMapper mapper,
                                     ILogger <MyUserPasswordHistoryService> logger)
 {
     this.context = context;
     Mapper       = mapper;
     Logger       = logger;
 }
 public FlowHistoryService(BackendDBContext context, IMapper mapper,
                           ILogger <FlowHistoryService> logger)
 {
     this.context = context;
     Mapper       = mapper;
     Logger       = logger;
 }
 public AccountPolicyService(BackendDBContext context, IMapper mapper,
                             ILogger <AccountPolicyService> logger)
 {
     this.context = context;
     Mapper       = mapper;
     Logger       = logger;
 }
 public MenuRoleService(BackendDBContext context, IMapper mapper,
                        ILogger <MenuRoleService> logger)
 {
     this.context = context;
     Mapper       = mapper;
     Logger       = logger;
 }
Exemplo n.º 6
0
        static async Task Main(string[] args)
        {
            #region 取得 Blazor 專案內的連線字串
            IConfiguration config = new ConfigurationBuilder()
                                    .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
                                    .Build();
            string connectionString = config.GetConnectionString(MagicHelper.DefaultConnectionString);
            #endregion

            #region 使用取得的連線字串,建立 DbContext
            DbContextOptions <BackendDBContext> options = new DbContextOptionsBuilder <BackendDBContext>()
                                                          .UseSqlServer(connectionString)
                                                          .Options;
            BackendDBContext context = new BackendDBContext(options);
            #endregion

            Random random = new Random();
            Console.WriteLine("請輸入任意鍵後");
            Console.WriteLine("開始執行 Database Initialization");
            Console.ReadKey();

            #region 適用於 Code First ,刪除資料庫與移除資料庫
            Console.WriteLine($"請稍後,刪除資料庫中");
            await context.Database.EnsureDeletedAsync();

            Console.WriteLine($"請稍後,建立資料庫中");
            await context.Database.EnsureCreatedAsync();

            #endregion

            await GenerateTestDataAsync(context, random);
        }
Exemplo n.º 7
0
 public ChangePasswordService(BackendDBContext context, IMapper mapper,
                              AuthenticationStateProvider authenticationStateProvider)
 {
     this.context = context;
     Mapper       = mapper;
     AuthenticationStateProvider = authenticationStateProvider;
 }
Exemplo n.º 8
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, BackendDBContext db)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
                // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
                app.UseHsts();
            }
            //https://stackoverflow.com/questions/50507668/database-migrate-creating-database-but-not-tables-ef-net-core-2
            db.Database.Migrate(); //Udfør migration fra koden
            app.UseHttpsRedirection();
            app.UseStaticFiles();
            app.UseCookiePolicy();

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });
            //https://stackoverflow.com/questions/47101155/ambiguites-in-aspnet-core-2-0-using-swagger-in-web-api
            app.UseSwagger();

            app.UseSwaggerUI(c =>
            {
                c.SwaggerEndpoint("/swagger/v1/swagger.json", "F19ITONK Haandvaerker API V1");
            });
        }
 public static void Clean <T>(BackendDBContext context) where T : class
 {
     foreach (var fooXItem in context.Set <T>().Local)
     {
         context.Entry(fooXItem).State = EntityState.Detached;
     }
 }
Exemplo n.º 10
0
 public CategoryMainService(BackendDBContext context, IMapper mapper,
                            ILogger <CategoryMainService> logger)
 {
     this.context = context;
     Mapper       = mapper;
     Logger       = logger;
 }
 public PasswordPolicyService(BackendDBContext context, IMapper mapper,
                              ILogger <PasswordPolicyService> logger)
 {
     this.context = context;
     Mapper       = mapper;
     Logger       = logger;
 }
 public PhaseCategoryService(BackendDBContext context, IMapper mapper,
                             ILogger <PhaseCategoryService> logger)
 {
     this.context = context;
     Mapper       = mapper;
     Logger       = logger;
 }
Exemplo n.º 13
0
        public PolicyHeaderViewModel(IPolicyHeaderService CurrentService,
                                     BackendDBContext context, IMapper Mapper,
                                     TranscationResultHelper transcationResultHelper)
        {
            this.CurrentService = CurrentService;
            this.context        = context;
            mapper = Mapper;
            TranscationResultHelper = transcationResultHelper;
            PolicyHeaderSort.Initialization(SortConditions);

            #region 工具列按鈕初始化
            Toolbaritems.Add(new ItemModel()
            {
                Id          = ButtonIdHelper.ButtonIdAdd,
                Text        = "新增",
                TooltipText = "新增",
                Type        = ItemType.Button,
                PrefixIcon  = "mdi mdi-plus-thick",
                Align       = ItemAlign.Left,
            });
            Toolbaritems.Add(new ItemModel()
            {
                Id          = ButtonIdHelper.ButtonIdRefresh,
                Text        = "重新整理",
                TooltipText = "重新整理",
                PrefixIcon  = "mdi mdi-refresh",
                Align       = ItemAlign.Left,
            });
            Toolbaritems.Add("Search");
            #endregion
        }
Exemplo n.º 14
0
        public MailQueueViewModel(IMailQueueService CurrentService,
                                  BackendDBContext context, IMapper Mapper,
                                  TranscationResultHelper transcationResultHelper)
        {
            this.CurrentService = CurrentService;
            this.context        = context;
            mapper = Mapper;
            TranscationResultHelper = transcationResultHelper;
            MailQueueSort.Initialization(SortConditions);
            MailQueueStatusCondition.Initialization(MailQueueStatusConditions);
            CurrentMailQueueStatusCondition.Id    = MailQueueStatusConditions[0].Id;
            CurrentMailQueueStatusCondition.Title = MailQueueStatusConditions[0].Title;
            FilterMailQueueStatusCondition        = CurrentMailQueueStatusCondition.Id;

            #region 工具列按鈕初始化
            Toolbaritems.Add(new ItemModel()
            {
                Id          = ButtonIdHelper.ButtonIdAdd,
                Text        = "新增",
                TooltipText = "新增",
                Type        = ItemType.Button,
                PrefixIcon  = "mdi mdi-plus-thick",
                Align       = ItemAlign.Left,
            });
            Toolbaritems.Add(new ItemModel()
            {
                Id          = ButtonIdHelper.ButtonIdRefresh,
                Text        = "重新整理",
                TooltipText = "重新整理",
                PrefixIcon  = "mdi mdi-refresh",
                Align       = ItemAlign.Left,
            });
            Toolbaritems.Add("Search");
            #endregion
        }
Exemplo n.º 15
0
 public ProductService(BackendDBContext context, IMapper mapper,
                       ILogger <ProductService> logger)
 {
     this.context = context;
     Mapper       = mapper;
     Logger       = logger;
 }
 public WorkOrderService(BackendDBContext context, IMapper mapper,
                         ILogger <WorkOrderService> logger)
 {
     this.context = context;
     Mapper       = mapper;
     Logger       = logger;
 }
        private static async Task SetIdentityInsertAsync <T>([NotNull] BackendDBContext context, bool enable)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }
            //var entityType = context.Model.FindEntityType(typeof(T).Name);

            // We need dbcontext to access the models
            var models = context.Model;

            // Get all the entity types information
            var entityTypes = models.GetEntityTypes();
            // T is Name of class
            var entityType = entityTypes.First(t => t.ClrType == typeof(T));

            var value = enable ? "ON" : "OFF";

            try
            {
                var cmd = $"SET IDENTITY_INSERT {entityType.GetTableName()} {value}";
                await context.Database.ExecuteSqlRawAsync(cmd);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
        public ProductViewModel(IProductService CurrentService,
                                BackendDBContext context,
                                IMapper Mapper)
        {
            this.CurrentService = CurrentService;
            this.context        = context;
            mapper = Mapper;
            ProductSort.Initialization(SortConditions);

            Toolbaritems.Add(new ItemModel()
            {
                Id          = ButtonIdHelper.ButtonIdAdd,
                Text        = "新增",
                TooltipText = "新增",
                Type        = ItemType.Button,
                PrefixIcon  = "mdi mdi-plus-thick",
                Align       = ItemAlign.Left,
            });
            Toolbaritems.Add(new ItemModel()
            {
                Id          = ButtonIdHelper.ButtonIdRefresh,
                Text        = "重新整理",
                TooltipText = "重新整理",
                PrefixIcon  = "mdi mdi-refresh",
                Align       = ItemAlign.Left,
            });
            Toolbaritems.Add("Search");
        }
Exemplo n.º 19
0
 public PolicyDetailService(BackendDBContext context, IMapper mapper,
                            ILogger <PolicyDetailService> logger)
 {
     this.context = context;
     Mapper       = mapper;
     Logger       = logger;
 }
        private static async Task GenerateTestDataAsync(BackendDBContext context, Random random)
        {
            context.ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking;

            #region 產生開發用的測試資料
            //await GenerateMyUserAsync(context, random);
            #endregion
        }
 public MyUserService(BackendDBContext context, IMapper mapper,
                      IConfiguration configuration, ILogger <MyUserService> logger)
 {
     this.context  = context;
     Mapper        = mapper;
     Configuration = configuration;
     Logger        = logger;
 }
Exemplo n.º 22
0
 public FlowInboxService(BackendDBContext context, IMapper mapper,
                         ILogger <FlowInboxService> logger, UserHelper currentUserHelper)
 {
     this.context      = context;
     Mapper            = mapper;
     Logger            = logger;
     CurrentUserHelper = currentUserHelper;
 }
Exemplo n.º 23
0
 public DatabaseInitService(BackendDBContext context, IMapper mapper,
                            IConfiguration configuration, ILogger <DatabaseInitService> logger,
                            IHttpContextAccessor httpContextAccessor, SystemLogHelper systemLogHelper)
 {
     this.context        = context;
     Mapper              = mapper;
     Configuration       = configuration;
     Logger              = logger;
     HttpContextAccessor = httpContextAccessor;
     SystemLogHelper     = systemLogHelper;
 }
        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();
        }
        private static async Task GenerateMyUserAsync(BackendDBContext context, Random random)
        {
            List <MyUser> users = new List <MyUser>();

            for (int i = 1; i < 30; i++)
            {
                MyUser MyUser = new MyUser()
                {
                    Account  = $"user{i}",
                    Name     = $"user{i}",
                    Password = "******",
                };
                users.Add(MyUser);
            }
            await context.BulkInsertAsync(users);
        }
Exemplo n.º 26
0
        public FlowMasterViewModel(IFlowMasterService CurrentService,
                                   BackendDBContext context, IMapper Mapper,
                                   UserHelper currentUserHelper,
                                   TranscationResultHelper transcationResultHelper,
                                   CurrentUser currentUser)
        {
            this.CurrentService = CurrentService;
            this.context        = context;
            mapper                  = Mapper;
            CurrentUserHelper       = currentUserHelper;
            TranscationResultHelper = transcationResultHelper;
            CurrentUser             = currentUser;
            FlowMasterSort.Initialization(SortConditions);

            #region 工具列按鈕初始化
            Toolbaritems.Add(new ItemModel()
            {
                Id          = ButtonIdHelper.ButtonIdAdd,
                Text        = "新增",
                TooltipText = "新增",
                Type        = ItemType.Button,
                PrefixIcon  = "mdi mdi-plus-thick",
                Align       = ItemAlign.Left,
            });
            Toolbaritems.Add(new ItemModel()
            {
                Id          = ButtonIdHelper.ButtonIdRefresh,
                Text        = "重新整理",
                TooltipText = "重新整理",
                PrefixIcon  = "mdi mdi-refresh",
                Align       = ItemAlign.Left,
            });
            Toolbaritems.Add("Search");
            #endregion


            #region 互動式彈出功能表 ContextMenu 初始化
            ContextMenuItems.Add(new ContextMenuItemModel
            {
                Text    = "查看來源記錄",
                Target  = ".e-content",
                Id      = "查看來源記錄",
                IconCss = "mdi mdi-file-find",
            });
            #endregion
        }
Exemplo n.º 27
0
        public ExceptionRecordRazorModel(IExceptionRecordService CurrentService,
                                         BackendDBContext context,
                                         IMapper Mapper)
        {
            this.CurrentService = CurrentService;
            this.context        = context;
            mapper = Mapper;
            ExceptionRecordSort.Initialization(SortConditions);

            Toolbaritems.Add(new ItemModel()
            {
                Id          = ButtonIdHelper.ButtonIdRefresh,
                Text        = "重新整理",
                TooltipText = "重新整理",
                PrefixIcon  = "mdi mdi-refresh",
                Align       = ItemAlign.Left,
            });
            Toolbaritems.Add("Search");
        }
        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();
        }
Exemplo n.º 29
0
        public FlowHistoryViewModel(IFlowHistoryService CurrentService,
                                    BackendDBContext context, IMapper Mapper,
                                    TranscationResultHelper transcationResultHelper)
        {
            this.CurrentService = CurrentService;
            this.context        = context;
            mapper = Mapper;
            TranscationResultHelper = transcationResultHelper;
            FlowHistorySort.Initialization(SortConditions);

            #region 工具列按鈕初始化
            Toolbaritems.Add(new ItemModel()
            {
                Id          = ButtonIdHelper.ButtonIdRefresh,
                Text        = "重新整理",
                TooltipText = "重新整理",
                PrefixIcon  = "mdi mdi-refresh",
                Align       = ItemAlign.Left,
            });
            Toolbaritems.Add("Search");
            #endregion
        }
Exemplo n.º 30
0
        public MenuDataViewModel(IMenuDataService CurrentService,
                                 BackendDBContext context, IMapper Mapper,
                                 TranscationResultHelper transcationResultHelper)
        {
            this.CurrentService = CurrentService;
            this.context        = context;
            mapper = Mapper;
            TranscationResultHelper = transcationResultHelper;
            MenuDataSort.Initialization(SortConditions);

            Toolbaritems.Add(new ItemModel()
            {
                Id          = ButtonIdHelper.ButtonIdAdd,
                Text        = "新增",
                TooltipText = "新增",
                Type        = ItemType.Button,
                PrefixIcon  = "mdi mdi-plus-thick",
                Align       = ItemAlign.Left,
            });
            Toolbaritems.Add(new ItemModel()
            {
                Id          = ButtonIdHelper.ButtonIdRefresh,
                Text        = "重新整理",
                TooltipText = "重新整理",
                PrefixIcon  = "mdi mdi-refresh",
                Align       = ItemAlign.Left,
            });
            Toolbaritems.Add(new ItemModel()
            {
                Id          = ButtonIdHelper.ButtonIdReOrder,
                Text        = "重新編號",
                TooltipText = "重新編號",
                PrefixIcon  = "mdi mdi-order-numeric-ascending",
                Align       = ItemAlign.Left,
            });
            Toolbaritems.Add("Search");
        }