aboutsummaryrefslogtreecommitdiff
path: root/API/Startup.cs
diff options
context:
space:
mode:
authortranstrike <transtrike@gmail.com>2020-12-10 17:13:52 +0200
committertranstrike <transtrike@gmail.com>2020-12-10 17:13:52 +0200
commitb9e8b4e7b8d8fc2c6b5d21370e4ec389e4d2c02a (patch)
treee5fe1d488a0ed534d207bcd0e6cd6b6454204ba6 /API/Startup.cs
parent123d1534a70d7909eca234f85f95538c538f6085 (diff)
downloadDevHive-b9e8b4e7b8d8fc2c6b5d21370e4ec389e4d2c02a.tar
DevHive-b9e8b4e7b8d8fc2c6b5d21370e4ec389e4d2c02a.tar.gz
DevHive-b9e8b4e7b8d8fc2c6b5d21370e4ec389e4d2c02a.zip
Trying to implement AutoMapper
Diffstat (limited to 'API/Startup.cs')
-rw-r--r--API/Startup.cs31
1 files changed, 29 insertions, 2 deletions
diff --git a/API/Startup.cs b/API/Startup.cs
index 6167993..6d95c1a 100644
--- a/API/Startup.cs
+++ b/API/Startup.cs
@@ -1,4 +1,6 @@
+using System;
using API.Database;
+using AutoMapper;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Identity;
@@ -8,6 +10,7 @@ using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.OpenApi.Models;
using Models.Classes;
+using Models.DTOs;
namespace API
{
@@ -25,7 +28,7 @@ namespace API
{
services.AddControllers();
- services.AddDbContext<DevHiveContext>(options =>
+ services.AddDbContext<DevHiveContext>(options =>
options.UseNpgsql(Configuration.GetConnectionString("DEV")))
.AddAuthentication()
.AddJwtBearer();
@@ -45,6 +48,8 @@ namespace API
{
c.SwaggerDoc("v1", new OpenApiInfo { Title = "API", Version = "v1" });
});
+
+ services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies());
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
@@ -71,6 +76,28 @@ namespace API
{
endpoints.MapControllers();
});
+
+ IMapper configuration = new MapperConfiguration(cfg =>
+ {
+ //cfg.DestinationMemberNamingConvention = new ExactMatchNamingConvention();
+
+ cfg.CreateMap<User, UserDTO>();
+ cfg.CreateMap<UserDTO, User>()
+ .ForMember(x => x.AccessFailedCount, o => o.Ignore())
+ .ForMember(x => x.ConcurrencyStamp, o => o.Ignore())
+ .ForMember(x => x.EmailConfirmed, o => o.Ignore())
+ .ForMember(x => x.Id, o => o.Ignore())
+ .ForMember(x => x.LockoutEnabled, o => o.Ignore())
+ .ForMember(x => x.LockoutEnd, o => o.Ignore())
+ .ForMember(x => x.NormalizedEmail, o => o.Ignore())
+ .ForMember(x => x.NormalizedUserName, o => o.Ignore())
+ .ForMember(x => x.PasswordHash, o => o.Ignore())
+ .ForMember(x => x.PhoneNumber, o => o.Ignore())
+ .ForMember(x => x.PhoneNumberConfirmed, o => o.Ignore())
+ .ForMember(x => x.ProfilePicture, o => o.Ignore())
+ .ForMember(x => x.SecurityStamp, o => o.Ignore())
+ .ForMember(x => x.TwoFactorEnabled, o => o.Ignore());
+ }).CreateMapper();
}
- }
+}
}