diff --git a/ef-migration/Strata.Code.sln b/ef-migration/Strata.Code.sln index 1489653..78f4e81 100644 --- a/ef-migration/Strata.Code.sln +++ b/ef-migration/Strata.Code.sln @@ -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 diff --git a/ef-migration/readme.md b/ef-migration/readme.md index 59d301c..42ef523 100644 --- a/ef-migration/readme.md +++ b/ef-migration/readme.md @@ -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 - - - - - -``` - -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 @@ -170,9 +36,94 @@ Note: Make sure your project has all required EF Core packages installed: ``` +## 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 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(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 \ No newline at end of file +- DbContext will be placed in the Data directory +- Use data annotations for simple configurations +- Use fluent API in OnModelCreating for complex configurations \ No newline at end of file diff --git a/ef-migration/src/Strata.Code.Business/Services/BudgetConfigDefaultSettingService.cs b/ef-migration/src/Strata.Code.Business/Services/BudgetConfigDefaultSettingService.cs new file mode 100644 index 0000000..04078b3 --- /dev/null +++ b/ef-migration/src/Strata.Code.Business/Services/BudgetConfigDefaultSettingService.cs @@ -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> GetAllAsync() + { + var settings = await _repository.GetAllAsync(); + return settings.Select(s => MapToDto(s)); + } + + public async Task GetByIdAsync(int id) + { + var setting = await _repository.GetByIdAsync(id); + return setting != null ? MapToDto(setting) : null; + } + + public async Task CreateAsync(BudgetConfigDefaultSettingDto settingDto) + { + var setting = MapToEntity(settingDto); + var result = await _repository.CreateAsync(setting); + return MapToDto(result); + } + + public async Task UpdateAsync(BudgetConfigDefaultSettingDto settingDto) + { + var setting = MapToEntity(settingDto); + var result = await _repository.UpdateAsync(setting); + return result != null ? MapToDto(result) : null; + } + + public async Task 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 + }; + } + } +} diff --git a/ef-migration/src/Strata.Code.Business/Services/Interfaces/IBudgetConfigDefaultSettingService.cs b/ef-migration/src/Strata.Code.Business/Services/Interfaces/IBudgetConfigDefaultSettingService.cs new file mode 100644 index 0000000..d4fc601 --- /dev/null +++ b/ef-migration/src/Strata.Code.Business/Services/Interfaces/IBudgetConfigDefaultSettingService.cs @@ -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> GetAllAsync(); + Task GetByIdAsync(int id); + Task CreateAsync(BudgetConfigDefaultSettingDto setting); + Task UpdateAsync(BudgetConfigDefaultSettingDto setting); + Task DeleteAsync(int id); + } +} diff --git a/ef-migration/src/Strata.Code.Business/Strata.Code.Business.csproj b/ef-migration/src/Strata.Code.Business/Strata.Code.Business.csproj new file mode 100644 index 0000000..3c3c410 --- /dev/null +++ b/ef-migration/src/Strata.Code.Business/Strata.Code.Business.csproj @@ -0,0 +1,13 @@ + + + + net8.0 + enable + enable + + + + + + + diff --git a/ef-migration/src/Strata.Code.DataAccess/Class1.cs b/ef-migration/src/Strata.Code.DataAccess/Class1.cs deleted file mode 100644 index 8687269..0000000 --- a/ef-migration/src/Strata.Code.DataAccess/Class1.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace Strata.Code.DataAccess; - -public class Class1 -{ - -} diff --git a/ef-migration/src/Strata.Code.DataAccess/Repositories/BudgetConfigDefaultSettingRepository.cs b/ef-migration/src/Strata.Code.DataAccess/Repositories/BudgetConfigDefaultSettingRepository.cs new file mode 100644 index 0000000..4301fe4 --- /dev/null +++ b/ef-migration/src/Strata.Code.DataAccess/Repositories/BudgetConfigDefaultSettingRepository.cs @@ -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> GetAllAsync() + { + return await _context.Set() + .ToListAsync(); + } + + public async Task GetByIdAsync(int id) + { + return await _context.Set() + .FirstOrDefaultAsync(x => x.SettingId == id); + } + + public async Task CreateAsync(BudgetConfigDefaultSetting setting) + { + setting.DateCreated = DateOnly.FromDateTime(DateTime.UtcNow); + await _context.Set().AddAsync(setting); + await _context.SaveChangesAsync(); + + return setting; + } + + public async Task 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().Update(existingSetting); + await _context.SaveChangesAsync(); + + return existingSetting; + } + + public async Task DeleteAsync(int id) + { + var setting = await GetByIdAsync(id); + if (setting == null) + return false; + + _context.Remove(setting); + await _context.SaveChangesAsync(); + + return true; + } + } +} diff --git a/ef-migration/src/Strata.Code.DataAccess/Repositories/Interfaces/IBudgetConfigDefaultSettingRepository.cs b/ef-migration/src/Strata.Code.DataAccess/Repositories/Interfaces/IBudgetConfigDefaultSettingRepository.cs new file mode 100644 index 0000000..d5b4b00 --- /dev/null +++ b/ef-migration/src/Strata.Code.DataAccess/Repositories/Interfaces/IBudgetConfigDefaultSettingRepository.cs @@ -0,0 +1,13 @@ +using Strata.Code.DataAccess.Models; + +namespace Strata.Code.DataAccess.Repositories.Interfaces +{ + public interface IBudgetConfigDefaultSettingRepository + { + Task> GetAllAsync(); + Task GetByIdAsync(int id); + Task CreateAsync(BudgetConfigDefaultSetting setting); + Task UpdateAsync(BudgetConfigDefaultSetting setting); + Task DeleteAsync(int id); + } +} diff --git a/ef-migration/src/Strata.Code.DataAccess/Strata.Code.DataAccess.csproj b/ef-migration/src/Strata.Code.DataAccess/Strata.Code.DataAccess.csproj index b3834c8..d3849e5 100644 --- a/ef-migration/src/Strata.Code.DataAccess/Strata.Code.DataAccess.csproj +++ b/ef-migration/src/Strata.Code.DataAccess/Strata.Code.DataAccess.csproj @@ -1,18 +1,19 @@  - net9.0 + net8.0 enable enable - + runtime; build; native; contentfiles; analyzers; buildtransitive all - - + + + runtime; build; native; contentfiles; analyzers; buildtransitive all diff --git a/ef-migration/src/Strata.Code.Web/Controllers/BudgetConfigDefaultSettingController .cs b/ef-migration/src/Strata.Code.Web/Controllers/BudgetConfigDefaultSettingController .cs new file mode 100644 index 0000000..4b1e891 --- /dev/null +++ b/ef-migration/src/Strata.Code.Web/Controllers/BudgetConfigDefaultSettingController .cs @@ -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), StatusCodes.Status200OK)] + public async Task GetAll() + { + var settings = await _service.GetAllAsync(); + return Ok(settings); + } + + [HttpGet("{id}")] + [ProducesResponseType(typeof(BudgetConfigDefaultSettingDto), StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status404NotFound)] + public async Task 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 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 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 Delete(int id) + { + var result = await _service.DeleteAsync(id); + if (!result) + return NotFound(); + + return NoContent(); + } + } +} diff --git a/ef-migration/src/Strata.Code.Web/Program.cs b/ef-migration/src/Strata.Code.Web/Program.cs new file mode 100644 index 0000000..f51801c --- /dev/null +++ b/ef-migration/src/Strata.Code.Web/Program.cs @@ -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(options => + options.UseSqlServer(builder.Configuration.GetConnectionString("DefaultConnection"))); + +builder.Services.AddScoped(); +builder.Services.AddScoped(); + +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(); diff --git a/ef-migration/src/Strata.Code.Web/Properties/launchSettings.json b/ef-migration/src/Strata.Code.Web/Properties/launchSettings.json new file mode 100644 index 0000000..d53f34a --- /dev/null +++ b/ef-migration/src/Strata.Code.Web/Properties/launchSettings.json @@ -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" + } + } + } +} diff --git a/ef-migration/src/Strata.Code.Web/Strata.Code.Web.csproj b/ef-migration/src/Strata.Code.Web/Strata.Code.Web.csproj new file mode 100644 index 0000000..7b40504 --- /dev/null +++ b/ef-migration/src/Strata.Code.Web/Strata.Code.Web.csproj @@ -0,0 +1,18 @@ + + + + net8.0 + enable + enable + True + + + + + + + + + + + diff --git a/ef-migration/src/Strata.Code.Web/appsettings.Development.json b/ef-migration/src/Strata.Code.Web/appsettings.Development.json new file mode 100644 index 0000000..0c208ae --- /dev/null +++ b/ef-migration/src/Strata.Code.Web/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/ef-migration/src/Strata.Code.Web/appsettings.json b/ef-migration/src/Strata.Code.Web/appsettings.json new file mode 100644 index 0000000..f37fe5f --- /dev/null +++ b/ef-migration/src/Strata.Code.Web/appsettings.json @@ -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;" + } +}