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
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk">

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

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.4">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="7.0.3" />
<PackageReference Include="NpgSql.EntityFrameworkCore.PostgreSQL.Design" Version="1.1.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Domain\Domain.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
namespace Application;
public class Class1
{

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Application.Common.DTOs.Users
{
public class UserForCreate
{

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Application.Common.DTOs.Users
{
public class UserForDisplayDto
{
public string FirstName { get; set; }
public string LastName { get; set; }
public int Age { get; set; }
public string MaritalStatus { get; set; }
public string Address { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

namespace Application.Data
{
public class ApplicationDbContext : DbContext
{
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : base(options) { }

public DbSet<User> Users { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
global using Microsoft.EntityFrameworkCore;
global using Domain.Entities;
global using Domain.Common;

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;

#nullable disable

namespace Application.Persistence.Migrations
{
/// <inheritdoc />
public partial class InitialMigrations : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Users",
columns: table => new
{
UserId = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
FirstName = table.Column<string>(type: "text", nullable: false),
LastName = table.Column<string>(type: "text", nullable: false),
Age = table.Column<int>(type: "integer", nullable: false),
MaritalStatus = table.Column<string>(type: "text", nullable: false),
Address = table.Column<string>(type: "text", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Users", x => x.UserId);
});
}

/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Users");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// <auto-generated />
using Application.Data;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;

#nullable disable

namespace Application.Persistence.Migrations
{
[DbContext(typeof(ApplicationDbContext))]
partial class ApplicationDbContextModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "7.0.4")
.HasAnnotation("Relational:MaxIdentifierLength", 63);

NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);

modelBuilder.Entity("Domain.Entities.User", b =>
{
b.Property<int>("UserId")
.ValueGeneratedOnAdd()
.HasColumnType("integer");

NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("UserId"));

b.Property<string>("Address")
.IsRequired()
.HasColumnType("text");

b.Property<int>("Age")
.HasColumnType("integer");

b.Property<string>("FirstName")
.IsRequired()
.HasColumnType("text");

b.Property<string>("LastName")
.IsRequired()
.HasColumnType("text");

b.Property<string>("MaritalStatus")
.IsRequired()
.HasColumnType("text");

b.HasKey("UserId");

b.ToTable("Users");
});
#pragma warning restore 612, 618
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Application.Users
{
public interface IRepository<T> where T : BaseEntity
{
IEnumerable<T> GetAll();
T Get(int Id);
List<T> Filter(string name);
void Insert(T entity);
void Update(T entity);
void Delete(T entity);
void SaveChanges();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Application.Data;

namespace Application.Users
{
public class Repository<T> : IRepository<T> where T : User
{
private readonly ApplicationDbContext _context;
private DbSet<T> entities;
public Repository(ApplicationDbContext context)
{
_context = context;
entities = _context.Set<T>();
}

public IEnumerable<T> GetAll()
{
return entities.AsEnumerable();
}

public T Get(int Id)
{
return entities.SingleOrDefault(u => u.UserId == Id);
}

public List<T> Filter(string name)
{
var obj = entities.Where(e => e.FirstName.ToLower() == name.ToLower()).Select(x=>x).ToList();
Console.WriteLine(obj);
return obj;
}

public void Insert(T entity)
{
if (entity == null)
{
throw new ArgumentNullException("entity");
}
entities.Add(entity);
_context.SaveChanges();
}

public void Update(T entity)
{
if (entity == null)
{
throw new ArgumentNullException("entity");
}
entities.Update(entity);
_context.SaveChanges();
}

public void Delete(T entity)
{
if (entity == null)
{
throw new ArgumentNullException("entity");
}
entities.Remove(entity);
_context.SaveChanges();
}

public void SaveChanges()
{
_context.SaveChanges();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
namespace Domain;
public class Class1
{

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System.Net.Mime;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;

namespace Domain.Common
{
public class BaseEntity
{
[Key]
public int UserId { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">

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

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Domain.Common;

namespace Domain.Entities
{
public class User : BaseEntity
{
public string FirstName { get; set; }
public string LastName { get; set; }
public int Age { get; set; }
public string MaritalStatus { get; set; }
public string Address { get; set; }
}
}
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
namespace Infrastructure;
public class Class1
{

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
global using Application.Users;
global using Domain.Entities;
global using Application.Common.DTOs.Users;
Loading