name and entity changes
This commit is contained in:
parent
3e4933e9c2
commit
70525979e7
|
|
@ -20,7 +20,7 @@ namespace TIAM.Database.DataLayers.ServiceProviders
|
|||
{
|
||||
public class ServiceProviderDal : DalBase<ServiceProviderDbContext>
|
||||
{
|
||||
|
||||
|
||||
public ServiceProviderDal() : base()
|
||||
{
|
||||
}
|
||||
|
|
@ -41,24 +41,16 @@ namespace TIAM.Database.DataLayers.ServiceProviders
|
|||
public virtual Task<TiamServiceProvider?> GetServiceProviderByIdAsync(Guid id)
|
||||
{
|
||||
Console.WriteLine($"Getting serviceProvider from db {id}");
|
||||
return Context.ServiceProviders.SingleOrDefaultAsync(x=>x.Id == id);
|
||||
return Context.ServiceProviders.SingleOrDefaultAsync(x => x.Id == id);
|
||||
}
|
||||
|
||||
//15. (IServiceProviderDataService) Create service provider
|
||||
public Task<bool> CreateServiceProviderAsync(TiamServiceProvider serviceProvider)
|
||||
{
|
||||
if(serviceProvider.Name == Context.ServiceProviders.FirstOrDefault(x=>x.Name == serviceProvider.Name)?.Name)
|
||||
{
|
||||
throw new Exception("ServiceProvider already exists");
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Context.ServiceProviders.Add(serviceProvider);
|
||||
Console.WriteLine($"Saving serviceProvider to db {serviceProvider.Id}, {serviceProvider.Name}, {serviceProvider.OwnerId}");
|
||||
return Context.SaveChangesAsync().ContinueWith(x=>x.Result > 0);
|
||||
Context.CreateServiceProvider(serviceProvider);
|
||||
return Context.SaveChangesAsync().ContinueWith(x => x.Result > 0);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
//14. (IserviceProviderDataService) Update service provider
|
||||
|
|
@ -66,7 +58,7 @@ namespace TIAM.Database.DataLayers.ServiceProviders
|
|||
{
|
||||
var dbServiceProvider = Context.ServiceProviders.FirstOrDefault(u => u.Id == serviceProvider.Id);
|
||||
if (dbServiceProvider != null)
|
||||
{
|
||||
{
|
||||
dbServiceProvider = serviceProvider;
|
||||
Context.ServiceProviders.Update(dbServiceProvider);
|
||||
return Context.SaveChangesAsync().ContinueWith(x => x.Result > 0);
|
||||
|
|
@ -115,7 +107,7 @@ namespace TIAM.Database.DataLayers.ServiceProviders
|
|||
return Context.SaveChangesAsync().ContinueWith(x => x.Result > 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
{
|
||||
return Task.FromResult(false);
|
||||
}
|
||||
}
|
||||
|
|
@ -135,7 +127,7 @@ namespace TIAM.Database.DataLayers.ServiceProviders
|
|||
|
||||
//10. (IPermissionService) create permission type
|
||||
public Task<bool> CreatePermissionsTypeAsync(PermissionsType permissionsType)
|
||||
{
|
||||
{
|
||||
bool result = false;
|
||||
|
||||
using (var transaction = Context.Database.BeginTransaction())
|
||||
|
|
@ -160,7 +152,7 @@ namespace TIAM.Database.DataLayers.ServiceProviders
|
|||
}
|
||||
else
|
||||
{
|
||||
nextBitValue = Math.Pow(2,0);
|
||||
nextBitValue = Math.Pow(2, 0);
|
||||
}
|
||||
permissionsType.PermissionBit = (int)nextBitValue;
|
||||
Context.PermissionsTypes.Add(permissionsType);
|
||||
|
|
@ -186,7 +178,7 @@ namespace TIAM.Database.DataLayers.ServiceProviders
|
|||
|
||||
public Task<int> GetPermissionFromPermissionType(PermissionsType pType)
|
||||
{
|
||||
if(Context.PermissionsTypes.FirstOrDefault(x=>x.Id == pType.Id) != null)
|
||||
if (Context.PermissionsTypes.FirstOrDefault(x => x.Id == pType.Id) != null)
|
||||
{
|
||||
return Task.FromResult(pType.PermissionBit);
|
||||
}
|
||||
|
|
@ -201,57 +193,18 @@ namespace TIAM.Database.DataLayers.ServiceProviders
|
|||
#region PermissionMappings
|
||||
|
||||
public Task<List<PermissionContextMapping>> GetPermissionContextMappingByContextIdAsync(Guid contextId)
|
||||
=> SessionAsync(x => x.GetPermissionContextMappingByContextId(contextId).ToList());
|
||||
|
||||
//2. get the contexts where the user has permission
|
||||
//public async Task<List<AssignedPermissionModel>> GetPermissionModelByUserIdAsync(Guid UserId)
|
||||
//{
|
||||
// List<AssignedPermissionModel> _permissions = new List<AssignedPermissionModel>();
|
||||
// //get all assignedUsers
|
||||
// List<AssignedUser> assignedUsers = await Context.AssignedUsers.Where(x => x.EmployeeUserId == UserId).ToListAsync();
|
||||
// //List<PermissionContextMapping> _permissionContextMappings = new List<PermissionContextMapping>();
|
||||
// List<PermissionGroupUserMapping> _permissionGroupUserMappings = new List<PermissionGroupUserMapping>();
|
||||
// //get contexts where the user has permission
|
||||
// foreach (var item in assignedUsers)
|
||||
// {
|
||||
// //get the product where the permissioncontextmapping is
|
||||
// var contextMapping = await Context.PermissionContextMappings.FirstOrDefaultAsync(x => x.SubjectId == item.Id);
|
||||
// if (contextMapping != null)
|
||||
// {
|
||||
// _permissions.Add(new AssignedPermissionModel(item.ContextId, item.Id, PermissionContextMappingSubjectType.User, item.Id.ToString(), contextMapping.Permissions));
|
||||
// }
|
||||
// //get permissiongroupusermappings where the user is in the group
|
||||
// _permissionGroupUserMappings = await Context.PermissionGroupUserMappings.Where(x => x.AssignedUserId == item.Id).ToListAsync();
|
||||
|
||||
// foreach (var groupUserMapping in _permissionGroupUserMappings)
|
||||
// {
|
||||
// //get the permissioncontextmapping where the permissiongroup is
|
||||
// var contextMapping2 = await Context.PermissionContextMappings.FirstOrDefaultAsync(x => x.Id == groupUserMapping.PermissionContextMappingId);
|
||||
// if (contextMapping2 != null)
|
||||
// {
|
||||
|
||||
// //get the group so we have the contextId
|
||||
// var group = await Context.PermissionGroups.FirstOrDefaultAsync(x => x.Id == contextMapping2.SubjectId);
|
||||
|
||||
// _permissions.Add(new AssignedPermissionModel(group.ContextId, contextMapping2.SubjectId, PermissionContextMappingSubjectType.Group, group.GroupName, contextMapping2.Permissions));
|
||||
// }
|
||||
// }
|
||||
|
||||
// }
|
||||
|
||||
// return _permissions;
|
||||
//}
|
||||
=> SessionAsync(x => x.GetPermissionContextMappingByContextId(contextId).ToList());
|
||||
|
||||
//3. (IPermissionService) get permissions of assigned users and groups
|
||||
public Task<List<AssignedPermissionModel>> GetPermissionsOfAssignedUsersAndGroupsAsyncByContextId(Guid contextId)
|
||||
public Task<List<AssignedPermissionModel>> GetPermissionsOfUserProductMappingsAndGroupsAsyncByContextId(Guid contextId)
|
||||
{
|
||||
List<AssignedPermissionModel> result = new List<AssignedPermissionModel>();
|
||||
|
||||
var AssignedUsers = Context.AssignedUsers.Where(x => x.ContextId == contextId).ToListAsync();
|
||||
var UserProductMappings = Context.UserProductMappings.Where(x => x.ProductId == contextId).ToListAsync();
|
||||
|
||||
if (AssignedUsers.Result != null)
|
||||
if (UserProductMappings.Result != null)
|
||||
{
|
||||
foreach (var item in AssignedUsers.Result)
|
||||
foreach (var item in UserProductMappings.Result)
|
||||
{
|
||||
var mappingRow = Context.PermissionContextMappings.Where(x => x.SubjectId == item.Id).ToListAsync();
|
||||
if (mappingRow.Result == null)
|
||||
|
|
@ -268,14 +221,14 @@ namespace TIAM.Database.DataLayers.ServiceProviders
|
|||
{
|
||||
foreach (var mapping in mappingRow.Result)
|
||||
{
|
||||
result.Add(new AssignedPermissionModel(item.ContextId, item.Id, mapping.SubjectType, item.EmployeeUserId.ToString(), mapping.Permissions));
|
||||
result.Add(new AssignedPermissionModel(item.ProductId, item.Id, mapping.SubjectType, item.UserId.ToString(), mapping.Permissions));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
var AssingedGroups = Context.PermissionGroups.Where(x => x.ContextId == contextId).ToListAsync();
|
||||
var AssingedGroups = Context.PermissionGroups.Where(x => x.OwnerId == contextId).ToListAsync();
|
||||
|
||||
if (AssingedGroups.Result != null)
|
||||
{
|
||||
|
|
@ -296,7 +249,7 @@ namespace TIAM.Database.DataLayers.ServiceProviders
|
|||
{
|
||||
foreach (var mapping in mappingRow.Result)
|
||||
{
|
||||
result.Add(new AssignedPermissionModel(group.ContextId, group.Id, mapping.SubjectType, group.GroupName, mapping.Permissions));
|
||||
result.Add(new AssignedPermissionModel(group.OwnerId, group.Id, mapping.SubjectType, group.GroupName, mapping.Permissions));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -304,7 +257,7 @@ namespace TIAM.Database.DataLayers.ServiceProviders
|
|||
}
|
||||
foreach (var row in result)
|
||||
{
|
||||
Console.WriteLine($"GetPermissionsOfAssignedUsersAndGroupsAsyncByContextId: {row.ContextId}, {row.SubjectId}, {row.SubjectType}, {row.Name}, {row.PermissionsValue}");
|
||||
Console.WriteLine($"GetPermissionsOfUserProductMappingsAndGroupsAsyncByContextId: {row.ContextId}, {row.SubjectId}, {row.SubjectType}, {row.Name}, {row.PermissionsValue}");
|
||||
}
|
||||
return Task.FromResult(result);
|
||||
}
|
||||
|
|
@ -316,7 +269,7 @@ namespace TIAM.Database.DataLayers.ServiceProviders
|
|||
{
|
||||
List<PermissionContextMapping> permissionContextMappings = new List<PermissionContextMapping>();
|
||||
//get all Groups where the contextId is the same
|
||||
var groups = Context.PermissionGroups.Where(x => x.ContextId == contextId).Select(x=>x.Id).ToHashSet();
|
||||
var groups = Context.PermissionGroups.Where(x => x.OwnerId == contextId).Select(x => x.Id).ToHashSet();
|
||||
permissionContextMappings = Context.PermissionContextMappings.Where(x => groups.Contains(x.SubjectId)).ToList();
|
||||
|
||||
//foreach (var item in groups.Result)
|
||||
|
|
@ -355,7 +308,7 @@ namespace TIAM.Database.DataLayers.ServiceProviders
|
|||
{
|
||||
//create permission type 1 for the group
|
||||
var permissionType = new PermissionsType(serviceProvider.Id, "View");
|
||||
Context.PermissionsTypes.Add(permissionType);
|
||||
Context.CreatePermissionsType(permissionType);
|
||||
|
||||
//Create PermissionContextMapping for the group
|
||||
|
||||
|
|
@ -363,8 +316,8 @@ namespace TIAM.Database.DataLayers.ServiceProviders
|
|||
Guid Id = Guid.NewGuid();
|
||||
permissionGroup.Id = Id;
|
||||
var permissionContextMapping = new PermissionContextMapping(serviceProvider.Id, Id, PermissionContextMappingSubjectType.Group, 1, true);
|
||||
Context.PermissionContextMappings.Add(permissionContextMapping);
|
||||
Context.PermissionGroups.Add(permissionGroup);
|
||||
Context.CreatePermissionContextMapping(permissionContextMapping);
|
||||
Context.CreatePermissionGroup(permissionGroup);
|
||||
Context.SaveChanges();
|
||||
transaction.Commit();
|
||||
result = true;
|
||||
|
|
@ -378,10 +331,10 @@ namespace TIAM.Database.DataLayers.ServiceProviders
|
|||
return Task.FromResult(result);
|
||||
}
|
||||
|
||||
public List<AssignedUser> GetAssingedUsersInPermissionGroupByGroupId(Guid groupId)
|
||||
public List<UserProductMapping> GetUserProductMappingsInPermissionGroupByGroupId(Guid groupId)
|
||||
{
|
||||
return Context.GetAssignedUsersByPermissionGroupId(groupId).ToList();
|
||||
//List<AssignedUser> assignedUsers = new List<AssignedUser>();
|
||||
return Context.GetUserProductMappingsByPermissionGroupId(groupId).ToList();
|
||||
//List<UserProductMapping> userProductMappings = new List<UserProductMapping>();
|
||||
|
||||
////let's get the permissioncontextmapping for the group
|
||||
//var pCm = Context.PermissionContextMappings.FirstOrDefault(x => x.SubjectId == groupId);
|
||||
|
|
@ -393,86 +346,62 @@ namespace TIAM.Database.DataLayers.ServiceProviders
|
|||
//{
|
||||
// foreach (var group in pGum)
|
||||
// {
|
||||
// assignedUsers.Add(Context.AssignedUsers.FirstOrDefault(x => x.Id == group.AssignedUserId));
|
||||
// userProductMappings.Add(Context.UserProductMappings.FirstOrDefault(x => x.Id == group.UserProductMappingId));
|
||||
// }
|
||||
|
||||
//}
|
||||
|
||||
//return Task.FromResult(assignedUsers);
|
||||
//return Task.FromResult(userProductMappings);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Products
|
||||
|
||||
//19. (IServiceProviderDataService) Create product
|
||||
public Task<bool> CreateProductAsync(TiamProduct product)
|
||||
//* 19. (IServiceProviderDataService) Create product
|
||||
public bool CreateProductAsync(TiamProduct product)
|
||||
{
|
||||
|
||||
|
||||
|
||||
Context.Products.Add(product);
|
||||
Console.WriteLine($"Saving product to db {product.Id}, {product.Name}, {product.OwnerId}");
|
||||
return Context.SaveChangesAsync().ContinueWith(x => x.Result > 0);
|
||||
|
||||
Context.CreateProduct(product);
|
||||
Console.WriteLine($"Saving product to db {product.Id}, {product.Name}, {product.OwnerId}");
|
||||
var _result = Context.SaveChangesAsync();
|
||||
return _result.Result > 0;
|
||||
}
|
||||
|
||||
//20. (IServiceProviderDataService) Update product
|
||||
public Task<bool> UpdateProductAsync(TiamProduct product)
|
||||
//* 20. (IServiceProviderDataService) Update product
|
||||
public TiamProduct UpdateProduct(TiamProduct product)
|
||||
{
|
||||
var dbProduct = Context.Products.FirstOrDefault(u => u.Id == product.Id);
|
||||
if (dbProduct != null)
|
||||
{
|
||||
dbProduct = product;
|
||||
Context.Products.Update(dbProduct);
|
||||
return Context.SaveChangesAsync().ContinueWith(x => x.Result > 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("Product not found");
|
||||
}
|
||||
|
||||
var prod = Context.UpdateProduct(product);
|
||||
Console.WriteLine($"Saving product to db {product.Id}, {product.Name}, {product.OwnerId}");
|
||||
Context.SaveChanges();
|
||||
return prod;
|
||||
}
|
||||
|
||||
//21. (IServiceProviderDataService) delete product
|
||||
//* 21. (IServiceProviderDataService) delete product
|
||||
public Task<bool> DeleteProductByIdAsync(Guid productId)
|
||||
{
|
||||
return TransactionAsync(ctx =>
|
||||
{
|
||||
ctx.DeleteProductById(productId);
|
||||
|
||||
//var dbProduct = ctx.Products.FirstOrDefault(u => u.Id == id);
|
||||
//if (dbProduct != null)
|
||||
//{
|
||||
// ctx.CleanUpAndRemoveAssignedUser();
|
||||
// //get assignedUsers for this product
|
||||
// var assignedUsers = ctx.AssignedUsers.Where(x => x.ContextId == id).ToList();
|
||||
// //remove assignedUsers
|
||||
// foreach (var item in assignedUsers)
|
||||
// {
|
||||
// await RemoveAssignedUserByUserIdAsync(item.Id);
|
||||
// }
|
||||
|
||||
// return true;
|
||||
//}
|
||||
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
//4. (IPermissionService) AssignPermissionToUserForContextAsync
|
||||
public Task<bool> AssignPermissionToUserForContextAsync(AssignedUser assignedUser, PermissionsType permission)
|
||||
public Task<bool> AssignPermissionToUserForContextAsync(UserProductMapping userProductMapping, PermissionsType permission)
|
||||
{
|
||||
var _assIgnedUser = Context.AssignedUsers.FirstOrDefault(x => x.Id == assignedUser.Id);
|
||||
var _assIgnedUser = Context.UserProductMappings.FirstOrDefault(x => x.Id == userProductMapping.Id);
|
||||
|
||||
if(_assIgnedUser != null)
|
||||
if (_assIgnedUser != null)
|
||||
{
|
||||
//user exists
|
||||
var _permissionInt = GetPermissionFromPermissionType(permission);
|
||||
|
||||
var permissionContextMapping = Context.PermissionContextMappings.FirstOrDefault(x => x.SubjectId == assignedUser.Id);
|
||||
var permissionContextMapping = Context.PermissionContextMappings.FirstOrDefault(x => x.SubjectId == userProductMapping.Id);
|
||||
var currentPermissions = permissionContextMapping.Permissions;
|
||||
var newPermissions = currentPermissions + _permissionInt.Result;
|
||||
permissionContextMapping.Permissions = newPermissions;
|
||||
permissionContextMapping.Permissions = newPermissions;
|
||||
return Context.SaveChangesAsync().ContinueWith(x => x.Result > 0);
|
||||
}
|
||||
else
|
||||
|
|
@ -485,85 +414,85 @@ namespace TIAM.Database.DataLayers.ServiceProviders
|
|||
#endregion
|
||||
|
||||
|
||||
#region AssignedUsers
|
||||
#region UserProductMappings
|
||||
|
||||
//22. (IServiceProviderDataService) Create assignedUser
|
||||
public Task<AssignedUser> CreateAssignedUserAsync(AssignedUser assignedUser)
|
||||
//22. (IServiceProviderDataService) Create userProductMapping
|
||||
public Task<UserProductMapping> CreateUserProductMappingAsync(UserProductMapping userProductMapping)
|
||||
{
|
||||
Context.AssignedUsers.Add(assignedUser);
|
||||
Console.WriteLine($"Saving assignedUser to db {assignedUser.Id}, {assignedUser.ContextId}, {assignedUser.EmployeeUserId}, {assignedUser.UserRoles}");
|
||||
return Context.SaveChangesAsync().ContinueWith(x => assignedUser);
|
||||
Context.UserProductMappings.Add(userProductMapping);
|
||||
Console.WriteLine($"Saving userProductMapping to db {userProductMapping.Id}, {userProductMapping.ProductId}, {userProductMapping.UserId}");
|
||||
return Context.SaveChangesAsync().ContinueWith(x => userProductMapping);
|
||||
}
|
||||
|
||||
//23. (IServiceProviderDataService) Get Assigned Users By ProductId
|
||||
public Task<List<AssignedUser>> GetAssignedUsersByProductIdAsync(Guid productId)
|
||||
public Task<List<UserProductMapping>> GetUserProductMappingsByProductIdAsync(Guid productId)
|
||||
{
|
||||
return Context.AssignedUsers.Where(x => x.ContextId == productId).ToListAsync();
|
||||
return Context.UserProductMappings.Where(x => x.ProductId == productId).ToListAsync();
|
||||
}
|
||||
|
||||
|
||||
//24 . (IServiceProviderDataService) Remove Assigned Users By Product Id
|
||||
public Task RemoveAssignedUsersByContextId(Guid contextId)
|
||||
public Task RemoveUserProductMappingsByContextId(Guid productId)
|
||||
{
|
||||
using (var transaction = Context.Database.BeginTransaction())
|
||||
{
|
||||
var assignedUsers = Context.AssignedUsers.Where(x => x.ContextId == contextId).ToList();
|
||||
//remove assignedUsers
|
||||
var userProductMappings = Context.UserProductMappings.Where(x => x.ProductId == productId).ToList();
|
||||
//remove userProductMappings
|
||||
|
||||
return Context.SaveChangesAsync().ContinueWith(x => x.Result > 0);
|
||||
|
||||
return Context.SaveChangesAsync().ContinueWith(x => x.Result > 0);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
//25. (IServiceProviderDataService) Remove Assigned from product by assignedUserId
|
||||
public Task<bool> RemoveAssignedUserAsync(AssignedUser assignedUser, bool removeFromGroups)
|
||||
//25. (IServiceProviderDataService) Remove Assigned from product by userProductMappingId
|
||||
public Task<bool> RemoveUserProductMappingAsync(UserProductMapping userProductMapping, bool removeFromGroups)
|
||||
{
|
||||
return TransactionAsync(ctx =>
|
||||
{
|
||||
var result = false;
|
||||
var assignedUserToRemove = ctx.AssignedUsers.FirstOrDefault(x => x.Id == assignedUser.Id);
|
||||
var userProductMappingToRemove = ctx.UserProductMappings.FirstOrDefault(x => x.Id == userProductMapping.Id);
|
||||
|
||||
//remove assignedUsers
|
||||
if (assignedUserToRemove == null) return false;
|
||||
//remove userProductMappings
|
||||
if (userProductMappingToRemove == null) return false;
|
||||
|
||||
|
||||
if (removeFromGroups)
|
||||
{
|
||||
//remove permissiongroupusermappings
|
||||
ctx.RemoveAssingedUserFromPermissionGroups(assignedUserToRemove.Id);
|
||||
ctx.RemoveAssingedUserFromPermissionGroups(userProductMappingToRemove.Id);
|
||||
}
|
||||
|
||||
ctx.AssignedUsers.Remove(assignedUserToRemove);
|
||||
ctx.UserProductMappings.Remove(userProductMappingToRemove);
|
||||
|
||||
|
||||
return result;
|
||||
});
|
||||
}
|
||||
|
||||
//public Task RemoveAssignedUserByUserIdAsync(Guid assignedUserId)
|
||||
//public Task RemoveUserProductMappingByUserIdAsync(Guid userProductMappingId)
|
||||
//{
|
||||
// return TransactionAsync(ctx =>
|
||||
// {
|
||||
// var assignedUser = ctx.AssignedUsers.FirstOrDefault(x => x.Id == assignedUserId);
|
||||
// //remove assignedUsers
|
||||
// if (assignedUser == null) return false;
|
||||
// var userProductMapping = ctx.UserProductMappings.FirstOrDefault(x => x.Id == userProductMappingId);
|
||||
// //remove userProductMappings
|
||||
// if (userProductMapping == null) return false;
|
||||
|
||||
// //CleanUp
|
||||
// //remove permissioncontextmappings
|
||||
// ctx.RemoveAssignedUserContextMappingBySubjectId(assignedUserId);
|
||||
// ctx.RemoveUserProductMappingContextMappingBySubjectId(userProductMappingId);
|
||||
// //remove permissiongroupusermappings
|
||||
// ctx.RemoveAssingedUserFromAllProductPermissionGroups(assignedUserId);
|
||||
// ctx.RemoveAssingedUserFromAllProductPermissionGroups(userProductMappingId);
|
||||
|
||||
// return true;
|
||||
// });
|
||||
//}
|
||||
|
||||
//public Task RemoveAssignedUserContextMappingByAssignedUserId(Guid assignedUserId)
|
||||
//public Task RemoveUserProductMappingContextMappingByUserProductMappingId(Guid userProductMappingId)
|
||||
//{
|
||||
// using (var transaction = Context.Database.BeginTransaction())
|
||||
// {
|
||||
// PermissionContextMapping? contextMapping = Context.PermissionContextMappings.FirstOrDefault(x => x.SubjectId == assignedUserId);
|
||||
// //remove assignedUsers
|
||||
// PermissionContextMapping? contextMapping = Context.PermissionContextMappings.FirstOrDefault(x => x.SubjectId == userProductMappingId);
|
||||
// //remove userProductMappings
|
||||
// if(contextMapping != null)
|
||||
// {
|
||||
// Context.PermissionContextMappings.Remove(contextMapping);
|
||||
|
|
@ -574,13 +503,13 @@ namespace TIAM.Database.DataLayers.ServiceProviders
|
|||
//}
|
||||
|
||||
|
||||
//public Task RemoveAssingedUserFromAllProductPermissionGroups(Guid assignedUserId)
|
||||
//public Task RemoveAssingedUserFromAllProductPermissionGroups(Guid userProductMappingId)
|
||||
//{
|
||||
// using (var transaction = Context.Database.BeginTransaction())
|
||||
// {
|
||||
// var permissionGroupUserMapping = Context.PermissionGroupUserMappings.Where(x => x.AssignedUserId == assignedUserId);
|
||||
// //remove assignedUsers
|
||||
|
||||
// var permissionGroupUserMapping = Context.PermissionGroupUserMappings.Where(x => x.UserProductMappingId == userProductMappingId);
|
||||
// //remove userProductMappings
|
||||
|
||||
// if (permissionGroupUserMapping != null)
|
||||
// {
|
||||
// foreach (var item in permissionGroupUserMapping)
|
||||
|
|
|
|||
|
|
@ -1,65 +1,185 @@
|
|||
using AyCode.Database.DataLayers.Users;
|
||||
using AyCode.Models.Enums;
|
||||
using Microsoft.EntityFrameworkCore.Diagnostics;
|
||||
using TIAM.Database.DbContexts.ServiceProviders;
|
||||
using TIAM.Database.DbSets.Permissions;
|
||||
using TIAM.Database.DbSets.Users;
|
||||
using TIAM.Entities.Permissions;
|
||||
using TIAM.Entities.Products;
|
||||
using TIAM.Entities.ServiceProviders;
|
||||
using TIAM.Entities.Users;
|
||||
|
||||
namespace TIAM.Database.DataLayers.ServiceProviders;
|
||||
|
||||
public static class ServiceProviderDalExtension
|
||||
{
|
||||
public static IQueryable<AssignedUser> GetAssignedUsersByPermissionGroupId(this ServiceProviderDbContext ctx, Guid permissionGroupId)
|
||||
public static IQueryable<UserProductMapping> GetUserProductMappingsByPermissionGroupId(this ServiceProviderDbContext ctx, Guid permissionGroupId)
|
||||
{
|
||||
return ctx.AssignedUsers
|
||||
return ctx.UserProductMappings
|
||||
.Where(user => ctx.PermissionGroupUserMappings
|
||||
.Where(x => x.PermissionGroupId == permissionGroupId)
|
||||
.Select(x => x.AssignedUserId)
|
||||
.Select(x => x.SubjectId)
|
||||
.Contains(user.Id));
|
||||
}
|
||||
|
||||
public static IQueryable<PermissionContextMapping> GetPermissionContextMappingByContextId(this IServiceProviderDbContext ctx, Guid contextId)
|
||||
{
|
||||
var subjectIds = ctx.GetAssignedUsersByContextId(contextId).Select(x => x.Id).
|
||||
Concat(ctx.PermissionGroups.Where(x => x.ContextId == contextId).Select(x => x.Id)).ToHashSet();
|
||||
var subjectIds = ctx.GetUserProductMappingsByProductId(contextId).Select(x => x.Id).
|
||||
Concat(ctx.PermissionGroups.Where(x => x.OwnerId == contextId).Select(x => x.Id)).ToHashSet();
|
||||
|
||||
return ctx.GetPermissionContextMappingsBySubjectIds(subjectIds);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static void CleanUpAndRemoveUserProductMappings(this IServiceProviderDbContext ctx, IEnumerable<UserProductMapping> userProductMappings)
|
||||
{
|
||||
foreach (var userProductMapping in userProductMappings)
|
||||
{
|
||||
ctx.CleanUpAndRemoveAssignedUser(userProductMapping);
|
||||
}
|
||||
}
|
||||
|
||||
public static void CleanUpAndRemoveAssignedUser(this IServiceProviderDbContext ctx, UserProductMapping userProductMapping)
|
||||
{
|
||||
ctx.RemoveContextMappingBySubjectId(userProductMapping.Id);
|
||||
ctx.RemoveAssingedUserFromPermissionGroups(userProductMapping.Id);
|
||||
|
||||
ctx.UserProductMappings.Remove(userProductMapping);
|
||||
}
|
||||
|
||||
public static bool CleanUpAndRemoveUserProductMappings(this IServiceProviderDbContext ctx, Guid userProductMappingId)
|
||||
{
|
||||
var userProductMapping = ctx.GetUserProductMappingById(userProductMappingId);
|
||||
|
||||
if (userProductMapping == null) return false;
|
||||
|
||||
ctx.CleanUpAndRemoveAssignedUser(userProductMapping);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool CreateAssignedUser(this IServiceProviderDbContext ctx, UserProductMapping userProductMapping)
|
||||
{
|
||||
if (userProductMapping == null) return false;
|
||||
|
||||
ctx.UserProductMappings.Add(userProductMapping);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static UserProductMapping UpdateUserProductMapping(this IServiceProviderDbContext context, UserProductMapping userProductMapping)
|
||||
{
|
||||
if(userProductMapping == null) return null;
|
||||
var existingUserProductMapping = context.UserProductMappings.FirstOrDefault(u => u.Id == userProductMapping.Id);
|
||||
if (existingUserProductMapping == null) return null;
|
||||
existingUserProductMapping.Id = userProductMapping.Id;
|
||||
existingUserProductMapping.UserId = userProductMapping.UserId;
|
||||
existingUserProductMapping.ProductId = userProductMapping.ProductId;
|
||||
|
||||
return existingUserProductMapping;
|
||||
|
||||
}
|
||||
|
||||
public static bool CreateProduct(this IServiceProviderDbContext ctx, TiamProduct myproduct)
|
||||
{
|
||||
if (myproduct == null) return false;
|
||||
//Automatically add assigneduser for owner
|
||||
TiamServiceProvider? productOwner = ctx.ServiceProviders.FirstOrDefault(x => x.Id == myproduct.OwnerId);
|
||||
if(productOwner == null) return false;
|
||||
var userProductMapping = new UserProductMapping(myproduct.Id, productOwner.OwnerId);
|
||||
ctx.CreateAssignedUser(userProductMapping);
|
||||
ctx.Products.Add(myproduct);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static TiamProduct UpdateProduct(this IServiceProviderDbContext ctx, TiamProduct product)
|
||||
{
|
||||
if (product == null) return null;
|
||||
|
||||
var existingProduct = ctx.Products.FirstOrDefault(u => u.Id == product.Id);
|
||||
if (existingProduct == null) return null;
|
||||
|
||||
existingProduct.Name = product.Name;
|
||||
existingProduct.OwnerId = product.OwnerId;
|
||||
existingProduct.Description = product.Description;
|
||||
existingProduct.Price = product.Price;
|
||||
existingProduct.JsonDetails = product.JsonDetails;
|
||||
existingProduct.UserMediaId = product.UserMediaId;
|
||||
existingProduct.ProductType = product.ProductType;
|
||||
|
||||
|
||||
|
||||
return existingProduct;
|
||||
}
|
||||
|
||||
public static void DeleteProductById(this IServiceProviderDbContext ctx, Guid productId)
|
||||
{
|
||||
var product = ctx.Products.FirstOrDefault(u => u.Id == productId);
|
||||
if (product == null) return;
|
||||
|
||||
ctx.CleanUpAndRemoveAssignedUsers(ctx.GetAssignedUsersByContextId(productId));
|
||||
ctx.CleanUpAndRemoveUserProductMappings(ctx.GetUserProductMappingsByProductId(productId));
|
||||
ctx.Products.Remove(product);
|
||||
}
|
||||
|
||||
public static void CleanUpAndRemoveAssignedUsers(this IServiceProviderDbContext ctx, IEnumerable<AssignedUser> assignedUsers)
|
||||
public static bool CreatePermissionGroup(this IServiceProviderDbContext ctx, PermissionGroup permissionGroup)
|
||||
{
|
||||
foreach (var assignedUser in assignedUsers)
|
||||
{
|
||||
ctx.CleanUpAndRemoveAssignedUser(assignedUser);
|
||||
}
|
||||
}
|
||||
if (permissionGroup == null) return false;
|
||||
|
||||
public static void CleanUpAndRemoveAssignedUser(this IServiceProviderDbContext ctx, AssignedUser assignedUser)
|
||||
{
|
||||
ctx.RemoveContextMappingBySubjectId(assignedUser.Id);
|
||||
ctx.RemoveAssingedUserFromPermissionGroups(assignedUser.Id);
|
||||
|
||||
ctx.AssignedUsers.Remove(assignedUser);
|
||||
}
|
||||
|
||||
public static bool CleanUpAndRemoveAssignedUsers(this IServiceProviderDbContext ctx, Guid assignedUserId)
|
||||
{
|
||||
var assignedUser = ctx.GetAssignedUserById(assignedUserId);
|
||||
|
||||
if (assignedUser == null) return false;
|
||||
|
||||
ctx.CleanUpAndRemoveAssignedUser(assignedUser);
|
||||
ctx.PermissionGroups.Add(permissionGroup);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool CreatePermissionContextMapping(this IServiceProviderDbContext ctx, PermissionContextMapping permissionContextMapping)
|
||||
{
|
||||
if (permissionContextMapping == null) return false;
|
||||
|
||||
ctx.PermissionContextMappings.Add(permissionContextMapping);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool CreatePermissionGroupUserMapping(this IServiceProviderDbContext ctx, PermissionGroupUserMapping permissionGroupUserMapping)
|
||||
{
|
||||
if (permissionGroupUserMapping == null) return false;
|
||||
|
||||
ctx.PermissionGroupUserMappings.Add(permissionGroupUserMapping);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool CreatePermissionsType(this IServiceProviderDbContext ctx, PermissionsType permissionType)
|
||||
{
|
||||
if (permissionType == null) return false;
|
||||
|
||||
ctx.PermissionsTypes.Add(permissionType);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static TiamServiceProvider CreateServiceProvider(this IServiceProviderDbContext ctx, TiamServiceProvider serviceProvider)
|
||||
{
|
||||
if (serviceProvider == null) return null;
|
||||
|
||||
ctx.ServiceProviders.Add(serviceProvider);
|
||||
var userProductMapping = new UserProductMapping(serviceProvider.Id, serviceProvider.OwnerId);
|
||||
ctx.CreateAssignedUser(userProductMapping);
|
||||
return serviceProvider;
|
||||
}
|
||||
|
||||
public static TiamServiceProvider UpdateServiceProvider(this IServiceProviderDbContext ctx, TiamServiceProvider serviceProvider)
|
||||
{
|
||||
if (serviceProvider == null) return null;
|
||||
|
||||
var existingServiceProvider = ctx.ServiceProviders.FirstOrDefault(u => u.Id == serviceProvider.Id);
|
||||
if (existingServiceProvider == null) return null;
|
||||
|
||||
existingServiceProvider.Name = serviceProvider.Name;
|
||||
existingServiceProvider.OwnerId = serviceProvider.OwnerId;
|
||||
return existingServiceProvider;
|
||||
}
|
||||
}
|
||||
|
|
@ -68,6 +68,7 @@ namespace TIAM.Database.DataLayers.Users
|
|||
|
||||
public async Task<bool> UpdateJwtRefreshTokenAsync(string email, string refreshToken)
|
||||
{
|
||||
Console.WriteLine("UserDal Update refresh token");
|
||||
var existingUser = Context.Users.FirstOrDefault(u => u.EmailAddress == email);
|
||||
if (existingUser != null)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ namespace TIAM.Database.DbContexts.ServiceProviders
|
|||
{
|
||||
public DbSet<TiamServiceProvider> ServiceProviders { get; set; }
|
||||
public DbSet<TiamProduct> Products { get; set; }
|
||||
public DbSet<AssignedUser> AssignedUsers { get; set; }
|
||||
public DbSet<UserProductMapping> UserProductMappings { get; set; }
|
||||
|
||||
public DbSet<PermissionsType> PermissionsTypes { get; set; }
|
||||
public DbSet<PermissionGroup> PermissionGroups { get; set; }
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ public static class PermissionsDbSetExtensions
|
|||
}
|
||||
|
||||
public static IQueryable<PermissionGroupUserMapping> GetAllPermissionGroupsByAssignedUserId(this IPermissionsDbSetContext ctx, Guid assignedUserId)
|
||||
=> ctx.PermissionGroupUserMappings.Where(x => x.AssignedUserId == assignedUserId);
|
||||
=> ctx.PermissionGroupUserMappings.Where(x => x.SubjectId == assignedUserId);
|
||||
|
||||
public static void RemoveAssingedUserFromPermissionGroups(this IPermissionsDbSetContext ctx, Guid assignedUserId)
|
||||
=> ctx.PermissionGroupUserMappings.RemoveRange(ctx.GetAllPermissionGroupsByAssignedUserId(assignedUserId));
|
||||
|
|
|
|||
|
|
@ -1,13 +0,0 @@
|
|||
using TIAM.Database.DbContexts.ServiceProviders;
|
||||
using TIAM.Entities.Users;
|
||||
|
||||
namespace TIAM.Database.DbSets.Users;
|
||||
|
||||
public static class AssignedUserDbSetExtensions
|
||||
{
|
||||
public static AssignedUser? GetAssignedUserById(this IAssignedUserDbSet ctx, Guid assignedUserId)
|
||||
=> ctx.AssignedUsers.FirstOrDefault(x => x.Id == assignedUserId);
|
||||
|
||||
public static IQueryable<AssignedUser> GetAssignedUsersByContextId(this IAssignedUserDbSet ctx, Guid contextId)
|
||||
=> ctx.AssignedUsers.Where(x => x.ContextId == contextId);
|
||||
}
|
||||
|
|
@ -5,5 +5,5 @@ namespace TIAM.Database.DbSets.Users;
|
|||
|
||||
public interface IAssignedUserDbSet
|
||||
{
|
||||
public DbSet<AssignedUser> AssignedUsers { get; set; }
|
||||
public DbSet<UserProductMapping> UserProductMappings { get; set; }
|
||||
}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
using TIAM.Database.DbContexts.ServiceProviders;
|
||||
using TIAM.Entities.Users;
|
||||
|
||||
namespace TIAM.Database.DbSets.Users;
|
||||
|
||||
public static class UserProductMappingDbSetExtensions
|
||||
{
|
||||
public static UserProductMapping? GetUserProductMappingById(this IAssignedUserDbSet ctx, Guid userProductMappingId)
|
||||
=> ctx.UserProductMappings.FirstOrDefault(x => x.Id == userProductMappingId);
|
||||
|
||||
public static IQueryable<UserProductMapping> GetUserProductMappingsByProductId(this IAssignedUserDbSet ctx, Guid productId)
|
||||
=> ctx.UserProductMappings.Where(x => x.ProductId == productId);
|
||||
}
|
||||
|
|
@ -18,7 +18,6 @@
|
|||
<Folder Include="DataLayers\Products\" />
|
||||
<Folder Include="DbSets\ServiceProvider\" />
|
||||
<Folder Include="DbSets\Products\" />
|
||||
<Folder Include="DbSets\Users\" />
|
||||
<Folder Include="Extensions\" />
|
||||
</ItemGroup>
|
||||
|
||||
|
|
|
|||
|
|
@ -10,7 +10,9 @@ namespace TIAM.Entities.Permissions;
|
|||
public class PermissionContextMapping : IEntityGuid, ITimeStampInfo
|
||||
{
|
||||
[Key, DatabaseGenerated(DatabaseGeneratedOption.None)]
|
||||
public Guid Id { get; set; }
|
||||
public Guid Id { get; set; }
|
||||
|
||||
public Guid ContextId { get; set; } //product or serviceprovider
|
||||
public Guid SubjectId { get; set; } //group or user
|
||||
|
||||
public PermissionContextMappingSubjectType SubjectType { get; set; } //1 for user, 2 for group
|
||||
|
|
@ -20,10 +22,11 @@ public class PermissionContextMapping : IEntityGuid, ITimeStampInfo
|
|||
public DateTime Created { get; set; }
|
||||
public DateTime Modified { get; set; }
|
||||
|
||||
public PermissionContextMapping(Guid subjectId, PermissionContextMappingSubjectType subjectType, int permissions, bool isBuiltin) : this(Guid.NewGuid(), subjectId, subjectType, permissions, isBuiltin) { }
|
||||
public PermissionContextMapping(Guid id, Guid subjectId, PermissionContextMappingSubjectType subjectType, int permissions, bool isBuiltin)
|
||||
public PermissionContextMapping(Guid contextId, Guid subjectId, PermissionContextMappingSubjectType subjectType, int permissions, bool isBuiltin) : this(Guid.NewGuid(), contextId, subjectId, subjectType, permissions, isBuiltin) { }
|
||||
public PermissionContextMapping(Guid id, Guid contextId, Guid subjectId, PermissionContextMappingSubjectType subjectType, int permissions, bool isBuiltin)
|
||||
{
|
||||
Id = id;
|
||||
Id = id;
|
||||
ContextId = contextId;
|
||||
SubjectId = subjectId;
|
||||
SubjectType = subjectType;
|
||||
Permissions = permissions;
|
||||
|
|
|
|||
|
|
@ -11,18 +11,18 @@ namespace TIAM.Entities.Permissions;
|
|||
public class PermissionGroup : GroupBase
|
||||
{
|
||||
public PermissionGroup() { }
|
||||
public PermissionGroup( Guid contextId, bool isPublic, string groupName, bool isBuiltin) : this(Guid.NewGuid(), contextId, isPublic, groupName, isBuiltin) { }
|
||||
public PermissionGroup(Guid id, Guid contextId, bool isPublic, string groupName, bool isBuiltin) : base(id, isPublic)
|
||||
public PermissionGroup( Guid ownerId, bool isPublic, string groupName, bool isBuiltin) : this(Guid.NewGuid(), ownerId, isPublic, groupName, isBuiltin) { }
|
||||
public PermissionGroup(Guid id, Guid ownerId, bool isPublic, string groupName, bool isBuiltin) : base(id, isPublic)
|
||||
{
|
||||
Id = id;
|
||||
ContextId = contextId;
|
||||
OwnerId = ownerId;
|
||||
IsPublic = isPublic;
|
||||
GroupName = groupName;
|
||||
IsBuiltin = isBuiltin;
|
||||
}
|
||||
|
||||
|
||||
public Guid ContextId { get; set; }
|
||||
public Guid OwnerId { get; set; }
|
||||
public string? GroupName { get; set; }
|
||||
public bool IsBuiltin { get; set; }
|
||||
}
|
||||
|
|
@ -10,19 +10,19 @@ public class PermissionGroupUserMapping : IEntityGuid, ITimeStampInfo
|
|||
{
|
||||
[Key, DatabaseGenerated(DatabaseGeneratedOption.None)]
|
||||
public Guid Id { get; set; }
|
||||
public Guid AssignedUserId { get; set; }
|
||||
public Guid SubjectId { get; set; }
|
||||
public Guid PermissionGroupId { get; set; }
|
||||
|
||||
public DateTime Created { get; set; }
|
||||
public DateTime Modified { get; set; }
|
||||
|
||||
public PermissionGroupUserMapping(Guid assignedUserId, Guid permissionContextMappingId) : this (Guid.NewGuid(), assignedUserId, permissionContextMappingId)
|
||||
public PermissionGroupUserMapping(Guid subjectId, Guid permissionContextMappingId) : this (Guid.NewGuid(), subjectId, permissionContextMappingId)
|
||||
{ }
|
||||
|
||||
public PermissionGroupUserMapping(Guid id, Guid assignedUserId, Guid permissionGroupId)
|
||||
public PermissionGroupUserMapping(Guid id, Guid subjectId, Guid permissionGroupId)
|
||||
{
|
||||
Id = id;
|
||||
AssignedUserId = assignedUserId;
|
||||
SubjectId = subjectId;
|
||||
PermissionGroupId = permissionGroupId;
|
||||
Created = DateTime.UtcNow;
|
||||
Modified = DateTime.UtcNow;
|
||||
|
|
|
|||
|
|
@ -1,33 +0,0 @@
|
|||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using AyCode.Interfaces.Entities;
|
||||
using AyCode.Interfaces.TimeStampInfo;
|
||||
|
||||
namespace TIAM.Entities.Users;
|
||||
|
||||
[Table("AssignedUser")]
|
||||
public class AssignedUser : IEntityGuid, ITimeStampInfo
|
||||
{
|
||||
[Key, DatabaseGenerated(DatabaseGeneratedOption.None)]
|
||||
public Guid Id { get; set; }
|
||||
public Guid ContextId { get; set; }
|
||||
public Guid EmployeeUserId { get; set; }
|
||||
|
||||
public int UserRoles { get; set; }
|
||||
|
||||
public DateTime Created { get; set; }
|
||||
public DateTime Modified { get; set; }
|
||||
|
||||
public AssignedUser(Guid contextId, Guid employeeUserId, int userRoles) : this(Guid.NewGuid(), contextId, employeeUserId, userRoles)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public AssignedUser(Guid id, Guid contextId, Guid employeeUserId, int userRoles)
|
||||
{
|
||||
Id = id;
|
||||
ContextId = contextId;
|
||||
EmployeeUserId = employeeUserId;
|
||||
UserRoles = userRoles;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using AyCode.Interfaces.Entities;
|
||||
using AyCode.Interfaces.TimeStampInfo;
|
||||
|
||||
namespace TIAM.Entities.Users;
|
||||
|
||||
[Table("UserProductMapping")]
|
||||
public class UserProductMapping : IEntityGuid, ITimeStampInfo
|
||||
{
|
||||
[Key, DatabaseGenerated(DatabaseGeneratedOption.None)]
|
||||
public Guid Id { get; set; }
|
||||
public Guid UserId { get; set; }
|
||||
public Guid ProductId { get; set; }
|
||||
|
||||
|
||||
public DateTime Created { get; set; }
|
||||
public DateTime Modified { get; set; }
|
||||
|
||||
public UserProductMapping(Guid userId, Guid productId) : this(Guid.NewGuid(), userId, productId)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public UserProductMapping(Guid id, Guid userId, Guid productId)
|
||||
{
|
||||
Id = id;
|
||||
UserId = userId;
|
||||
ProductId = productId;
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -29,7 +29,7 @@ namespace TIAMWebApp.Client.Services
|
|||
}
|
||||
|
||||
//22.
|
||||
public Task<bool> CreateAssignedUserAsync(AssignedUser assignedUser)
|
||||
public Task<bool> CreateUserProductMappingAsync(UserProductMapping userProductMapping)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
|
@ -59,7 +59,7 @@ namespace TIAMWebApp.Client.Services
|
|||
}
|
||||
|
||||
//23.
|
||||
public Task<List<AssignedUser>> GetAssignedUsersByProductIdAsync(Guid productId)
|
||||
public Task<List<UserProductMapping>> GetUserProductMappingsByProductIdAsync(Guid productId)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
|
@ -94,7 +94,7 @@ namespace TIAMWebApp.Client.Services
|
|||
}
|
||||
|
||||
//24.
|
||||
public Task RemoveAssignedUsersByContextIdAsync(Guid productId)
|
||||
public Task RemoveUserProductMappingsByContextIdAsync(Guid productId)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ using Newtonsoft.Json.Linq;
|
|||
using System.Text.Json;
|
||||
using TIAM.Database.DataLayers.ServiceProviders;
|
||||
using TIAM.Entities.Permissions;
|
||||
using TIAM.Entities.Products;
|
||||
using TIAM.Entities.ServiceProviders;
|
||||
using TIAM.Entities.Users;
|
||||
using TIAMWebApp.Shared.Application.Models;
|
||||
|
|
@ -29,6 +30,8 @@ namespace TIAMWebApp.Server.Controllers
|
|||
//15.
|
||||
[HttpPost]
|
||||
[Route("CreateServiceProvider")]
|
||||
[Tags("In-Progress", "ServiceProvider")]
|
||||
[EndpointSummary("Create assigned user")]
|
||||
public async Task<IActionResult> CreateServiceProvider([FromBody] ServiceProviderModel SerializedServiceProviderModel)
|
||||
{
|
||||
Console.WriteLine("CreateUser called");
|
||||
|
|
@ -71,7 +74,6 @@ namespace TIAMWebApp.Server.Controllers
|
|||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -102,6 +104,9 @@ namespace TIAMWebApp.Server.Controllers
|
|||
[AllowAnonymous]
|
||||
[HttpPost]
|
||||
[Route("GetServiceProvidersByOwnerId")]
|
||||
[Tags("Finished", "ServiceProvider")]
|
||||
|
||||
|
||||
public async Task<Dictionary<Guid, string>> GetServiceProvidersByOwnerId(Guid ownerId)
|
||||
{
|
||||
Console.WriteLine($"GetServiceProvidersByOwnerId called with ownerId: {ownerId}");
|
||||
|
|
@ -118,20 +123,22 @@ namespace TIAMWebApp.Server.Controllers
|
|||
//22.
|
||||
[AllowAnonymous]
|
||||
[HttpPost]
|
||||
[Route("CreateAssignedUser")]
|
||||
public async Task<IActionResult> CreateAssignedUser(Guid productId, Guid userId)
|
||||
[Route("CreateUserProductMapping")]
|
||||
[Tags("Finished", "ServiceProvider")]
|
||||
[EndpointSummary("Create assigned user to product")]
|
||||
public async Task<IActionResult> CreateUserProductMapping(CreateUserProductMappingModel createUserProductMappingModel)
|
||||
{
|
||||
if(productId == Guid.Empty || userId == Guid.Empty)
|
||||
if(createUserProductMappingModel.ContextId == Guid.Empty || createUserProductMappingModel.UserId == Guid.Empty)
|
||||
{
|
||||
return BadRequest("Invalid request");
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine($"CreateAssignedUsers called with ownerId: {productId}, {userId}");
|
||||
Console.WriteLine($"CreateUserProductMappings called with ownerId: {createUserProductMappingModel.ContextId}, {createUserProductMappingModel.ContextId}");
|
||||
|
||||
AssignedUser assignedUser = new AssignedUser(productId, userId, 1);
|
||||
UserProductMapping userProductMapping = new UserProductMapping(createUserProductMappingModel.ContextId, createUserProductMappingModel.ContextId);
|
||||
|
||||
var result = await _serviceProviderDal.CreateAssignedUserAsync(assignedUser);
|
||||
var result = await _serviceProviderDal.CreateUserProductMappingAsync(userProductMapping);
|
||||
|
||||
|
||||
return Ok(result);
|
||||
|
|
@ -142,12 +149,12 @@ namespace TIAMWebApp.Server.Controllers
|
|||
//23.
|
||||
[AllowAnonymous]
|
||||
[HttpPost]
|
||||
[Route("GetAssignedUsersForProduct")]
|
||||
public async Task<Dictionary<Guid, string>> GetAssignedUsersForProduct(Guid serviceProviderId)
|
||||
[Route("GetUserProductMappingsForProduct")]
|
||||
public async Task<Dictionary<Guid, string>> GetUserProductMappingsForProduct(Guid serviceProviderId)
|
||||
{
|
||||
Console.WriteLine($"GetAssignedUsersForServiceProvider called with serviceProviderId: {serviceProviderId}");
|
||||
Console.WriteLine($"GetUserProductMappingsForServiceProvider called with serviceProviderId: {serviceProviderId}");
|
||||
|
||||
Dictionary<Guid, string> assignedUserDictionary = new Dictionary<Guid, string>();
|
||||
Dictionary<Guid, string> userProductMappingDictionary = new Dictionary<Guid, string>();
|
||||
|
||||
var serviceProviders = await _serviceProviderDal.GetServiceProvidersAsync();
|
||||
|
||||
|
|
@ -157,6 +164,23 @@ namespace TIAMWebApp.Server.Controllers
|
|||
return myServiceproviders;
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Route("CreateProduct")]
|
||||
[Tags("In-Progress", "Product")]
|
||||
public async Task<IActionResult> CreateProduct([FromBody] TiamProduct product)
|
||||
{
|
||||
Console.WriteLine("CreateProduct called");
|
||||
if (product == null)
|
||||
{
|
||||
return BadRequest("Product is required");
|
||||
}
|
||||
else
|
||||
{
|
||||
var result = _serviceProviderDal.CreateProductAsync(product);
|
||||
return Ok(result);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -112,6 +112,7 @@ namespace TIAMWebApp.Server.Controllers
|
|||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("User not valid");
|
||||
return Unauthorized();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -89,7 +89,7 @@ namespace TIAMWebApp.Server.Controllers
|
|||
}
|
||||
else
|
||||
{
|
||||
var response = await _serviceProviderDal.AssignPermissionToUserForContextAsync(assignPermissionModel.AssignedUser, assignPermissionModel.PermissionsType);
|
||||
var response = await _serviceProviderDal.AssignPermissionToUserForContextAsync(assignPermissionModel.UserProductMapping, assignPermissionModel.PermissionsType);
|
||||
return Ok(response);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,14 +38,14 @@ namespace TIAMWebApp.Shared.Application.Interfaces
|
|||
//21. (IServiceProviderDataService) Delete product
|
||||
public Task DeleteProductAsync(Guid productId);
|
||||
|
||||
//22. (IServiceProviderDataService) Create assignedUser
|
||||
public Task<bool> CreateAssignedUserAsync(AssignedUser assignedUser);
|
||||
//22. (IServiceProviderDataService) Create userProductMapping
|
||||
public Task<bool> CreateUserProductMappingAsync(UserProductMapping userProductMapping);
|
||||
|
||||
//23. (IServiceProviderDataService) Get Assigned Users By ProductId
|
||||
public Task<List<AssignedUser>> GetAssignedUsersByProductIdAsync(Guid productId);
|
||||
public Task<List<UserProductMapping>> GetUserProductMappingsByProductIdAsync(Guid productId);
|
||||
|
||||
//24. (IServiceProviderDataService) Remove Assigned Users from Product
|
||||
public Task RemoveAssignedUsersByContextIdAsync(Guid productId);
|
||||
public Task RemoveUserProductMappingsByContextIdAsync(Guid productId);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,11 +10,11 @@ namespace TIAMWebApp.Shared.Application.Models
|
|||
{
|
||||
public class AssignPermissionModel
|
||||
{
|
||||
public AssignedUser AssignedUser { get; set; }
|
||||
public UserProductMapping UserProductMapping { get; set; }
|
||||
public PermissionsType PermissionsType { get; set; }
|
||||
public AssignPermissionModel(AssignedUser assignedUser, PermissionsType permissionsType) {
|
||||
public AssignPermissionModel(UserProductMapping userProductMapping, PermissionsType permissionsType) {
|
||||
|
||||
AssignedUser = assignedUser;
|
||||
UserProductMapping = userProductMapping;
|
||||
PermissionsType = permissionsType;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,17 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace TIAMWebApp.Shared.Application.Models
|
||||
{
|
||||
public class CreateUserProductMappingModel
|
||||
{
|
||||
|
||||
public Guid ContextId { get; set; }
|
||||
|
||||
public Guid UserId { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue