visualbasic/migration #1
@ -5,18 +5,32 @@ VisualStudioVersion = 17.0.31903.59
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Strata.Code.DataAccess", "src\Strata.Code.DataAccess\Strata.Code.DataAccess.csproj", "{C27AA99E-EEC0-41FE-B949-F4EEED1F3952}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Strata.Code.Business", "src\Strata.Code.Business\Strata.Code.Business.csproj", "{478E3F10-2B5C-4D40-BE53-327E5B2AD0AC}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{C4F5F2DA-7191-4ACE-8EC4-5715C1E9388E}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Strata.Code.Web", "src\Strata.Code.Web\Strata.Code.Web.csproj", "{120D37EF-20DC-492B-AB2B-8A887627A211}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{C27AA99E-EEC0-41FE-B949-F4EEED1F3952}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{C27AA99E-EEC0-41FE-B949-F4EEED1F3952}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{C27AA99E-EEC0-41FE-B949-F4EEED1F3952}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{C27AA99E-EEC0-41FE-B949-F4EEED1F3952}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{478E3F10-2B5C-4D40-BE53-327E5B2AD0AC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{478E3F10-2B5C-4D40-BE53-327E5B2AD0AC}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{478E3F10-2B5C-4D40-BE53-327E5B2AD0AC}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{478E3F10-2B5C-4D40-BE53-327E5B2AD0AC}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{120D37EF-20DC-492B-AB2B-8A887627A211}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{120D37EF-20DC-492B-AB2B-8A887627A211}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{120D37EF-20DC-492B-AB2B-8A887627A211}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{120D37EF-20DC-492B-AB2B-8A887627A211}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
|
||||
@ -6,65 +6,17 @@ Your solution should follow this structure for optimal organization:
|
||||
```
|
||||
YourSolution/
|
||||
├── src/
|
||||
│ ├── YourProject/
|
||||
│ ├── OnePlan/ <- Your project
|
||||
│ │ ├── Controllers/
|
||||
│ │ ├── Models/ <- Scaffolded models will go here
|
||||
│ │ └── Data/ <- DbContext will go here
|
||||
│ │ ├── Models/ <- Scaffolded models will go here
|
||||
│ │ └── Data/ <- DbContext will go here
|
||||
├── tests/
|
||||
│ └── YourProject.Tests/
|
||||
│ └── OnePlan.Tests/
|
||||
├── tools/
|
||||
│ └── scaffold.bat <- Place scaffolding script here
|
||||
│ └── scaffold.bat <- Scaffolding script here
|
||||
└── YourSolution.sln
|
||||
```
|
||||
|
||||
Alternative structure with scripts directory:
|
||||
```
|
||||
YourSolution/
|
||||
├── src/
|
||||
│ ├── YourProject/
|
||||
│ │ ├── Controllers/
|
||||
│ │ ├── Models/
|
||||
│ │ └── Data/
|
||||
├── tests/
|
||||
│ └── YourProject.Tests/
|
||||
├── scripts/
|
||||
│ ├── database/
|
||||
│ │ └── scaffold.bat <- Or place it here
|
||||
│ └── other-scripts/
|
||||
└── YourSolution.sln
|
||||
```
|
||||
|
||||
To run the scaffold script:
|
||||
|
||||
Method 1 (From project directory):
|
||||
1. Open command prompt
|
||||
2. Navigate to project directory: `cd src/YourProject`
|
||||
3. Run: `../../tools/scaffold.bat`
|
||||
|
||||
Method 2 (From any directory):
|
||||
Update your scaffold.bat to include the project path:
|
||||
```bat
|
||||
@echo off
|
||||
cd ../src/YourProject
|
||||
dotnet ef dbcontext scaffold ^
|
||||
"Your_Connection_String" ^
|
||||
Microsoft.EntityFrameworkCore.SqlServer ^
|
||||
--project YourProject.csproj ^
|
||||
[rest of your options]
|
||||
pause
|
||||
```
|
||||
|
||||
Note: Make sure your project has all required EF Core packages installed:
|
||||
```xml
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.0" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.0" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.0" />
|
||||
</ItemGroup>
|
||||
```
|
||||
|
||||
This guide explains how to set up Entity Framework Core using a database-first approach for specific tables in the OnePlan database.
|
||||
|
||||
## Prerequisites
|
||||
|
||||
Before starting, ensure you have:
|
||||
@ -76,92 +28,6 @@ dotnet tool install --global dotnet-ef
|
||||
```
|
||||
|
||||
3. Required NuGet packages in your project:
|
||||
```bash
|
||||
dotnet add package Microsoft.EntityFrameworkCore.Design
|
||||
dotnet add package Microsoft.EntityFrameworkCore.SqlServer
|
||||
dotnet add package Microsoft.EntityFrameworkCore.Tools
|
||||
```
|
||||
|
||||
## Scaffolding Process
|
||||
|
||||
### Step 1: Create a Scaffold Script
|
||||
|
||||
Create a file named `scaffold.bat` in your `tools` directory with the following content:
|
||||
|
||||
```bat
|
||||
@echo off
|
||||
cd ../src/YourProject
|
||||
dotnet ef dbcontext scaffold ^
|
||||
"Server=your_server;Database=your_database;User=your_user;Password=your_password;TrustServerCertificate=True;Encrypt=True;" ^
|
||||
Microsoft.EntityFrameworkCore.SqlServer ^
|
||||
--project YourProject.csproj ^
|
||||
--context-dir Data ^
|
||||
--output-dir Models ^
|
||||
--context OnePlanDbContext ^
|
||||
--force ^
|
||||
--data-annotations ^
|
||||
--no-onconfiguring ^
|
||||
--no-connection-string ^
|
||||
-t fp.AddProviderEncountersDataForCharges ^
|
||||
-t fp.AddProviderSummary ^
|
||||
-t fp.AdjustmentChunkingConfiguration ^
|
||||
-t fp.APEDepartmentWorkflowStatus ^
|
||||
-t fp.APEWorkflow ^
|
||||
-t fp.BenefitsSpreads ^
|
||||
-t fp.BudgetConfig ^
|
||||
-t fp.BudgetConfigDefaultSetting ^
|
||||
-t fp.BudgetConfigSetting ^
|
||||
-t fp.BudgetRefreshRequest ^
|
||||
-t fp.BudgetRefreshRequestHistory ^
|
||||
-t fp.ChargeVolumeAddProviderAdjustment ^
|
||||
-t fp.ChargeVolumeSpreads ^
|
||||
-t fp.DataRefreshTargetThreshold ^
|
||||
-t fp.DepartmentChargeVolumeAdjustment ^
|
||||
-t fp.DepartmentConfig ^
|
||||
-t fp.DimCategory ^
|
||||
-t fw.DimDepartment ^
|
||||
-t dss.DimPhysician ^
|
||||
-t fp.EngineLog ^
|
||||
-t fp.EntityGroupConfig ^
|
||||
-t fp.FixChangeHistoryRequest ^
|
||||
-t fp.GeneralLedger ^
|
||||
-t fp.GeneralLedgerInitialPlanConfigDetail ^
|
||||
-t fp.GeneralLedgerSpreads ^
|
||||
-t fp.InitialPlanRule ^
|
||||
-t dbo.LOCK ^
|
||||
-t dbo.log ^
|
||||
-t dbo.OnePlanPerformanceTestHistory ^
|
||||
-t fp.OnePlanPerformanceTestValidationResult ^
|
||||
-t fp.PerformanceTestingSetting ^
|
||||
-t fp.ProviderCompensationSpreads ^
|
||||
-t fp.SamplingLog ^
|
||||
-t fp.ScheduledRefreshRequest ^
|
||||
-t fp.ServiceLineEncounterSpreads ^
|
||||
-t fp.SettingCategory ^
|
||||
-t fp.SpreadHistory ^
|
||||
-t fp.StaffingInitialPlanConfigDetail ^
|
||||
-t fp.StaffingSpreads ^
|
||||
-t fp.StatisticsSpreads ^
|
||||
-t fp.SystemSetting ^
|
||||
-t dbo.TEScheduledTask ^
|
||||
-t dbo.UserProfile ^
|
||||
-t fp.viewBenefitsAdjustment ^
|
||||
-t fp.viewDepartmentChargeVolumeAdjustment ^
|
||||
-t fp.viewGeneralLedgerAdjustment ^
|
||||
-t fp.viewReimbursementAdjustment ^
|
||||
-t fp.viewReimbursementGeneralLedgerAdjustment ^
|
||||
-t fp.viewServiceLineEncounterAdjustment ^
|
||||
-t fp.viewStaffingAdjustment ^
|
||||
-t fp.viewStatisticsAdjustment
|
||||
pause
|
||||
```
|
||||
|
||||
To run the scaffold script:
|
||||
1. Open command prompt
|
||||
2. Navigate to solution root directory
|
||||
3. Run: `tools/scaffold.bat`
|
||||
|
||||
Note: Make sure your project has all required EF Core packages installed:
|
||||
```xml
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.0" />
|
||||
@ -170,9 +36,94 @@ Note: Make sure your project has all required EF Core packages installed:
|
||||
</ItemGroup>
|
||||
```
|
||||
|
||||
## Scaffolding Process
|
||||
|
||||
### Step 1: Create Scaffold Script
|
||||
|
||||
Create a file named `scaffold.bat` in your `tools` directory with the following content:
|
||||
|
||||
```bat
|
||||
@echo off
|
||||
cd ..\src\OnePlan
|
||||
dotnet ef dbcontext scaffold^
|
||||
"Server=your_server;Database=your_database;User=your_user;Password=your_password;TrustServerCertificate=True;Encrypt=True;"^
|
||||
Microsoft.EntityFrameworkCore.SqlServer^
|
||||
--project OnePlan.csproj^
|
||||
--context-dir Data^
|
||||
--output-dir Models^
|
||||
--context OnePlanDbContext^
|
||||
--force^
|
||||
--data-annotations^
|
||||
--no-onconfiguring^
|
||||
-t fp.AddProviderEncountersDataForCharges^
|
||||
-t fp.AddProviderSummary^
|
||||
-t fp.AdjustmentChunkingConfiguration^
|
||||
-t fp.APEDepartmentWorkflowStatus^
|
||||
-t fp.APEWorkflow^
|
||||
-t fp.BenefitsSpreads^
|
||||
-t fp.BudgetConfig^
|
||||
-t fp.BudgetConfigDefaultSetting^
|
||||
-t fp.BudgetConfigSetting^
|
||||
-t fp.BudgetRefreshRequest^
|
||||
-t fp.BudgetRefreshRequestHistory^
|
||||
-t fp.ChargeVolumeAddProviderAdjustment^
|
||||
-t fp.ChargeVolumeSpreads^
|
||||
-t fp.DataRefreshTargetThreshold^
|
||||
-t fp.DepartmentChargeVolumeAdjustment^
|
||||
-t fp.DepartmentConfig^
|
||||
-t fp.DimCategory^
|
||||
-t fw.DimDepartment^
|
||||
-t dss.DimPhysician^
|
||||
-t fp.EngineLog^
|
||||
-t fp.EntityGroupConfig^
|
||||
-t fp.FixChangeHistoryRequest^
|
||||
-t fp.GeneralLedger^
|
||||
-t fp.GeneralLedgerInitialPlanConfigDetail^
|
||||
-t fp.GeneralLedgerSpreads^
|
||||
-t fp.InitialPlanRule^
|
||||
-t dbo.LOCK^
|
||||
-t dbo.log^
|
||||
-t dbo.OnePlanPerformanceTestHistory^
|
||||
-t fp.OnePlanPerformanceTestValidationResult^
|
||||
-t fp.PerformanceTestingSetting^
|
||||
-t fp.ProviderCompensationSpreads^
|
||||
-t fp.SamplingLog^
|
||||
-t fp.ScheduledRefreshRequest^
|
||||
-t fp.ServiceLineEncounterSpreads^
|
||||
-t fp.SettingCategory^
|
||||
-t fp.SpreadHistory^
|
||||
-t fp.StaffingInitialPlanConfigDetail^
|
||||
-t fp.StaffingSpreads^
|
||||
-t fp.StatisticsSpreads^
|
||||
-t fp.SystemSetting^
|
||||
-t dbo.TEScheduledTask^
|
||||
-t dbo.UserProfile^
|
||||
-t fp.viewBenefitsAdjustment^
|
||||
-t fp.viewDepartmentChargeVolumeAdjustment^
|
||||
-t fp.viewGeneralLedgerAdjustment^
|
||||
-t fp.viewReimbursementAdjustment^
|
||||
-t fp.viewReimbursementGeneralLedgerAdjustment^
|
||||
-t fp.viewServiceLineEncounterAdjustment^
|
||||
-t fp.viewStaffingAdjustment^
|
||||
-t fp.viewStatisticsAdjustment
|
||||
pause
|
||||
```
|
||||
|
||||
Important Notes for Multi-line Batch Files:
|
||||
1. The `^` character must be the last character on each line (no spaces after it)
|
||||
2. Each new line should start with a space before the parameter
|
||||
3. The connection string must be in quotes
|
||||
4. The last command line doesn't need a `^`
|
||||
5. Use `..\` instead of `../` for Windows paths
|
||||
|
||||
To run the scaffold script:
|
||||
1. Open command prompt
|
||||
2. Navigate to the tools directory: `cd tools`
|
||||
3. Run: `scaffold.bat`
|
||||
|
||||
### Step 2: Configure Connection String
|
||||
|
||||
After scaffolding, configure your connection string in `appsettings.json`:
|
||||
Add your connection string to `appsettings.json`:
|
||||
|
||||
```json
|
||||
{
|
||||
@ -182,49 +133,32 @@ After scaffolding, configure your connection string in `appsettings.json`:
|
||||
}
|
||||
```
|
||||
|
||||
### Step 3: Configure DbContext
|
||||
### Step 3: Set Up Dependency Injection
|
||||
|
||||
In your `Program.cs` or `Startup.cs`:
|
||||
1. Modify the generated DbContext to use constructor injection:
|
||||
|
||||
```csharp
|
||||
public class OnePlanDbContext : DbContext
|
||||
{
|
||||
public OnePlanDbContext(DbContextOptions<OnePlanDbContext> options)
|
||||
: base(options)
|
||||
{
|
||||
}
|
||||
|
||||
// Your DbSet properties will be here
|
||||
}
|
||||
```
|
||||
|
||||
2. Register the DbContext in `Program.cs`:
|
||||
|
||||
```csharp
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
// Add DbContext
|
||||
builder.Services.AddDbContext<OnePlanDbContext>(options =>
|
||||
options.UseSqlServer(builder.Configuration.GetConnectionString("DefaultConnection")));
|
||||
```
|
||||
|
||||
## Command Line Parameters Explained
|
||||
|
||||
- `--context-dir Data`: Places the DbContext in a Data folder
|
||||
- `--output-dir Models`: Places entity classes in a Models folder
|
||||
- `--force`: Overwrites existing files
|
||||
- `--data-annotations`: Uses attributes instead of fluent API
|
||||
- `--no-onconfiguring`: Skips generating the OnConfiguring method
|
||||
- `--no-connection-string`: Prevents connection string from being scaffolded into DbContext
|
||||
|
||||
## Schema Organization
|
||||
|
||||
The tables are organized across multiple schemas:
|
||||
- `fp`: Financial Planning schema (majority of tables)
|
||||
- `dbo`: Database Owner schema
|
||||
- `dss`: Decision Support System schema
|
||||
- `fw`: Framework schema
|
||||
|
||||
## Best Practices
|
||||
|
||||
1. Always scaffold all related tables together to maintain proper relationships
|
||||
2. Keep connection strings in configuration, not in code
|
||||
3. Use dependency injection for DbContext
|
||||
4. Consider using separate configuration classes for complex entity configurations
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
If you encounter SSL/TLS warnings, ensure your connection string includes:
|
||||
- `TrustServerCertificate=True`
|
||||
- `Encrypt=True`
|
||||
|
||||
For Docker connections, use:
|
||||
- `Server=localhost,1433` (adjust port as needed)
|
||||
- Ensure the container is running and accessible
|
||||
|
||||
## DbContext Organization
|
||||
|
||||
You have two main approaches for organizing your DbContext:
|
||||
@ -275,9 +209,10 @@ For this project, the single DbContext approach is recommended due to:
|
||||
- Coherent domain model around financial planning
|
||||
|
||||
## Notes
|
||||
|
||||
- Views are included in the scaffold and will be read-only
|
||||
- The scaffold includes all specified tables across multiple schemas
|
||||
- Relationships between tables will be automatically mapped
|
||||
- Generated models will be placed in the Models directory
|
||||
- DbContext will be placed in the Data directory
|
||||
- DbContext will be placed in the Data directory
|
||||
- Use data annotations for simple configurations
|
||||
- Use fluent API in OnModelCreating for complex configurations
|
||||
@ -0,0 +1,71 @@
|
||||
using Strata.Code.Business.Services.Interfaces;
|
||||
using Strata.Code.DataAccess.Models;
|
||||
using Strata.Code.DataAccess.Repositories.Interfaces;
|
||||
|
||||
namespace Strata.Code.Business.Services
|
||||
{
|
||||
public class BudgetConfigDefaultSettingService : IBudgetConfigDefaultSettingService
|
||||
{
|
||||
private readonly IBudgetConfigDefaultSettingRepository _repository;
|
||||
|
||||
public BudgetConfigDefaultSettingService(IBudgetConfigDefaultSettingRepository repository)
|
||||
{
|
||||
_repository = repository;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<BudgetConfigDefaultSettingDto>> GetAllAsync()
|
||||
{
|
||||
var settings = await _repository.GetAllAsync();
|
||||
return settings.Select(s => MapToDto(s));
|
||||
}
|
||||
|
||||
public async Task<BudgetConfigDefaultSettingDto?> GetByIdAsync(int id)
|
||||
{
|
||||
var setting = await _repository.GetByIdAsync(id);
|
||||
return setting != null ? MapToDto(setting) : null;
|
||||
}
|
||||
|
||||
public async Task<BudgetConfigDefaultSettingDto> CreateAsync(BudgetConfigDefaultSettingDto settingDto)
|
||||
{
|
||||
var setting = MapToEntity(settingDto);
|
||||
var result = await _repository.CreateAsync(setting);
|
||||
return MapToDto(result);
|
||||
}
|
||||
|
||||
public async Task<BudgetConfigDefaultSettingDto?> UpdateAsync(BudgetConfigDefaultSettingDto settingDto)
|
||||
{
|
||||
var setting = MapToEntity(settingDto);
|
||||
var result = await _repository.UpdateAsync(setting);
|
||||
return result != null ? MapToDto(result) : null;
|
||||
}
|
||||
|
||||
public async Task<bool> DeleteAsync(int id)
|
||||
{
|
||||
return await _repository.DeleteAsync(id);
|
||||
}
|
||||
|
||||
private BudgetConfigDefaultSettingDto MapToDto(BudgetConfigDefaultSetting entity)
|
||||
{
|
||||
return new BudgetConfigDefaultSettingDto
|
||||
{
|
||||
SettingId = entity.SettingId,
|
||||
Name = entity.Name,
|
||||
DefaultValue = entity.DefaultValue,
|
||||
Description = entity.Description,
|
||||
DateCreated = entity.DateCreated
|
||||
};
|
||||
}
|
||||
|
||||
private BudgetConfigDefaultSetting MapToEntity(BudgetConfigDefaultSettingDto dto)
|
||||
{
|
||||
return new BudgetConfigDefaultSetting
|
||||
{
|
||||
SettingId = dto.SettingId,
|
||||
Name = dto.Name,
|
||||
DefaultValue = dto.DefaultValue,
|
||||
Description = dto.Description,
|
||||
DateCreated = dto.DateCreated
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,30 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Strata.Code.Business.Services.Interfaces
|
||||
{
|
||||
public class BudgetConfigDefaultSettingDto
|
||||
{
|
||||
public int SettingId { get; set; }
|
||||
|
||||
public string Name { get; set; } = null!;
|
||||
|
||||
public string Description { get; set; } = null!;
|
||||
|
||||
public bool DefaultValue { get; set; }
|
||||
|
||||
public DateOnly DateCreated { get; set; }
|
||||
}
|
||||
|
||||
public interface IBudgetConfigDefaultSettingService
|
||||
{
|
||||
Task<IEnumerable<BudgetConfigDefaultSettingDto>> GetAllAsync();
|
||||
Task<BudgetConfigDefaultSettingDto?> GetByIdAsync(int id);
|
||||
Task<BudgetConfigDefaultSettingDto> CreateAsync(BudgetConfigDefaultSettingDto setting);
|
||||
Task<BudgetConfigDefaultSettingDto?> UpdateAsync(BudgetConfigDefaultSettingDto setting);
|
||||
Task<bool> DeleteAsync(int id);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,13 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Strata.Code.DataAccess\Strata.Code.DataAccess.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@ -1,6 +0,0 @@
|
||||
namespace Strata.Code.DataAccess;
|
||||
|
||||
public class Class1
|
||||
{
|
||||
|
||||
}
|
||||
@ -0,0 +1,66 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Strata.Code.DataAccess.Data;
|
||||
using Strata.Code.DataAccess.Models;
|
||||
using Strata.Code.DataAccess.Repositories.Interfaces;
|
||||
|
||||
namespace Strata.Code.DataAccess.Repositories
|
||||
{
|
||||
public class BudgetConfigDefaultSettingRepository : IBudgetConfigDefaultSettingRepository
|
||||
{
|
||||
private readonly OnePlanDbContext _context;
|
||||
|
||||
public BudgetConfigDefaultSettingRepository(OnePlanDbContext context)
|
||||
{
|
||||
_context = context ?? throw new ArgumentNullException(nameof(context));
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<BudgetConfigDefaultSetting>> GetAllAsync()
|
||||
{
|
||||
return await _context.Set<BudgetConfigDefaultSetting>()
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<BudgetConfigDefaultSetting?> GetByIdAsync(int id)
|
||||
{
|
||||
return await _context.Set<BudgetConfigDefaultSetting>()
|
||||
.FirstOrDefaultAsync(x => x.SettingId == id);
|
||||
}
|
||||
|
||||
public async Task<BudgetConfigDefaultSetting> CreateAsync(BudgetConfigDefaultSetting setting)
|
||||
{
|
||||
setting.DateCreated = DateOnly.FromDateTime(DateTime.UtcNow);
|
||||
await _context.Set<BudgetConfigDefaultSetting>().AddAsync(setting);
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
return setting;
|
||||
}
|
||||
|
||||
public async Task<BudgetConfigDefaultSetting?> UpdateAsync(BudgetConfigDefaultSetting setting)
|
||||
{
|
||||
var existingSetting = await GetByIdAsync(setting.SettingId);
|
||||
if (existingSetting == null)
|
||||
return null;
|
||||
|
||||
existingSetting.Name = setting.Name;
|
||||
existingSetting.DefaultValue = setting.DefaultValue;
|
||||
existingSetting.Description = setting.Description;
|
||||
|
||||
_context.Set<BudgetConfigDefaultSetting>().Update(existingSetting);
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
return existingSetting;
|
||||
}
|
||||
|
||||
public async Task<bool> DeleteAsync(int id)
|
||||
{
|
||||
var setting = await GetByIdAsync(id);
|
||||
if (setting == null)
|
||||
return false;
|
||||
|
||||
_context.Remove(setting);
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,13 @@
|
||||
using Strata.Code.DataAccess.Models;
|
||||
|
||||
namespace Strata.Code.DataAccess.Repositories.Interfaces
|
||||
{
|
||||
public interface IBudgetConfigDefaultSettingRepository
|
||||
{
|
||||
Task<IEnumerable<BudgetConfigDefaultSetting>> GetAllAsync();
|
||||
Task<BudgetConfigDefaultSetting?> GetByIdAsync(int id);
|
||||
Task<BudgetConfigDefaultSetting> CreateAsync(BudgetConfigDefaultSetting setting);
|
||||
Task<BudgetConfigDefaultSetting?> UpdateAsync(BudgetConfigDefaultSetting setting);
|
||||
Task<bool> DeleteAsync(int id);
|
||||
}
|
||||
}
|
||||
@ -1,18 +1,19 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.1">
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.12">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="9.0.1" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="9.0.1">
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.12" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.12" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.12">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
|
||||
@ -0,0 +1,77 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Strata.Code.Business.Services.Interfaces;
|
||||
|
||||
namespace Strata.Code.Web.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("api/[controller]")]
|
||||
public class BudgetConfigDefaultSettingController : ControllerBase
|
||||
{
|
||||
private readonly IBudgetConfigDefaultSettingService _service;
|
||||
|
||||
public BudgetConfigDefaultSettingController(IBudgetConfigDefaultSettingService service)
|
||||
{
|
||||
_service = service;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[ProducesResponseType(typeof(IEnumerable<BudgetConfigDefaultSettingDto>), StatusCodes.Status200OK)]
|
||||
public async Task<IActionResult> GetAll()
|
||||
{
|
||||
var settings = await _service.GetAllAsync();
|
||||
return Ok(settings);
|
||||
}
|
||||
|
||||
[HttpGet("{id}")]
|
||||
[ProducesResponseType(typeof(BudgetConfigDefaultSettingDto), StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||
public async Task<IActionResult> GetById(int id)
|
||||
{
|
||||
var setting = await _service.GetByIdAsync(id);
|
||||
if (setting == null)
|
||||
return NotFound();
|
||||
|
||||
return Ok(setting);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[ProducesResponseType(typeof(BudgetConfigDefaultSettingDto), StatusCodes.Status201Created)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task<IActionResult> Create([FromBody] BudgetConfigDefaultSettingDto setting)
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
return BadRequest(ModelState);
|
||||
|
||||
var createdSetting = await _service.CreateAsync(setting);
|
||||
return CreatedAtAction(nameof(GetById), new { id = createdSetting.SettingId }, createdSetting);
|
||||
}
|
||||
|
||||
[HttpPut("{id}")]
|
||||
[ProducesResponseType(typeof(BudgetConfigDefaultSettingDto), StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task<IActionResult> Update(int id, [FromBody] BudgetConfigDefaultSettingDto setting)
|
||||
{
|
||||
if (id != setting.SettingId)
|
||||
return BadRequest();
|
||||
|
||||
var updatedSetting = await _service.UpdateAsync(setting);
|
||||
if (updatedSetting == null)
|
||||
return NotFound();
|
||||
|
||||
return Ok(updatedSetting);
|
||||
}
|
||||
|
||||
[HttpDelete("{id}")]
|
||||
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||
public async Task<IActionResult> Delete(int id)
|
||||
{
|
||||
var result = await _service.DeleteAsync(id);
|
||||
if (!result)
|
||||
return NotFound();
|
||||
|
||||
return NoContent();
|
||||
}
|
||||
}
|
||||
}
|
||||
51
ef-migration/src/Strata.Code.Web/Program.cs
Normal file
51
ef-migration/src/Strata.Code.Web/Program.cs
Normal file
@ -0,0 +1,51 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.OpenApi.Models;
|
||||
using Strata.Code.DataAccess.Repositories.Interfaces;
|
||||
using Strata.Code.DataAccess.Repositories;
|
||||
using System.Reflection;
|
||||
using Strata.Code.Business.Services;
|
||||
using Strata.Code.Business.Services.Interfaces;
|
||||
using Strata.Code.DataAccess.Data;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
builder.Services.AddControllers();
|
||||
builder.Services.AddEndpointsApiExplorer();
|
||||
builder.Services.AddSwaggerGen(c =>
|
||||
{
|
||||
c.SwaggerDoc("v1", new OpenApiInfo
|
||||
{
|
||||
Title = "Budget Config API",
|
||||
Version = "v1",
|
||||
Description = "API for managing budget configuration default settings"
|
||||
});
|
||||
|
||||
// Include XML comments in Swagger documentation
|
||||
var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
|
||||
var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
|
||||
c.IncludeXmlComments(xmlPath);
|
||||
});
|
||||
|
||||
// Add your DbContext configuration here
|
||||
builder.Services.AddDbContext<OnePlanDbContext>(options =>
|
||||
options.UseSqlServer(builder.Configuration.GetConnectionString("DefaultConnection")));
|
||||
|
||||
builder.Services.AddScoped<IBudgetConfigDefaultSettingRepository, BudgetConfigDefaultSettingRepository>();
|
||||
builder.Services.AddScoped<IBudgetConfigDefaultSettingService, BudgetConfigDefaultSettingService>();
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
if (app.Environment.IsDevelopment())
|
||||
{
|
||||
app.UseSwagger();
|
||||
app.UseSwaggerUI(c =>
|
||||
{
|
||||
c.SwaggerEndpoint("/swagger/v1/swagger.json", "Budget Config API V1");
|
||||
});
|
||||
}
|
||||
|
||||
app.UseHttpsRedirection();
|
||||
app.UseAuthorization();
|
||||
app.MapControllers();
|
||||
|
||||
app.Run();
|
||||
@ -0,0 +1,41 @@
|
||||
{
|
||||
"$schema": "http://json.schemastore.org/launchsettings.json",
|
||||
"iisSettings": {
|
||||
"windowsAuthentication": false,
|
||||
"anonymousAuthentication": true,
|
||||
"iisExpress": {
|
||||
"applicationUrl": "http://localhost:27409",
|
||||
"sslPort": 44329
|
||||
}
|
||||
},
|
||||
"profiles": {
|
||||
"http": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "swagger",
|
||||
"applicationUrl": "http://localhost:5247",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
},
|
||||
"https": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "swagger",
|
||||
"applicationUrl": "https://localhost:7241;http://localhost:5247",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
},
|
||||
"IIS Express": {
|
||||
"commandName": "IISExpress",
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "swagger",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
18
ef-migration/src/Strata.Code.Web/Strata.Code.Web.csproj
Normal file
18
ef-migration/src/Strata.Code.Web/Strata.Code.Web.csproj
Normal file
@ -0,0 +1,18 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<GenerateDocumentationFile>True</GenerateDocumentationFile>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.6.2" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Strata.Code.Business\Strata.Code.Business.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@ -0,0 +1,8 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
}
|
||||
}
|
||||
12
ef-migration/src/Strata.Code.Web/appsettings.json
Normal file
12
ef-migration/src/Strata.Code.Web/appsettings.json
Normal file
@ -0,0 +1,12 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*",
|
||||
"ConnectionStrings": {
|
||||
"DefaultConnection": "Server=54.71.217.228,1433;Database=st-database;User=sa;Password=YourStrong@Passw0rd;TrustServerCertificate=True;"
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user