Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
P
payments
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Юнусов Ибрагим
payments
Commits
962d7eab
Commit
962d7eab
authored
Jul 27, 2022
by
Юнусов Ибрагим
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Добавил все круд операции для пользователя
parent
10764f24
Show whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
131 additions
and
439 deletions
+131
-439
UserController.cs
Payments/Payment.WebApi/Controllers/UserController.cs
+86
-1
ResponseStatusType.cs
Payments/Payment.WebApi/Enums/ResponseStatusType.cs
+8
-0
DataSeeder.cs
...ts/Payment.WebApi/Infrastructures/Databases/DataSeeder.cs
+6
-2
20220706141914_Initial.Designer.cs
...ment.WebApi/Migrations/20220706141914_Initial.Designer.cs
+0
-163
20220706141914_Initial.cs
Payments/Payment.WebApi/Migrations/20220706141914_Initial.cs
+0
-108
PaymentDbContextModelSnapshot.cs
...ayment.WebApi/Migrations/PaymentDbContextModelSnapshot.cs
+0
-161
User.cs
Payments/Payment.WebApi/Models/DbModels/User.cs
+3
-1
DefaultResponse.cs
...ts/Payment.WebApi/Models/RequestModels/DefaultResponse.cs
+8
-0
UserRequestModel.cs
...s/Payment.WebApi/Models/RequestModels/UserRequestModel.cs
+10
-0
Payment.WebApi.csproj
Payments/Payment.WebApi/Payment.WebApi.csproj
+4
-0
IUserRepository.cs
...Payment.WebApi/Repositories/Interfaces/IUserRepository.cs
+1
-0
UserRepository.cs
Payments/Payment.WebApi/Repositories/UserRepository.cs
+4
-1
appsettings.json
Payments/Payment.WebApi/appsettings.json
+1
-2
No files found.
Payments/Payment.WebApi/Controllers/UserController.cs
View file @
962d7eab
using
Microsoft.AspNetCore.Mvc
;
using
Microsoft.AspNetCore.Mvc
;
using
Payment.WebApi.Enums
;
using
Payment.WebApi.Models.DbModels
;
using
Payment.WebApi.Models.DbModels
;
using
Payment.WebApi.Models.RequestModels
;
using
Payment.WebApi.Repositories.Interfaces
;
using
Payment.WebApi.Repositories.Interfaces
;
namespace
Payment.WebApi.Controllers
;
namespace
Payment.WebApi.Controllers
;
...
@@ -16,7 +18,7 @@ public class UserController : Controller
...
@@ -16,7 +18,7 @@ public class UserController : Controller
}
}
[
HttpGet
]
[
HttpGet
]
[
ActionName
(
"Get
User
"
)]
[
ActionName
(
"Get
ById
"
)]
public
ActionResult
<
User
>
GetUser
(
int
id
)
public
ActionResult
<
User
>
GetUser
(
int
id
)
{
{
try
try
...
@@ -32,4 +34,87 @@ public class UserController : Controller
...
@@ -32,4 +34,87 @@ public class UserController : Controller
return
StatusCode
(
500
,
new
{
errorMessage
=
e
.
Message
});
return
StatusCode
(
500
,
new
{
errorMessage
=
e
.
Message
});
}
}
}
}
[
HttpPost
]
[
ActionName
(
"Create"
)]
public
ActionResult
<
DefaultResponse
>
Create
(
UserRequestModel
requestModel
)
{
try
{
_userRepository
.
Create
(
new
User
{
FirstName
=
requestModel
.
FirstName
,
LastName
=
requestModel
.
LastName
,
MiddleName
=
requestModel
.
MiddleName
,
Age
=
requestModel
.
Age
,
Email
=
requestModel
.
Email
,
IsActive
=
true
});
_userRepository
.
Save
();
return
Ok
(
new
DefaultResponse
{
ResponseStatusType
=
ResponseStatusType
.
Ok
});
}
catch
(
Exception
e
)
{
return
StatusCode
(
500
,
new
{
errorMessage
=
e
.
Message
});
}
}
[
HttpPut
]
[
ActionName
(
"Edit"
)]
public
ActionResult
<
DefaultResponse
>
Edit
(
UserRequestModel
requestModel
)
{
try
{
var
user
=
_userRepository
.
GetFirstOrDefaultByEmail
(
requestModel
.
Email
);
if
(
user
is
null
)
return
Ok
(
new
DefaultResponse
{
ResponseStatusType
=
ResponseStatusType
.
NotFound
});
_userRepository
.
Update
(
UpdateUser
(
user
,
requestModel
));
_userRepository
.
Save
();
return
Ok
(
new
DefaultResponse
{
ResponseStatusType
=
ResponseStatusType
.
Ok
});
}
catch
(
Exception
e
)
{
return
StatusCode
(
500
,
new
{
errorMessage
=
e
.
Message
});
}
}
[
HttpDelete
]
[
ActionName
(
"Delete"
)]
public
ActionResult
<
DefaultResponse
>
Delete
(
int
id
)
{
var
user
=
_userRepository
.
GetFirstOrDefaultById
(
id
);
if
(
user
is
null
)
return
Ok
(
new
DefaultResponse
{
ResponseStatusType
=
ResponseStatusType
.
NotFound
});
user
.
IsActive
=
false
;
_userRepository
.
Save
();
return
Ok
(
new
DefaultResponse
{
ResponseStatusType
=
ResponseStatusType
.
Ok
});
}
private
static
User
UpdateUser
(
User
user
,
UserRequestModel
requestModel
)
{
user
.
FirstName
=
requestModel
.
FirstName
;
user
.
LastName
=
requestModel
.
LastName
;
user
.
MiddleName
=
requestModel
.
MiddleName
;
user
.
Age
=
user
.
Age
;
return
user
;
}
}
}
\ No newline at end of file
Payments/Payment.WebApi/Enums/ResponseStatusType.cs
0 → 100644
View file @
962d7eab
namespace
Payment.WebApi.Enums
;
public
enum
ResponseStatusType
{
Undefined
=
0
,
Ok
=
1
,
NotFound
=
2
}
\ No newline at end of file
Payments/Payment.WebApi/Infrastructures/Databases/DataSeeder.cs
View file @
962d7eab
...
@@ -14,7 +14,9 @@ public static class DataSeeder
...
@@ -14,7 +14,9 @@ public static class DataSeeder
Age
=
25
,
Age
=
25
,
FirstName
=
"Jhon"
,
FirstName
=
"Jhon"
,
LastName
=
"Doe"
,
LastName
=
"Doe"
,
MiddleName
=
"Blastovich"
MiddleName
=
"Blastovich"
,
Email
=
"userOne@test"
,
IsActive
=
true
});
});
builder
.
Entity
<
User
>()
builder
.
Entity
<
User
>()
...
@@ -24,7 +26,9 @@ public static class DataSeeder
...
@@ -24,7 +26,9 @@ public static class DataSeeder
Age
=
27
,
Age
=
27
,
FirstName
=
"Jhoan"
,
FirstName
=
"Jhoan"
,
LastName
=
"Shepard"
,
LastName
=
"Shepard"
,
MiddleName
=
default
MiddleName
=
default
,
Email
=
"userOne@test"
,
IsActive
=
true
});
});
}
}
...
...
Payments/Payment.WebApi/Migrations/20220706141914_Initial.Designer.cs
deleted
100644 → 0
View file @
10764f24
// <auto-generated />
using
Microsoft.EntityFrameworkCore
;
using
Microsoft.EntityFrameworkCore.Infrastructure
;
using
Microsoft.EntityFrameworkCore.Migrations
;
using
Microsoft.EntityFrameworkCore.Storage.ValueConversion
;
using
Npgsql.EntityFrameworkCore.PostgreSQL.Metadata
;
using
Payment.WebApi.Infrastructures.Databases
;
#
nullable
disable
namespace
Payment.WebApi.Migrations
{
[
DbContext
(
typeof
(
PaymentDbContext
))]
[
Migration
(
"20220706141914_Initial"
)]
partial
class
Initial
{
protected
override
void
BuildTargetModel
(
ModelBuilder
modelBuilder
)
{
#pragma warning disable 612, 618
modelBuilder
.
HasAnnotation
(
"ProductVersion"
,
"6.0.6"
)
.
HasAnnotation
(
"Relational:MaxIdentifierLength"
,
63
);
NpgsqlModelBuilderExtensions
.
UseIdentityByDefaultColumns
(
modelBuilder
);
modelBuilder
.
Entity
(
"Payment.WebApi.Models.DbModels.Supplier"
,
b
=>
{
b
.
Property
<
int
>(
"Id"
)
.
ValueGeneratedOnAdd
()
.
HasColumnType
(
"integer"
);
NpgsqlPropertyBuilderExtensions
.
UseIdentityByDefaultColumn
(
b
.
Property
<
int
>(
"Id"
));
b
.
Property
<
string
>(
"Name"
)
.
IsRequired
()
.
HasColumnType
(
"text"
);
b
.
HasKey
(
"Id"
);
b
.
ToTable
(
"Suppliers"
);
b
.
HasData
(
new
{
Id
=
1
,
Name
=
"Алсеко"
},
new
{
Id
=
2
,
Name
=
"Казактелеком"
},
new
{
Id
=
3
,
Name
=
"Beeline"
});
});
modelBuilder
.
Entity
(
"Payment.WebApi.Models.DbModels.User"
,
b
=>
{
b
.
Property
<
int
>(
"Id"
)
.
ValueGeneratedOnAdd
()
.
HasColumnType
(
"integer"
);
NpgsqlPropertyBuilderExtensions
.
UseIdentityByDefaultColumn
(
b
.
Property
<
int
>(
"Id"
));
b
.
Property
<
int
>(
"Age"
)
.
HasColumnType
(
"integer"
);
b
.
Property
<
string
>(
"FirstName"
)
.
IsRequired
()
.
HasColumnType
(
"text"
);
b
.
Property
<
string
>(
"LastName"
)
.
IsRequired
()
.
HasColumnType
(
"text"
);
b
.
Property
<
string
>(
"MiddleName"
)
.
HasColumnType
(
"text"
);
b
.
HasKey
(
"Id"
);
b
.
ToTable
(
"Users"
);
b
.
HasData
(
new
{
Id
=
1
,
Age
=
25
,
FirstName
=
"Jhon"
,
LastName
=
"Doe"
,
MiddleName
=
"Blastovich"
},
new
{
Id
=
2
,
Age
=
27
,
FirstName
=
"Jhoan"
,
LastName
=
"Shepard"
});
});
modelBuilder
.
Entity
(
"Payment.WebApi.Models.DbModels.UserBalance"
,
b
=>
{
b
.
Property
<
int
>(
"Id"
)
.
ValueGeneratedOnAdd
()
.
HasColumnType
(
"integer"
);
NpgsqlPropertyBuilderExtensions
.
UseIdentityByDefaultColumn
(
b
.
Property
<
int
>(
"Id"
));
b
.
Property
<
decimal
>(
"Amount"
)
.
HasColumnType
(
"numeric"
);
b
.
Property
<
string
>(
"Currency"
)
.
IsRequired
()
.
HasColumnType
(
"text"
);
b
.
Property
<
int
>(
"UserId"
)
.
HasColumnType
(
"integer"
);
b
.
HasKey
(
"Id"
);
b
.
HasIndex
(
"UserId"
);
b
.
ToTable
(
"UserBalance"
);
b
.
HasData
(
new
{
Id
=
1
,
Amount
=
100
m
,
Currency
=
"KZT"
,
UserId
=
1
},
new
{
Id
=
2
,
Amount
=
250
m
,
Currency
=
"KZT"
,
UserId
=
2
});
});
modelBuilder
.
Entity
(
"Payment.WebApi.Models.DbModels.UserBalance"
,
b
=>
{
b
.
HasOne
(
"Payment.WebApi.Models.DbModels.User"
,
"User"
)
.
WithMany
(
"Balances"
)
.
HasForeignKey
(
"UserId"
)
.
OnDelete
(
DeleteBehavior
.
Cascade
)
.
IsRequired
();
b
.
Navigation
(
"User"
);
});
modelBuilder
.
Entity
(
"Payment.WebApi.Models.DbModels.User"
,
b
=>
{
b
.
Navigation
(
"Balances"
);
});
#pragma warning restore 612, 618
}
}
}
Payments/Payment.WebApi/Migrations/20220706141914_Initial.cs
deleted
100644 → 0
View file @
10764f24
using
Microsoft.EntityFrameworkCore.Migrations
;
using
Npgsql.EntityFrameworkCore.PostgreSQL.Metadata
;
#
nullable
disable
namespace
Payment.WebApi.Migrations
{
public
partial
class
Initial
:
Migration
{
protected
override
void
Up
(
MigrationBuilder
migrationBuilder
)
{
migrationBuilder
.
CreateTable
(
name
:
"Suppliers"
,
columns
:
table
=>
new
{
Id
=
table
.
Column
<
int
>(
type
:
"integer"
,
nullable
:
false
)
.
Annotation
(
"Npgsql:ValueGenerationStrategy"
,
NpgsqlValueGenerationStrategy
.
IdentityByDefaultColumn
),
Name
=
table
.
Column
<
string
>(
type
:
"text"
,
nullable
:
false
)
},
constraints
:
table
=>
{
table
.
PrimaryKey
(
"PK_Suppliers"
,
x
=>
x
.
Id
);
});
migrationBuilder
.
CreateTable
(
name
:
"Users"
,
columns
:
table
=>
new
{
Id
=
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
),
MiddleName
=
table
.
Column
<
string
>(
type
:
"text"
,
nullable
:
true
),
Age
=
table
.
Column
<
int
>(
type
:
"integer"
,
nullable
:
false
)
},
constraints
:
table
=>
{
table
.
PrimaryKey
(
"PK_Users"
,
x
=>
x
.
Id
);
});
migrationBuilder
.
CreateTable
(
name
:
"UserBalance"
,
columns
:
table
=>
new
{
Id
=
table
.
Column
<
int
>(
type
:
"integer"
,
nullable
:
false
)
.
Annotation
(
"Npgsql:ValueGenerationStrategy"
,
NpgsqlValueGenerationStrategy
.
IdentityByDefaultColumn
),
Amount
=
table
.
Column
<
decimal
>(
type
:
"numeric"
,
nullable
:
false
),
Currency
=
table
.
Column
<
string
>(
type
:
"text"
,
nullable
:
false
),
UserId
=
table
.
Column
<
int
>(
type
:
"integer"
,
nullable
:
false
)
},
constraints
:
table
=>
{
table
.
PrimaryKey
(
"PK_UserBalance"
,
x
=>
x
.
Id
);
table
.
ForeignKey
(
name
:
"FK_UserBalance_Users_UserId"
,
column
:
x
=>
x
.
UserId
,
principalTable
:
"Users"
,
principalColumn
:
"Id"
,
onDelete
:
ReferentialAction
.
Cascade
);
});
migrationBuilder
.
InsertData
(
table
:
"Suppliers"
,
columns
:
new
[]
{
"Id"
,
"Name"
},
values
:
new
object
[,]
{
{
1
,
"Алсеко"
},
{
2
,
"Казактелеком"
},
{
3
,
"Beeline"
}
});
migrationBuilder
.
InsertData
(
table
:
"Users"
,
columns
:
new
[]
{
"Id"
,
"Age"
,
"FirstName"
,
"LastName"
,
"MiddleName"
},
values
:
new
object
[,]
{
{
1
,
25
,
"Jhon"
,
"Doe"
,
"Blastovich"
},
{
2
,
27
,
"Jhoan"
,
"Shepard"
,
null
}
});
migrationBuilder
.
InsertData
(
table
:
"UserBalance"
,
columns
:
new
[]
{
"Id"
,
"Amount"
,
"Currency"
,
"UserId"
},
values
:
new
object
[,]
{
{
1
,
100
m
,
"KZT"
,
1
},
{
2
,
250
m
,
"KZT"
,
2
}
});
migrationBuilder
.
CreateIndex
(
name
:
"IX_UserBalance_UserId"
,
table
:
"UserBalance"
,
column
:
"UserId"
);
}
protected
override
void
Down
(
MigrationBuilder
migrationBuilder
)
{
migrationBuilder
.
DropTable
(
name
:
"Suppliers"
);
migrationBuilder
.
DropTable
(
name
:
"UserBalance"
);
migrationBuilder
.
DropTable
(
name
:
"Users"
);
}
}
}
Payments/Payment.WebApi/Migrations/PaymentDbContextModelSnapshot.cs
deleted
100644 → 0
View file @
10764f24
// <auto-generated />
using
Microsoft.EntityFrameworkCore
;
using
Microsoft.EntityFrameworkCore.Infrastructure
;
using
Microsoft.EntityFrameworkCore.Storage.ValueConversion
;
using
Npgsql.EntityFrameworkCore.PostgreSQL.Metadata
;
using
Payment.WebApi.Infrastructures.Databases
;
#
nullable
disable
namespace
Payment.WebApi.Migrations
{
[
DbContext
(
typeof
(
PaymentDbContext
))]
partial
class
PaymentDbContextModelSnapshot
:
ModelSnapshot
{
protected
override
void
BuildModel
(
ModelBuilder
modelBuilder
)
{
#pragma warning disable 612, 618
modelBuilder
.
HasAnnotation
(
"ProductVersion"
,
"6.0.6"
)
.
HasAnnotation
(
"Relational:MaxIdentifierLength"
,
63
);
NpgsqlModelBuilderExtensions
.
UseIdentityByDefaultColumns
(
modelBuilder
);
modelBuilder
.
Entity
(
"Payment.WebApi.Models.DbModels.Supplier"
,
b
=>
{
b
.
Property
<
int
>(
"Id"
)
.
ValueGeneratedOnAdd
()
.
HasColumnType
(
"integer"
);
NpgsqlPropertyBuilderExtensions
.
UseIdentityByDefaultColumn
(
b
.
Property
<
int
>(
"Id"
));
b
.
Property
<
string
>(
"Name"
)
.
IsRequired
()
.
HasColumnType
(
"text"
);
b
.
HasKey
(
"Id"
);
b
.
ToTable
(
"Suppliers"
);
b
.
HasData
(
new
{
Id
=
1
,
Name
=
"Алсеко"
},
new
{
Id
=
2
,
Name
=
"Казактелеком"
},
new
{
Id
=
3
,
Name
=
"Beeline"
});
});
modelBuilder
.
Entity
(
"Payment.WebApi.Models.DbModels.User"
,
b
=>
{
b
.
Property
<
int
>(
"Id"
)
.
ValueGeneratedOnAdd
()
.
HasColumnType
(
"integer"
);
NpgsqlPropertyBuilderExtensions
.
UseIdentityByDefaultColumn
(
b
.
Property
<
int
>(
"Id"
));
b
.
Property
<
int
>(
"Age"
)
.
HasColumnType
(
"integer"
);
b
.
Property
<
string
>(
"FirstName"
)
.
IsRequired
()
.
HasColumnType
(
"text"
);
b
.
Property
<
string
>(
"LastName"
)
.
IsRequired
()
.
HasColumnType
(
"text"
);
b
.
Property
<
string
>(
"MiddleName"
)
.
HasColumnType
(
"text"
);
b
.
HasKey
(
"Id"
);
b
.
ToTable
(
"Users"
);
b
.
HasData
(
new
{
Id
=
1
,
Age
=
25
,
FirstName
=
"Jhon"
,
LastName
=
"Doe"
,
MiddleName
=
"Blastovich"
},
new
{
Id
=
2
,
Age
=
27
,
FirstName
=
"Jhoan"
,
LastName
=
"Shepard"
});
});
modelBuilder
.
Entity
(
"Payment.WebApi.Models.DbModels.UserBalance"
,
b
=>
{
b
.
Property
<
int
>(
"Id"
)
.
ValueGeneratedOnAdd
()
.
HasColumnType
(
"integer"
);
NpgsqlPropertyBuilderExtensions
.
UseIdentityByDefaultColumn
(
b
.
Property
<
int
>(
"Id"
));
b
.
Property
<
decimal
>(
"Amount"
)
.
HasColumnType
(
"numeric"
);
b
.
Property
<
string
>(
"Currency"
)
.
IsRequired
()
.
HasColumnType
(
"text"
);
b
.
Property
<
int
>(
"UserId"
)
.
HasColumnType
(
"integer"
);
b
.
HasKey
(
"Id"
);
b
.
HasIndex
(
"UserId"
);
b
.
ToTable
(
"UserBalance"
);
b
.
HasData
(
new
{
Id
=
1
,
Amount
=
100
m
,
Currency
=
"KZT"
,
UserId
=
1
},
new
{
Id
=
2
,
Amount
=
250
m
,
Currency
=
"KZT"
,
UserId
=
2
});
});
modelBuilder
.
Entity
(
"Payment.WebApi.Models.DbModels.UserBalance"
,
b
=>
{
b
.
HasOne
(
"Payment.WebApi.Models.DbModels.User"
,
"User"
)
.
WithMany
(
"Balances"
)
.
HasForeignKey
(
"UserId"
)
.
OnDelete
(
DeleteBehavior
.
Cascade
)
.
IsRequired
();
b
.
Navigation
(
"User"
);
});
modelBuilder
.
Entity
(
"Payment.WebApi.Models.DbModels.User"
,
b
=>
{
b
.
Navigation
(
"Balances"
);
});
#pragma warning restore 612, 618
}
}
}
Payments/Payment.WebApi/Models/DbModels/User.cs
View file @
962d7eab
...
@@ -4,10 +4,12 @@ public class User
...
@@ -4,10 +4,12 @@ public class User
{
{
public
int
Id
{
get
;
set
;
}
public
int
Id
{
get
;
set
;
}
public
string
FirstName
{
get
;
set
;
}
public
string
FirstName
{
get
;
set
;
}
public
string
LastName
{
get
;
set
;
}
public
string
?
LastName
{
get
;
set
;
}
public
string
?
MiddleName
{
get
;
set
;
}
public
string
?
MiddleName
{
get
;
set
;
}
public
string
Email
{
get
;
set
;
}
public
int
Age
{
get
;
set
;
}
public
int
Age
{
get
;
set
;
}
public
List
<
UserBalance
>
Balances
{
get
;
set
;
}
public
List
<
UserBalance
>
Balances
{
get
;
set
;
}
public
bool
IsActive
{
get
;
set
;
}
public
User
()
public
User
()
{
{
...
...
Payments/Payment.WebApi/Models/RequestModels/DefaultResponse.cs
0 → 100644
View file @
962d7eab
using
Payment.WebApi.Enums
;
namespace
Payment.WebApi.Models.RequestModels
;
public
class
DefaultResponse
{
public
ResponseStatusType
ResponseStatusType
{
get
;
set
;
}
}
\ No newline at end of file
Payments/Payment.WebApi/Models/RequestModels/UserRequestModel.cs
0 → 100644
View file @
962d7eab
namespace
Payment.WebApi.Models.RequestModels
;
public
class
UserRequestModel
{
public
string
FirstName
{
get
;
set
;
}
public
string
?
LastName
{
get
;
set
;
}
public
string
?
MiddleName
{
get
;
set
;
}
public
string
Email
{
get
;
set
;
}
public
int
Age
{
get
;
set
;
}
}
\ No newline at end of file
Payments/Payment.WebApi/Payment.WebApi.csproj
View file @
962d7eab
...
@@ -15,4 +15,8 @@
...
@@ -15,4 +15,8 @@
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
</ItemGroup>
</ItemGroup>
<ItemGroup>
<Folder Include="Migrations" />
</ItemGroup>
</Project>
</Project>
Payments/Payment.WebApi/Repositories/Interfaces/IUserRepository.cs
View file @
962d7eab
...
@@ -5,4 +5,5 @@ namespace Payment.WebApi.Repositories.Interfaces;
...
@@ -5,4 +5,5 @@ namespace Payment.WebApi.Repositories.Interfaces;
public
interface
IUserRepository
:
IRepository
<
User
>
public
interface
IUserRepository
:
IRepository
<
User
>
{
{
User
?
GetFirstOrDefaultById
(
int
id
);
User
?
GetFirstOrDefaultById
(
int
id
);
User
?
GetFirstOrDefaultByEmail
(
string
email
);
}
}
\ No newline at end of file
Payments/Payment.WebApi/Repositories/UserRepository.cs
View file @
962d7eab
...
@@ -11,7 +11,10 @@ public class UserRepository : IUserRepository
...
@@ -11,7 +11,10 @@ public class UserRepository : IUserRepository
public
UserRepository
(
PaymentDbContext
context
)
=>
public
UserRepository
(
PaymentDbContext
context
)
=>
_context
=
context
??
throw
new
ArgumentNullException
(
nameof
(
context
));
_context
=
context
??
throw
new
ArgumentNullException
(
nameof
(
context
));
public
User
?
GetFirstOrDefaultById
(
int
id
)
=>
_context
.
Users
.
FirstOrDefault
(
s
=>
s
.
Id
==
id
);
public
User
?
GetFirstOrDefaultById
(
int
id
)
=>
_context
.
Users
.
FirstOrDefault
(
s
=>
s
.
Id
==
id
&&
s
.
IsActive
);
public
User
?
GetFirstOrDefaultByEmail
(
string
email
)
=>
_context
.
Users
.
FirstOrDefault
(
s
=>
string
.
Equals
(
s
.
Email
,
email
,
StringComparison
.
CurrentCultureIgnoreCase
)
&&
s
.
IsActive
);
public
void
Create
(
User
item
)
=>
_context
.
Users
.
Add
(
item
);
public
void
Create
(
User
item
)
=>
_context
.
Users
.
Add
(
item
);
public
void
Update
(
User
item
)
=>
_context
.
Users
.
Update
(
item
);
public
void
Update
(
User
item
)
=>
_context
.
Users
.
Update
(
item
);
public
void
Remove
(
User
item
)
=>
_context
.
Users
.
Remove
(
item
);
public
void
Remove
(
User
item
)
=>
_context
.
Users
.
Remove
(
item
);
...
...
Payments/Payment.WebApi/appsettings.json
View file @
962d7eab
...
@@ -10,4 +10,3 @@
...
@@ -10,4 +10,3 @@
"ConnectionString"
:
"Server=localhost;Port=5432;Database=Payments;UserId=postgres"
"ConnectionString"
:
"Server=localhost;Port=5432;Database=Payments;UserId=postgres"
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment