Skip to content
Merged
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
2 changes: 2 additions & 0 deletions deploy/helm/auth-web/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ env:
value: Server=tcp:mssql-data;Initial Catalog=O2Bionics.O2NextGen.IdServerDb;User ID=sa;Password=yourStrong(!)Password;Connection Timeout=30;
- name: Urls__PfrMvcUrl
value: https://app.pfr-centr.com
- name: Urls__IdPortalMvcUrl
value: https://idportal-api.o2nextgen.com

resources: {}
# We usually recommend not to specify default resources and to leave this as a conscious
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using O2Bionics.Services.IdPortal.DbContexts;
using O2Bionics.Services.IdPortal.Mappings;
using O2Bionics.Services.IdPortal.Models;

namespace O2Bionics.Services.IdPortal.Controllers;

[Route("Users")]
[ApiController]
public class UserController : ControllerBase
{
private readonly ApplicationDbContext _context;
private readonly UserManager<ApplicationUser> _userManager;

public UserController(ApplicationDbContext context, UserManager<ApplicationUser> userManager)
{
_context = context;
_userManager = userManager;
}

[HttpGet]
public async Task<IActionResult> GetAll()
{
var user = await _userManager.Users.ToListAsync();
return Ok(user.ToService());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using Microsoft.AspNetCore.DataProtection.EntityFrameworkCore;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using O2Bionics.Services.IdPortal.Models;

namespace O2Bionics.Services.IdPortal.DbContexts
{
public class ApplicationDbContext: IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options):base(options)
{

}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using Microsoft.AspNetCore.DataProtection.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;

namespace O2Bionics.Services.IdPortal.DbContexts;

public class DataProtectedDbContext: DbContext, IDataProtectionKeyContext
{
public DbSet<DataProtectionKey> DataProtectionKeys { get; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System.Collections.ObjectModel;

namespace O2Bionics.Services.IdPortal.Mappings;

internal static class MappingExtensions
{
public static IReadOnlyCollection<TOut> MapCollection<TIn, TOut>(this IReadOnlyCollection<TIn> input, Func<TIn, TOut> mapper)
{
if (mapper is null)
{
throw new ArgumentNullException(nameof(mapper));
}

if (input is null || input.Count == 0)
{
return Array.Empty<TOut>();
}

var output = new TOut[input.Count];
var i = 0;
foreach (var entry in input)
{
output[i] = mapper(entry);
++i;
}

return new ReadOnlyCollection<TOut>(output);
}

public static string FromDbRowVersion(this uint rowVersion) => rowVersion.ToString();

public static uint ToDbRowVersion(this string rowVersion) => uint.TryParse(rowVersion, out var parsedRowVersion) ? parsedRowVersion : 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
using O2Bionics.Services.IdPortal.Models;
using O2Bionics.Services.IdPortal.ViewModels;

namespace O2Bionics.Services.IdPortal.Mappings;

public static class UserMappings
{
public static User ToService(this ApplicationUser entity)
{
if (entity == null)
return null;

var viewModel = new User();
viewModel.Id = entity.Id;
viewModel.UserName = entity.UserName;
viewModel.FirstName = entity.FirstName;
viewModel.LastName = entity.LastName;
viewModel.Email = entity.Email;
viewModel.LockoutEnabled = entity.LockoutEnabled;
viewModel.PhoneNumber = entity.PhoneNumber;
viewModel.PhoneNumberConfirmed = entity.PhoneNumberConfirmed;
viewModel.EmailConfirmed = entity.EmailConfirmed;
viewModel.AccessFailedCount = entity.AccessFailedCount;
// var viewModel = BaseDataMappings.ToService(entity);
// viewModel.AccountId = entity.AccountId;
// viewModel.CustomerId = entity.CustomerId;
// viewModel.CreatorId = entity.CreatorId;
// viewModel.PublishCode = entity.PublishCode;
// viewModel.IsVisible = entity.IsVisible;
// viewModel.AccountId = entity.AccountId;
// viewModel.PublishDate = entity.PublishDate;
// viewModel.ExpiredDate = entity.ExpiredDate;
// viewModel.CategoryId = entity.CategoryId;
// viewModel.Lock = entity.Lock;
// viewModel.LockedDate = entity.LockedDate;
// viewModel.LockInfo = entity.LockInfo;
// viewModel.CategoryModel = entity.Category.ToService();
// viewModel.LanguageInfos = entity.LanguageInfos.ToList().ToService();
return
viewModel;
}

public static ApplicationUser ToEntity(this User model)
{
if (model == null)
return null;
var dbEntity = new ApplicationUser();
dbEntity.Id = model.Id;
dbEntity.UserName = model.UserName;
dbEntity.FirstName = model.FirstName;
dbEntity.LastName = model.LastName;
dbEntity.Email = model.Email;
dbEntity.LockoutEnabled = model.LockoutEnabled;
dbEntity.PhoneNumber = model.PhoneNumber;
dbEntity.LockoutEnd = model.LockoutEnd;
dbEntity.PhoneNumberConfirmed = model.PhoneNumberConfirmed;
dbEntity.EmailConfirmed = model.EmailConfirmed;
dbEntity.AccessFailedCount = model.AccessFailedCount;
// var dbEntity = BaseDataMappings.ToEntity(model);
// dbEntity.CustomerId = model.CustomerId;
// dbEntity.CreatorId = model.CreatorId;
// dbEntity.IsVisible = model.IsVisible;
// dbEntity.PublishCode = model.PublishCode;
// dbEntity.AccountId = model.AccountId;
// dbEntity.PublishDate = model.PublishDate;
// dbEntity.ExpiredDate = model.ExpiredDate;
// dbEntity.CategoryId = model.CategoryId;
// dbEntity.Lock = model.Lock;
// dbEntity.LockedDate = model.LockedDate;
// dbEntity.LockInfo = model.LockInfo;
// dbEntity.Category = model.CategoryModel.ToEntity();
// dbEntity.LanguageInfos = model.LanguageInfos.ToEntity().ToList();
return
dbEntity;
}
public static IReadOnlyCollection<User> ToService(this IReadOnlyCollection<ApplicationUser> entities)
=> (IReadOnlyCollection<User>)entities.MapCollection(ToService);

public static IReadOnlyCollection<ApplicationUser> ToEntity(this IReadOnlyCollection<User> entities)
=> (IReadOnlyCollection<ApplicationUser>)entities.MapCollection(ToEntity);
}
Loading