Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions Condo/Condo.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.4">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.4" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
</ItemGroup>

</Project>
28 changes: 28 additions & 0 deletions Condo/Context/DatabaseContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using Condo.Context.Interfaces;
using Condo.Models;
using Microsoft.EntityFrameworkCore;

namespace Condo.Context;

public class DatabaseContext : DbContext, IDatabaseContext
{
public DatabaseContext(DbContextOptions<DatabaseContext> options) : base(options) {

}
public DatabaseContext() {}

public DbSet<Condominium> Condominiums { get; set; } = null!;

protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
if (!optionsBuilder.IsConfigured)
{
var connectionString = "Server=localhost;Database=Condo;User=SA;Password=SqlCondol12345!;TrustServerCertificate=True";
optionsBuilder.UseSqlServer(connectionString);
}
}




}
11 changes: 11 additions & 0 deletions Condo/Context/Interfaces/IDatabaseContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using Condo.Models;
using Microsoft.EntityFrameworkCore;

namespace Condo.Context.Interfaces;

public interface IDatabaseContext
{
public DbSet<Condominium> Condominiums { get; set; }
public int SaveChanges();

}
28 changes: 28 additions & 0 deletions Condo/Controllers/CondominiumController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using Condo.Models;
using Condo.UseCases.Interfaces;
using Microsoft.AspNetCore.Mvc;

namespace Condo.Controllers;

[ApiController]
[Route("[controller]")]
public class CondominiumController : ControllerBase
{
protected readonly ICondominiumUseCase _useCase;
public CondominiumController(ICondominiumUseCase useCase)
{
_useCase = useCase;
}

[HttpGet]
public IActionResult Get()
{
return Ok(_useCase.Get());
}

[HttpPost]
public IActionResult Post([FromBody] Condominium condominium)
{
return Created("", _useCase.Add(condominium));
}
}
51 changes: 51 additions & 0 deletions Condo/Migrations/20240429021611_InitialCreate.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 36 additions & 0 deletions Condo/Migrations/20240429021611_InitialCreate.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace Condo.Migrations
{
/// <inheritdoc />
public partial class InitialCreate : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Condominiums",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Name = table.Column<string>(type: "nvarchar(max)", nullable: true),
Type = table.Column<int>(type: "int", nullable: false),
PropertyTax = table.Column<double>(type: "float", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Condominiums", x => x.Id);
});
}

/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Condominiums");
}
}
}
48 changes: 48 additions & 0 deletions Condo/Migrations/DatabaseContextModelSnapshot.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// <auto-generated />
using Condo.Context;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;

#nullable disable

namespace Condo.Migrations
{
[DbContext(typeof(DatabaseContext))]
partial class DatabaseContextModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "7.0.4")
.HasAnnotation("Relational:MaxIdentifierLength", 128);

SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);

modelBuilder.Entity("Condo.Models.Condominium", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");

SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));

b.Property<string>("Name")
.HasColumnType("nvarchar(max)");

b.Property<double>("PropertyTax")
.HasColumnType("float");

b.Property<int>("Type")
.HasColumnType("int");

b.HasKey("Id");

b.ToTable("Condominiums");
});
#pragma warning restore 612, 618
}
}
}
11 changes: 11 additions & 0 deletions Condo/Models/Condominium.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using Condo.Types;

namespace Condo.Models;

public class Condominium
{
public int Id { get; set; }
public string? Name { get; set; }
public CondoType Type { get; set; }
public double PropertyTax { get; set; }
}
36 changes: 36 additions & 0 deletions Condo/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using Condo.Context;
using Condo.Context.Interfaces;
using Condo.Repository;
using Condo.Repository.Interfaces;
using Condo.UseCases;
using Condo.UseCases.Interfaces;

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.

builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
builder.Services.AddDbContext<DatabaseContext>();
builder.Services.AddScoped<IDatabaseContext, DatabaseContext>();
builder.Services.AddScoped<ICondominiumRepository, CondominiumRepository>();
builder.Services.AddScoped<ICondominiumUseCase, CondominiumUseCase>();

var app = builder.Build();

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}

app.UseHttpsRedirection();

app.UseAuthorization();

app.MapControllers();

app.Run();
41 changes: 41 additions & 0 deletions Condo/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"$schema": "https://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:2529",
"sslPort": 44374
}
},
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "http://localhost:5087",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "https://localhost:7024;http://localhost:5087",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
26 changes: 26 additions & 0 deletions Condo/Repository/CondominiumRepository.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using Condo.Context.Interfaces;
using Condo.Models;
using Condo.Repository.Interfaces;

namespace Condo.Repository;

public class CondominiumRepository : ICondominiumRepository
{
protected readonly IDatabaseContext _context;

public CondominiumRepository(IDatabaseContext context)
{
_context = context;
}
public Condominium Add(Condominium condominium)
{
_context.Condominiums.Add(condominium);
_context.SaveChanges();
return condominium;
}

public IEnumerable<Condominium> Get()
{
return _context.Condominiums;
}
}
9 changes: 9 additions & 0 deletions Condo/Repository/Interfaces/ICondominiumRepository.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using Condo.Models;

namespace Condo.Repository.Interfaces;

public interface ICondominiumRepository
{
IEnumerable<Condominium>Get();
Condominium Add(Condominium condominium);
}
7 changes: 7 additions & 0 deletions Condo/Types/CondoType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Condo.Types;

public enum CondoType
{
Residential = 0,
Commercial
}
22 changes: 22 additions & 0 deletions Condo/UseCases/CondominiumUseCase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
namespace Condo.UseCases;
using Condo.UseCases.Interfaces;
using Condo.Repository.Interfaces;
using Condo.Models;

public class CondominiumUseCase : ICondominiumUseCase
{
protected readonly ICondominiumRepository _repository;
public CondominiumUseCase(ICondominiumRepository repository)
{
_repository = repository;
}

public IEnumerable<Condominium> Get()
{
return _repository.Get();
}
public Condominium Add(Condominium condominium)
{
return _repository.Add(condominium);
}
}
Loading