diff --git a/TIAM.Database.Test/AdminDalTest.cs b/TIAM.Database.Test/AdminDalTest.cs index 089f014d..31910602 100644 --- a/TIAM.Database.Test/AdminDalTest.cs +++ b/TIAM.Database.Test/AdminDalTest.cs @@ -8,7 +8,7 @@ using AyCode.Database.DataLayers.Users; using AyCode.Utils.Extensions; using Newtonsoft.Json; using TIAM.Database.DataLayers.Admins; -using TIAM.Database.DataLayers.ServiceProviders; +//using TIAM.Database.DataLayers.ServiceProviders; using TIAM.Database.DataLayers.Users; using TIAM.Database.DbContexts.Admins; using TIAM.Database.DbContexts.ServiceProviders; diff --git a/TIAM.Database/DataLayers/Admins/AdminDal.cs b/TIAM.Database/DataLayers/Admins/AdminDal.cs index e397ca76..3bf18b0c 100644 --- a/TIAM.Database/DataLayers/Admins/AdminDal.cs +++ b/TIAM.Database/DataLayers/Admins/AdminDal.cs @@ -1,12 +1,15 @@ using AyCode.Database.DbSets.Users; +using AyCode.Models.Enums; using Microsoft.EntityFrameworkCore; -using TIAM.Database.DataLayers.ServiceProviders; +//using TIAM.Database.DataLayers.ServiceProviders; using TIAM.Database.DbContexts.Admins; using TIAM.Database.DbSets.Permissions; using TIAM.Database.DbSets.Products; using TIAM.Database.DbSets.Users; using TIAM.Entities.Permissions; using TIAM.Entities.Products; +using TIAM.Entities.Products.DTOs; +using TIAM.Entities.ServiceProviders; using TIAM.Entities.TransferDestinations; using TIAM.Entities.Users; using TIAM.Models.Dtos.Users; @@ -20,6 +23,7 @@ namespace TIAM.Database.DataLayers.Admins } public TransferDestination? GetTransferDestinationById(Guid transferDestinationId, bool autoInclude = false) => Session(ctx=>ctx.TransferDestinations.FirstOrDefault(x=>x.Id == transferDestinationId)); + public string? GetTransferDestinationJsonById(Guid transferDestinationId) => Session(ctx => ctx.TransferDestinations.FirstOrDefault(x => x.Id == transferDestinationId)?.ToJson()); public User? GetUserById(Guid userId, bool autoInclude = false) => Session(x => x.GetUserById(userId, autoInclude)); public User? GetUserByEmail(string email, bool autoInclude = false) => Session(x => x.GetUserByEmail(email, autoInclude)); @@ -32,6 +36,7 @@ namespace TIAM.Database.DataLayers.Admins public string GetUsersJson() => Session(ctx => ctx.Users.ToJson()); public Product? GetProductById(Guid contextId) => Session(x => x.GetProductById(contextId)); + public Task AddProduct(Product product) => TransactionAsync(ctx => ctx.AddProduct(product)); public UserProductMapping? GetUserProductMappingById(Guid userProductMappingId, bool autoInclude = true) => Session(x => x.GetUserProductMappingById(userProductMappingId, autoInclude)); @@ -45,43 +50,440 @@ namespace TIAM.Database.DataLayers.Admins => Session(x => x.GetPermissionContextsViewByContextId(contextId).ToList()); public Task> GetPermissionContextsViewByContextIdAsync(Guid contextId) - => SessionAsync(x => x.GetPermissionContextsViewByContextId(contextId).ToList()); + => SessionAsync(x => x.GetPermissionContextsViewByContextId(contextId).ToList()); - //public Task> GetUsersAsync() - //{ - // return Context.Users.ToListAsync(); - //} + //15. (IServiceProviderDataService) Create service provider + public Task CreateServiceProviderAsync(TiamServiceProvider serviceProvider) + { + Context.CreateServiceProvider(serviceProvider); + return Context.SaveChangesAsync().ContinueWith(x => x.Result > 0); + } - //public Task GetUserByEmailAsync(string email) - //{ - // Console.WriteLine($"Getting user from db {email}"); - // var emailLower = email.ToLower(); - // return Context.Users.SingleOrDefaultAsync(x=>x.EmailAddress.ToLower() == emailLower); - //} + public bool CreateProductAsync(Product product) + { + Context.CreateProduct(product); + Console.WriteLine($"Saving product to db {product.Id}, {product.Name}, {product.ServiceProviderId}"); + var _result = Context.SaveChangesAsync(); + return _result.Result > 0; + } - //public Task CreateUserAsync(User user) - //{ - // user.Created = DateTime.UtcNow; - // user.Modified = DateTime.UtcNow; - // Context.Users.Add(user); - // Console.WriteLine($"Saving user to db {user.Id}, {user.EmailAddress}, {user.PhoneNumber}, {user.Password}"); - // return Context.SaveChangesAsync().ContinueWith(x=>x.Result > 0); - //} + public Task> GetServiceProvidersAsync() + { + return Context.ServiceProviders.ToListAsync(); + } + + public virtual Task GetServiceProviderByIdAsync(Guid id) + { + Console.WriteLine($"Getting serviceProvider from db {id}"); + return Context.ServiceProviders.SingleOrDefaultAsync(x => x.Id == id); + } + + public Task CreateUserProductMappingAsync(UserProductMapping userProductMapping) + { + Context.UserProductMappings.Add(userProductMapping); + Console.WriteLine($"Saving userProductMapping to db {userProductMapping.Id}, {userProductMapping.ProductId}, {userProductMapping.UserId}"); + return Context.SaveChangesAsync().ContinueWith(x => userProductMapping); + } + + #region ServiceProviders + + //14. (IserviceProviderDataService) Update service provider + public Task UpdateServiceProviderAsync(TiamServiceProvider serviceProvider) + { + 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); + } + else + { + throw new Exception("ServiceProvider not found"); + } + } + + //13. (IserviceProviderDataService) delete service provider + public Task DeleteServiceProviderAsync(Guid id) + { + using (var transaction = Context.Database.BeginTransaction()) + { + var dbServiceProvider = Context.ServiceProviders.FirstOrDefault(u => u.Id == id); + if (dbServiceProvider != null) + { + //get products for this provider + var products = Context.Products.Where(x => x.ServiceProviderId == id).ToList(); + + /*foreach (var productItem in products) + { + //delete products + var permissionContextMappings = Context.PermissionContextMappings.Where(x => x.ContextId == productItem.Id).ToList(); + //iterate through every row + foreach (var item in permissionContextMappings) + { + + if (item.SubjectType == (int)PermissionContextMappingSubjectType.Group) + { + //get users in the permissiongroup + var permissionGroupUserMapping = Context.PermissionGroupUserMappings.Where(x => x.PermissionContextMappingId == item.Id).ToList(); + //remove every row (users) from permissiongroup + foreach (var user in permissionGroupUserMapping) + { + Context.PermissionGroupUserMappings.Remove(user); + } + } + } + //remove permissioncontextmappings + Context.PermissionContextMappings.RemoveRange(permissionContextMappings); + }*/ + Context.Products.RemoveRange(products); + Context.ServiceProviders.Remove(dbServiceProvider); + return Context.SaveChangesAsync().ContinueWith(x => x.Result > 0); + } + else + { + return Task.FromResult(false); + } + } + } + + //17. (IServiceProviderDataService) get service provider by ownerId + public Task> GetServiceProvidersByOwnerIdAsync() + { + throw new NotImplementedException(); + + } + + #endregion + + #region PermissionTypes + + + //10. (IPermissionService) create permission type + public Task CreatePermissionsTypeAsync(PermissionsType permissionsType) + { + bool result = false; + + using (var transaction = Context.Database.BeginTransaction()) + { + var existingPermission = Context.PermissionsTypes + .FirstOrDefault(x => x.PermissionName == permissionsType.PermissionName)?.PermissionName; + + if (existingPermission == null) + { + //get all the permissiontypes for this context + var permissionTypes = new List(); + var nextBitValue = 0.0; + permissionTypes = Context.PermissionsTypes + .Where(x => x.ContextId == permissionsType.ContextId) + .ToList(); + + //get the max value of the permissiontypes + if (permissionTypes != null) + { + //next bit value is the power of two of the count of the permissiontypes + nextBitValue = Math.Pow(2, permissionTypes.Count); + } + else + { + nextBitValue = Math.Pow(2, 0); + } + permissionsType.PermissionBit = (int)nextBitValue; + Context.PermissionsTypes.Add(permissionsType); + Context.SaveChanges(); + transaction.Commit(); + result = true; + } + else + { + result = false; + } + + } + return Task.FromResult(result); + + } + + //11. (IPermissionService) get permission types for context + public Task>? GetPermissionTypesByContextIdAsync(Guid contextId) + { + return Context.PermissionsTypes.Where(x => x.ContextId == contextId).ToListAsync(); + } + + public Task GetPermissionFromPermissionType(PermissionsType pType) + { + if (Context.PermissionsTypes.FirstOrDefault(x => x.Id == pType.Id) != null) + { + return Task.FromResult(pType.PermissionBit); + } + else + { + return Task.FromResult(0); + } + } + + #endregion + + #region PermissionMappings + + public Task> GetPermissionsOfUserProductMappingsAndGroupsAsyncByContextId(Guid contextId) + { + List result = new List(); + + var UserProductMappings = Context.UserProductMappings.Where(x => x.ProductId == contextId).ToListAsync(); + + if (UserProductMappings.Result != null) + { + foreach (var item in UserProductMappings.Result) + { + var mappingRow = Context.PermissionContextMappings.Where(x => x.SubjectId == item.Id).ToListAsync(); + if (mappingRow.Result == null) + { + //user has no permission but is assigned... must be banned + + } + else if (mappingRow.Result.Count > 1) + { + //user has been assigned more than onece to same context + + } + else + { + foreach (var mapping in mappingRow.Result) + { + result.Add(new AssignedPermissionModel(item.ProductId, item.Id, mapping.SubjectType, item.UserId.ToString(), mapping.Permissions)); + } + } + + } + } + + var AssingedGroups = Context.PermissionGroups.Where(x => x.OwnerId == contextId).ToListAsync(); + + if (AssingedGroups.Result != null) + { + foreach (var group in AssingedGroups.Result) + { + var mappingRow = Context.PermissionContextMappings.Where(x => x.SubjectId == group.Id).ToListAsync(); + if (mappingRow.Result == null) + { + //group has no permission but is assigned... + + } + else if (mappingRow.Result.Count > 1) + { + //group has been assigned more than onece to same context + + } + else + { + foreach (var mapping in mappingRow.Result) + { + result.Add(new AssignedPermissionModel(group.OwnerId, group.Id, mapping.SubjectType, group.GroupName, mapping.Permissions)); + } + } + + } + } + foreach (var row in result) + { + Console.WriteLine($"GetPermissionsOfUserProductMappingsAndGroupsAsyncByContextId: {row.ContextId}, {row.SubjectId}, {row.SubjectType}, {row.Name}, {row.PermissionsValue}"); + } + return Task.FromResult(result); + } + + + + //12. (IPermissionService) get permission groups for context + public Task> GetPermissionsForContextByContextIdAsync(Guid contextId) + { + List permissionContextMappings = new List(); + //get all Groups where the contextId is the same + 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) + //{ + // //get permissioncontextmapping for the group if there is, so we know what permissions the group has + // var pCm = Context.PermissionContextMappings.FirstOrDefault(x => x.SubjectId == item.Id); + // permissionContextMappings.Add(pCm); + //} + return Task.FromResult(permissionContextMappings); + } + + //9. (IPermissionService) add user to permission group + public Task AddUserToPermissionGroupAsync(Guid permissionGroupId, Guid userId) + { + bool result = false; + using (var transaction = Context.Database.BeginTransaction()) + { + //do we need to check if PermissionContextMappingId exists? + var permissionGroupUserMapping = new PermissionGroupUserMapping(userId, permissionGroupId); + Context.PermissionGroupUserMappings.Add(permissionGroupUserMapping); + Context.SaveChanges(); + transaction.Commit(); + result = true; + } + return Task.FromResult(result); + } + + //8. (IPermissionService) create permission group + public Task CreatePermissionGroupAsync(PermissionGroup permissionGroup, TiamServiceProvider serviceProvider) + { + bool result = false; + using (var transaction = Context.Database.BeginTransaction()) + { + var existingPermissionGroup = Context.PermissionGroups.FirstOrDefault(x => x.GroupName == permissionGroup.GroupName)?.GroupName; + if (existingPermissionGroup == null) + { + //create permission type 1 for the group + var permissionType = new PermissionsType(serviceProvider.Id, "View"); + Context.CreatePermissionsType(permissionType); + + //Create PermissionContextMapping for the group + + //create Id for the group + Guid Id = Guid.NewGuid(); + permissionGroup.Id = Id; + var permissionContextMapping = new PermissionContextMapping(serviceProvider.Id, Id, PermissionContextMappingSubjectType.Group, 1, true); + Context.CreatePermissionContextMapping(permissionContextMapping); + Context.CreatePermissionGroup(permissionGroup); + Context.SaveChanges(); + transaction.Commit(); + result = true; + } + else + { + //group with same name already exists + result = false; + } + } + return Task.FromResult(result); + } + + public List GetUserProductMappingsInPermissionGroupByGroupId(Guid groupId) + { + return Context.GetUserProductMappingsByPermissionGroupId(groupId).ToList(); + //List userProductMappings = new List(); + + ////let's get the permissioncontextmapping for the group + //var pCm = Context.PermissionContextMappings.FirstOrDefault(x => x.SubjectId == groupId); + //Guid pCmId = pCm.Id; + + ////let's get the permissiongroupusermappings for the permissioncontextmapping + //var pGum = Context.PermissionGroupUserMappings.Where(x => x.PermissionContextMappingId == pCmId).ToList(); + //if (pGum.Count > 0) + //{ + // foreach (var group in pGum) + // { + // userProductMappings.Add(Context.UserProductMappings.FirstOrDefault(x => x.Id == group.UserProductMappingId)); + // } + + //} + + //return Task.FromResult(userProductMappings); + } + + #endregion + + #region Products + + //* 20. (IServiceProviderDataService) Update product + public Product UpdateProduct(Product product) + { + + var prod = Context.UpdateProduct(product); + Console.WriteLine($"Saving product to db {product.Id}, {product.Name}, {product.ServiceProviderId}"); + Context.SaveChanges(); + return prod; + } + + //* 21. (IServiceProviderDataService) delete product + public Task DeleteProductByIdAsync(Guid productId) + { + return TransactionAsync(ctx => + { + ctx.DeleteProductById(productId); + + return true; + }); + } + + //4. (IPermissionService) AssignPermissionToUserForContextAsync + public Task AssignPermissionToUserForContextAsync(UserProductMapping userProductMapping, PermissionsType permission) + { + var _assIgnedUser = Context.UserProductMappings.FirstOrDefault(x => x.Id == userProductMapping.Id); + + if (_assIgnedUser != null) + { + //user exists + var _permissionInt = GetPermissionFromPermissionType(permission); + + var permissionContextMapping = Context.PermissionContextMappings.FirstOrDefault(x => x.SubjectId == userProductMapping.Id); + var currentPermissions = permissionContextMapping.Permissions; + var newPermissions = currentPermissions + _permissionInt.Result; + permissionContextMapping.Permissions = newPermissions; + return Context.SaveChangesAsync().ContinueWith(x => x.Result > 0); + } + else + { + //user does not exist, let's create it + return Task.FromResult(false); + } + } + + #endregion + + + #region UserProductMappings + + //23. (IServiceProviderDataService) Get Assigned Users By ProductId + public Task> GetUserProductMappingsByProductIdAsync(Guid productId) + { + return Context.UserProductMappings.Where(x => x.ProductId == productId).ToListAsync(); + } + + + //24 . (IServiceProviderDataService) Remove Assigned Users By Product Id + public Task RemoveUserProductMappingsByContextId(Guid productId) + { + using (var transaction = Context.Database.BeginTransaction()) + { + var userProductMappings = Context.UserProductMappings.Where(x => x.ProductId == productId).ToList(); + //remove userProductMappings + + return Context.SaveChangesAsync().ContinueWith(x => x.Result > 0); + + } + } + + //25. (IServiceProviderDataService) Remove Assigned from product by userProductMappingId + public Task RemoveUserProductMappingAsync(UserProductMapping userProductMapping, bool removeFromGroups) + { + return TransactionAsync(ctx => + { + var result = false; + var userProductMappingToRemove = ctx.UserProductMappings.FirstOrDefault(x => x.Id == userProductMapping.Id); + + //remove userProductMappings + if (userProductMappingToRemove == null) return false; + + + if (removeFromGroups) + { + //remove permissiongroupusermappings + ctx.RemoveAssingedUserFromPermissionGroups(userProductMappingToRemove.Id); + } + + ctx.UserProductMappings.Remove(userProductMappingToRemove); + + + return result; + }); + } + + + #endregion - //public Task UpdateUserAsync(User user) - //{ - // var existingUser = Context.Users.FirstOrDefault(u => u.EmailAddress == user.EmailAddress); - // if (existingUser != null) - // { - // //user.Modified = DateTime.UtcNow; //ezt nem kell megadni, a háttérben ezt magától megcsinálja a DbContextBase - J. - // existingUser = user; - // Context.Users.Update(existingUser); - // return Context.SaveChangesAsync().ContinueWith(x => x.Result > 0); - // } - // else - // { - // throw new Exception("User not found"); - // } - //} } } diff --git a/TIAM.Database/DataLayers/Admins/AdminDalDbContextExtension.cs b/TIAM.Database/DataLayers/Admins/AdminDalDbContextExtension.cs new file mode 100644 index 00000000..057a4c8a --- /dev/null +++ b/TIAM.Database/DataLayers/Admins/AdminDalDbContextExtension.cs @@ -0,0 +1,202 @@ +using AyCode.Interfaces.Entities; +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using TIAM.Database.DbContexts.Admins; +using TIAM.Database.DbContexts.ServiceProviders; +using TIAM.Database.DbSets.Permissions; +using TIAM.Database.DbSets.Products; +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.Admins +{ + public static class AdminDalDbContextExtension + { + public static string ToJson(this T source) where T : class, IEntity + { + JsonSerializerSettings options = new() + { + ReferenceLoopHandling = ReferenceLoopHandling.Ignore, + NullValueHandling = NullValueHandling.Ignore + }; + + return JsonConvert.SerializeObject(source, options); + } + + public static string ToJson(this IQueryable source) where T : class, IEntity + { + JsonSerializerSettings options = new() + { + ReferenceLoopHandling = ReferenceLoopHandling.Ignore, + NullValueHandling = NullValueHandling.Ignore + }; + + return JsonConvert.SerializeObject(source, options); + } + + public static IQueryable GetUserProductMappingsByPermissionGroupId(this IAdminDbContext ctx, Guid permissionGroupId) + { + return ctx.UserProductMappings + .Where(user => ctx.PermissionGroupUserMappings + .Where(x => x.PermissionGroupId == permissionGroupId) + .Select(x => x.SubjectId) + .Contains(user.Id)); + } + + public static void CleanUpAndRemoveUserProductMappings(this IAdminDbContext ctx, IEnumerable userProductMappings) + { + foreach (var userProductMapping in userProductMappings) + { + ctx.CleanUpAndRemoveAssignedUser(userProductMapping); + } + } + + public static void CleanUpAndRemoveAssignedUser(this IAdminDbContext ctx, UserProductMapping userProductMapping) + { + ctx.RemoveContextMappingBySubjectId(userProductMapping.Id); + ctx.RemoveAssingedUserFromPermissionGroups(userProductMapping.Id); + + ctx.UserProductMappings.Remove(userProductMapping); + } + + public static bool CleanUpAndRemoveUserProductMappings(this IAdminDbContext ctx, Guid userProductMappingId) + { + var userProductMapping = ctx.GetUserProductMappingById(userProductMappingId); + + if (userProductMapping == null) return false; + + ctx.CleanUpAndRemoveAssignedUser(userProductMapping); + + return true; + } + + public static UserProductMapping UpdateUserProductMapping(this IAdminDbContext 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 Product UpdateProduct(this IAdminDbContext ctx, Product 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.ServiceProviderId = product.ServiceProviderId; + 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 IAdminDbContext ctx, Guid productId) + { + var product = ctx.Products.FirstOrDefault(u => u.Id == productId); + if (product == null) return; + + ctx.CleanUpAndRemoveUserProductMappings(ctx.GetUserProductMappingsByProductId(productId)); + ctx.Products.Remove(product); + } + + public static bool CreatePermissionGroup(this IAdminDbContext ctx, PermissionGroup permissionGroup) + { + if (permissionGroup == null) return false; + + ctx.PermissionGroups.Add(permissionGroup); + + return true; + } + + public static bool CreatePermissionContextMapping(this IAdminDbContext ctx, PermissionContextMapping permissionContextMapping) + { + if (permissionContextMapping == null) return false; + + ctx.PermissionContextMappings.Add(permissionContextMapping); + + return true; + } + + public static bool CreatePermissionGroupUserMapping(this IAdminDbContext ctx, PermissionGroupUserMapping permissionGroupUserMapping) + { + if (permissionGroupUserMapping == null) return false; + + ctx.PermissionGroupUserMappings.Add(permissionGroupUserMapping); + + return true; + } + + public static bool CreatePermissionsType(this IAdminDbContext ctx, PermissionsType permissionType) + { + if (permissionType == null) return false; + + ctx.PermissionsTypes.Add(permissionType); + + return true; + } + + public static bool CreateProduct(this IAdminDbContext ctx, Product myproduct) + { + if (myproduct == null) return false; + //Automatically add assigneduser for owner + TiamServiceProvider? productOwner = ctx.ServiceProviders.FirstOrDefault(x => x.Id == myproduct.ServiceProviderId); + if (productOwner == null) return false; + var userProductMapping = new UserProductMapping(myproduct.Id, productOwner.OwnerId); + ctx.CreateAssignedUser(userProductMapping); + ctx.AddProduct(myproduct); + + return true; + } + + public static bool CreateAssignedUser(this IAdminDbContext ctx, UserProductMapping userProductMapping) + { + if (userProductMapping == null) return false; + + ctx.UserProductMappings.Add(userProductMapping); + + return true; + } + + public static TiamServiceProvider CreateServiceProvider(this IAdminDbContext 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 IAdminDbContext 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; + } + } +} diff --git a/TIAM.Database/DataLayers/ServiceProviders/ServiceProviderDal.cs b/TIAM.Database/DataLayers/ServiceProviders/ServiceProviderDal.cs index 876bafb9..1e11b529 100644 --- a/TIAM.Database/DataLayers/ServiceProviders/ServiceProviderDal.cs +++ b/TIAM.Database/DataLayers/ServiceProviders/ServiceProviderDal.cs @@ -23,538 +23,416 @@ using Newtonsoft.Json; namespace TIAM.Database.DataLayers.ServiceProviders { - public class ServiceProviderDal : DalBase - { - - public ServiceProviderDal() : base() - { - } - - public ServiceProviderDal(ServiceProviderDbContext _object) - { - } - - //public TransferDestination? GetTransferDestinationById(Guid transferDestinationId, bool autoInclude = false) => Session(ctx=>ctx.TransferDestinations.FirstOrDefault(x=>x.Id == transferDestinationId)); - - //public User? GetUserById(Guid userId, bool autoInclude = false) => Session(x => x.GetUserById(userId, autoInclude)); - //public User? GetUserByEmail(string email, bool autoInclude = false) => Session(x => x.GetUserByEmail(email, autoInclude)); - - //public UserModelDto? GetUserModelDtoById(Guid userId) => Session(x => x.GetUserModelDtoById(userId)); - //public Task GetUserModelDtoByIdAsync(Guid userId) => SessionAsync(x => x.GetUserModelDtoById(userId)); - //public UserModelDto? GetUserModelDtoByEmail(string email) => Session(x => x.GetUserModelDtoByEmail(email)); - - //public string? GetUserJsonById(Guid userId) => Session(ctx => ctx.GetUserById(userId)?.ToJson()); - //public string GetUsersJson() => Session(ctx => ctx.Users.ToJson()); - - - //public UserProductMapping? GetUserProductMappingById(Guid userProductMappingId, bool autoInclude = true) => Session(x => x.GetUserProductMappingById(userProductMappingId, autoInclude)); - - #region ServiceProviders - - //16. (IServiceProviderDataService) get all service providers - public Task> GetServiceProvidersAsync() - { - return Context.ServiceProviders.ToListAsync(); - } - - //18. (IServiceProviderDataService) get serviceProvider by Id - public virtual Task GetServiceProviderByIdAsync(Guid id) - { - Console.WriteLine($"Getting serviceProvider from db {id}"); - return Context.ServiceProviders.SingleOrDefaultAsync(x => x.Id == id); - } - - //15. (IServiceProviderDataService) Create service provider - public Task CreateServiceProviderAsync(TiamServiceProvider serviceProvider) - { - - Context.CreateServiceProvider(serviceProvider); - return Context.SaveChangesAsync().ContinueWith(x => x.Result > 0); - - } - - //14. (IserviceProviderDataService) Update service provider - public Task UpdateServiceProviderAsync(TiamServiceProvider serviceProvider) - { - 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); - } - else - { - throw new Exception("ServiceProvider not found"); - } - } - - //13. (IserviceProviderDataService) delete service provider - public Task DeleteServiceProviderAsync(Guid id) - { - using (var transaction = Context.Database.BeginTransaction()) - { - var dbServiceProvider = Context.ServiceProviders.FirstOrDefault(u => u.Id == id); - if (dbServiceProvider != null) - { - //get products for this provider - var products = Context.Products.Where(x => x.ServiceProviderId == id).ToList(); - - /*foreach (var productItem in products) - { - //delete products - var permissionContextMappings = Context.PermissionContextMappings.Where(x => x.ContextId == productItem.Id).ToList(); - //iterate through every row - foreach (var item in permissionContextMappings) - { - - if (item.SubjectType == (int)PermissionContextMappingSubjectType.Group) - { - //get users in the permissiongroup - var permissionGroupUserMapping = Context.PermissionGroupUserMappings.Where(x => x.PermissionContextMappingId == item.Id).ToList(); - //remove every row (users) from permissiongroup - foreach (var user in permissionGroupUserMapping) - { - Context.PermissionGroupUserMappings.Remove(user); - } - } - } - //remove permissioncontextmappings - Context.PermissionContextMappings.RemoveRange(permissionContextMappings); - }*/ - Context.Products.RemoveRange(products); - Context.ServiceProviders.Remove(dbServiceProvider); - return Context.SaveChangesAsync().ContinueWith(x => x.Result > 0); - } - else - { - return Task.FromResult(false); - } - } - } - - //17. (IServiceProviderDataService) get service provider by ownerId - public Task> GetServiceProvidersByOwnerIdAsync() - { - throw new NotImplementedException(); - - } - - #endregion - - #region PermissionTypes - - - //10. (IPermissionService) create permission type - public Task CreatePermissionsTypeAsync(PermissionsType permissionsType) - { - bool result = false; - - using (var transaction = Context.Database.BeginTransaction()) - { - var existingPermission = Context.PermissionsTypes - .FirstOrDefault(x => x.PermissionName == permissionsType.PermissionName)?.PermissionName; - - if (existingPermission == null) - { - //get all the permissiontypes for this context - var permissionTypes = new List(); - var nextBitValue = 0.0; - permissionTypes = Context.PermissionsTypes - .Where(x => x.ContextId == permissionsType.ContextId) - .ToList(); - - //get the max value of the permissiontypes - if (permissionTypes != null) - { - //next bit value is the power of two of the count of the permissiontypes - nextBitValue = Math.Pow(2, permissionTypes.Count); - } - else - { - nextBitValue = Math.Pow(2, 0); - } - permissionsType.PermissionBit = (int)nextBitValue; - Context.PermissionsTypes.Add(permissionsType); - Context.SaveChanges(); - transaction.Commit(); - result = true; - } - else - { - result = false; - } - - } - return Task.FromResult(result); - - } - - //11. (IPermissionService) get permission types for context - public Task>? GetPermissionTypesByContextIdAsync(Guid contextId) - { - return Context.PermissionsTypes.Where(x => x.ContextId == contextId).ToListAsync(); - } - - public Task GetPermissionFromPermissionType(PermissionsType pType) - { - if (Context.PermissionsTypes.FirstOrDefault(x => x.Id == pType.Id) != null) - { - return Task.FromResult(pType.PermissionBit); - } - else - { - return Task.FromResult(0); - } - } - - #endregion - - #region PermissionMappings - - //public List GetPermissionContextsView(Guid subjectId, Guid contextId) - // => Session(x => x.GetPermissionContextsView(subjectId, contextId).ToList()); - - //public List GetPermissionContextsViewBySubjectId(Guid contextId) - // => Session(x => x.GetPermissionContextsViewBySubjectId(contextId).ToList()); - - //public List GetPermissionContextsViewByContextId(Guid contextId) - // => Session(x => x.GetPermissionContextsViewByContextId(contextId).ToList()); - - //public Task> GetPermissionContextsViewByContextIdAsync(Guid contextId) - // => SessionAsync(x => x.GetPermissionContextsViewByContextId(contextId).ToList()); - - //3. (IPermissionService) get permissions of assigned users and groups - public Task> GetPermissionsOfUserProductMappingsAndGroupsAsyncByContextId(Guid contextId) - { - List result = new List(); - - var UserProductMappings = Context.UserProductMappings.Where(x => x.ProductId == contextId).ToListAsync(); - - if (UserProductMappings.Result != null) - { - foreach (var item in UserProductMappings.Result) - { - var mappingRow = Context.PermissionContextMappings.Where(x => x.SubjectId == item.Id).ToListAsync(); - if (mappingRow.Result == null) - { - //user has no permission but is assigned... must be banned - - } - else if (mappingRow.Result.Count > 1) - { - //user has been assigned more than onece to same context - - } - else - { - foreach (var mapping in mappingRow.Result) - { - result.Add(new AssignedPermissionModel(item.ProductId, item.Id, mapping.SubjectType, item.UserId.ToString(), mapping.Permissions)); - } - } - - } - } - - var AssingedGroups = Context.PermissionGroups.Where(x => x.OwnerId == contextId).ToListAsync(); - - if (AssingedGroups.Result != null) - { - foreach (var group in AssingedGroups.Result) - { - var mappingRow = Context.PermissionContextMappings.Where(x => x.SubjectId == group.Id).ToListAsync(); - if (mappingRow.Result == null) - { - //group has no permission but is assigned... - - } - else if (mappingRow.Result.Count > 1) - { - //group has been assigned more than onece to same context - - } - else - { - foreach (var mapping in mappingRow.Result) - { - result.Add(new AssignedPermissionModel(group.OwnerId, group.Id, mapping.SubjectType, group.GroupName, mapping.Permissions)); - } - } - - } - } - foreach (var row in result) - { - Console.WriteLine($"GetPermissionsOfUserProductMappingsAndGroupsAsyncByContextId: {row.ContextId}, {row.SubjectId}, {row.SubjectType}, {row.Name}, {row.PermissionsValue}"); - } - return Task.FromResult(result); - } - - - - //12. (IPermissionService) get permission groups for context - public Task> GetPermissionsForContextByContextIdAsync(Guid contextId) - { - List permissionContextMappings = new List(); - //get all Groups where the contextId is the same - 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) - //{ - // //get permissioncontextmapping for the group if there is, so we know what permissions the group has - // var pCm = Context.PermissionContextMappings.FirstOrDefault(x => x.SubjectId == item.Id); - // permissionContextMappings.Add(pCm); - //} - return Task.FromResult(permissionContextMappings); - } - - //9. (IPermissionService) add user to permission group - public Task AddUserToPermissionGroupAsync(Guid permissionGroupId, Guid userId) - { - bool result = false; - using (var transaction = Context.Database.BeginTransaction()) - { - //do we need to check if PermissionContextMappingId exists? - var permissionGroupUserMapping = new PermissionGroupUserMapping(userId, permissionGroupId); - Context.PermissionGroupUserMappings.Add(permissionGroupUserMapping); - Context.SaveChanges(); - transaction.Commit(); - result = true; - } - return Task.FromResult(result); - } - - //8. (IPermissionService) create permission group - public Task CreatePermissionGroupAsync(PermissionGroup permissionGroup, TiamServiceProvider serviceProvider) - { - bool result = false; - using (var transaction = Context.Database.BeginTransaction()) - { - var existingPermissionGroup = Context.PermissionGroups.FirstOrDefault(x => x.GroupName == permissionGroup.GroupName)?.GroupName; - if (existingPermissionGroup == null) - { - //create permission type 1 for the group - var permissionType = new PermissionsType(serviceProvider.Id, "View"); - Context.CreatePermissionsType(permissionType); - - //Create PermissionContextMapping for the group - - //create Id for the group - Guid Id = Guid.NewGuid(); - permissionGroup.Id = Id; - var permissionContextMapping = new PermissionContextMapping(serviceProvider.Id, Id, PermissionContextMappingSubjectType.Group, 1, true); - Context.CreatePermissionContextMapping(permissionContextMapping); - Context.CreatePermissionGroup(permissionGroup); - Context.SaveChanges(); - transaction.Commit(); - result = true; - } - else - { - //group with same name already exists - result = false; - } - } - return Task.FromResult(result); - } - - public List GetUserProductMappingsInPermissionGroupByGroupId(Guid groupId) - { - return Context.GetUserProductMappingsByPermissionGroupId(groupId).ToList(); - //List userProductMappings = new List(); - - ////let's get the permissioncontextmapping for the group - //var pCm = Context.PermissionContextMappings.FirstOrDefault(x => x.SubjectId == groupId); - //Guid pCmId = pCm.Id; - - ////let's get the permissiongroupusermappings for the permissioncontextmapping - //var pGum = Context.PermissionGroupUserMappings.Where(x => x.PermissionContextMappingId == pCmId).ToList(); - //if (pGum.Count > 0) - //{ - // foreach (var group in pGum) - // { - // userProductMappings.Add(Context.UserProductMappings.FirstOrDefault(x => x.Id == group.UserProductMappingId)); - // } - - //} - - //return Task.FromResult(userProductMappings); - } - - #endregion - - #region Products - - //public Product? GetProductById(Guid contextId) => Session(x => x.GetProductById(contextId)); - - //* 19. (IServiceProviderDataService) Create product - public bool CreateProductAsync(Product product) - { - Context.CreateProduct(product); - Console.WriteLine($"Saving product to db {product.Id}, {product.Name}, {product.ServiceProviderId}"); - var _result = Context.SaveChangesAsync(); - return _result.Result > 0; - } - - //* 20. (IServiceProviderDataService) Update product - public Product UpdateProduct(Product product) - { - - var prod = Context.UpdateProduct(product); - Console.WriteLine($"Saving product to db {product.Id}, {product.Name}, {product.ServiceProviderId}"); - Context.SaveChanges(); - return prod; - } - - //* 21. (IServiceProviderDataService) delete product - public Task DeleteProductByIdAsync(Guid productId) - { - return TransactionAsync(ctx => - { - ctx.DeleteProductById(productId); - - return true; - }); - } - - //4. (IPermissionService) AssignPermissionToUserForContextAsync - public Task AssignPermissionToUserForContextAsync(UserProductMapping userProductMapping, PermissionsType permission) - { - var _assIgnedUser = Context.UserProductMappings.FirstOrDefault(x => x.Id == userProductMapping.Id); - - if (_assIgnedUser != null) - { - //user exists - var _permissionInt = GetPermissionFromPermissionType(permission); - - var permissionContextMapping = Context.PermissionContextMappings.FirstOrDefault(x => x.SubjectId == userProductMapping.Id); - var currentPermissions = permissionContextMapping.Permissions; - var newPermissions = currentPermissions + _permissionInt.Result; - permissionContextMapping.Permissions = newPermissions; - return Context.SaveChangesAsync().ContinueWith(x => x.Result > 0); - } - else - { - //user does not exist, let's create it - return Task.FromResult(false); - } - } - - #endregion - - - #region UserProductMappings - - //22. (IServiceProviderDataService) Create userProductMapping - public Task CreateUserProductMappingAsync(UserProductMapping userProductMapping) - { - 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> GetUserProductMappingsByProductIdAsync(Guid productId) - { - return Context.UserProductMappings.Where(x => x.ProductId == productId).ToListAsync(); - } - - - //24 . (IServiceProviderDataService) Remove Assigned Users By Product Id - public Task RemoveUserProductMappingsByContextId(Guid productId) - { - using (var transaction = Context.Database.BeginTransaction()) - { - var userProductMappings = Context.UserProductMappings.Where(x => x.ProductId == productId).ToList(); - //remove userProductMappings - - return Context.SaveChangesAsync().ContinueWith(x => x.Result > 0); - - } - } - - //25. (IServiceProviderDataService) Remove Assigned from product by userProductMappingId - public Task RemoveUserProductMappingAsync(UserProductMapping userProductMapping, bool removeFromGroups) - { - return TransactionAsync(ctx => - { - var result = false; - var userProductMappingToRemove = ctx.UserProductMappings.FirstOrDefault(x => x.Id == userProductMapping.Id); - - //remove userProductMappings - if (userProductMappingToRemove == null) return false; - - - if (removeFromGroups) - { - //remove permissiongroupusermappings - ctx.RemoveAssingedUserFromPermissionGroups(userProductMappingToRemove.Id); - } - - ctx.UserProductMappings.Remove(userProductMappingToRemove); - - - return result; - }); - } - - //public Task RemoveUserProductMappingByUserIdAsync(Guid userProductMappingId) - //{ - // return TransactionAsync(ctx => - // { - // var userProductMapping = ctx.UserProductMappings.FirstOrDefault(x => x.Id == userProductMappingId); - // //remove userProductMappings - // if (userProductMapping == null) return false; - - // //CleanUp - // //remove permissioncontextmappings - // ctx.RemoveUserProductMappingContextMappingBySubjectId(userProductMappingId); - // //remove permissiongroupusermappings - // ctx.RemoveAssingedUserFromAllProductPermissionGroups(userProductMappingId); - - // return true; - // }); - //} - - //public Task RemoveUserProductMappingContextMappingByUserProductMappingId(Guid userProductMappingId) - //{ - // using (var transaction = Context.Database.BeginTransaction()) - // { - // PermissionContextMapping? contextMapping = Context.PermissionContextMappings.FirstOrDefault(x => x.SubjectId == userProductMappingId); - // //remove userProductMappings - // if(contextMapping != null) - // { - // Context.PermissionContextMappings.Remove(contextMapping); - // } - // return Context.SaveChangesAsync().ContinueWith(x => x.Result > 0); - - // } - //} - - - //public Task RemoveAssingedUserFromAllProductPermissionGroups(Guid userProductMappingId) - //{ - // using (var transaction = Context.Database.BeginTransaction()) - // { - // var permissionGroupUserMapping = Context.PermissionGroupUserMappings.Where(x => x.UserProductMappingId == userProductMappingId); - // //remove userProductMappings - - // if (permissionGroupUserMapping != null) - // { - // foreach (var item in permissionGroupUserMapping) - // { - // Context.PermissionGroupUserMappings.Remove(item); - // } - // } - // return Context.SaveChangesAsync().ContinueWith(x => x.Result > 0); - - // } - //} - - - #endregion - - } + //public class ServiceProviderDal : DalBase + //{ + + // public ServiceProviderDal() : base() + // { + // } + + // public ServiceProviderDal(ServiceProviderDbContext _object) + // { + // } + + //// #region ServiceProviders + + //// //14. (IserviceProviderDataService) Update service provider + //// public Task UpdateServiceProviderAsync(TiamServiceProvider serviceProvider) + //// { + //// 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); + //// } + //// else + //// { + //// throw new Exception("ServiceProvider not found"); + //// } + //// } + + //// //13. (IserviceProviderDataService) delete service provider + //// public Task DeleteServiceProviderAsync(Guid id) + //// { + //// using (var transaction = Context.Database.BeginTransaction()) + //// { + //// var dbServiceProvider = Context.ServiceProviders.FirstOrDefault(u => u.Id == id); + //// if (dbServiceProvider != null) + //// { + //// //get products for this provider + //// var products = Context.Products.Where(x => x.ServiceProviderId == id).ToList(); + + //// /*foreach (var productItem in products) + //// { + //// //delete products + //// var permissionContextMappings = Context.PermissionContextMappings.Where(x => x.ContextId == productItem.Id).ToList(); + //// //iterate through every row + //// foreach (var item in permissionContextMappings) + //// { + + //// if (item.SubjectType == (int)PermissionContextMappingSubjectType.Group) + //// { + //// //get users in the permissiongroup + //// var permissionGroupUserMapping = Context.PermissionGroupUserMappings.Where(x => x.PermissionContextMappingId == item.Id).ToList(); + //// //remove every row (users) from permissiongroup + //// foreach (var user in permissionGroupUserMapping) + //// { + //// Context.PermissionGroupUserMappings.Remove(user); + //// } + //// } + //// } + //// //remove permissioncontextmappings + //// Context.PermissionContextMappings.RemoveRange(permissionContextMappings); + //// }*/ + //// Context.Products.RemoveRange(products); + //// Context.ServiceProviders.Remove(dbServiceProvider); + //// return Context.SaveChangesAsync().ContinueWith(x => x.Result > 0); + //// } + //// else + //// { + //// return Task.FromResult(false); + //// } + //// } + //// } + + //// //17. (IServiceProviderDataService) get service provider by ownerId + //// public Task> GetServiceProvidersByOwnerIdAsync() + //// { + //// throw new NotImplementedException(); + + //// } + + //// #endregion + + //// #region PermissionTypes + + + //// //10. (IPermissionService) create permission type + //// public Task CreatePermissionsTypeAsync(PermissionsType permissionsType) + //// { + //// bool result = false; + + //// using (var transaction = Context.Database.BeginTransaction()) + //// { + //// var existingPermission = Context.PermissionsTypes + //// .FirstOrDefault(x => x.PermissionName == permissionsType.PermissionName)?.PermissionName; + + //// if (existingPermission == null) + //// { + //// //get all the permissiontypes for this context + //// var permissionTypes = new List(); + //// var nextBitValue = 0.0; + //// permissionTypes = Context.PermissionsTypes + //// .Where(x => x.ContextId == permissionsType.ContextId) + //// .ToList(); + + //// //get the max value of the permissiontypes + //// if (permissionTypes != null) + //// { + //// //next bit value is the power of two of the count of the permissiontypes + //// nextBitValue = Math.Pow(2, permissionTypes.Count); + //// } + //// else + //// { + //// nextBitValue = Math.Pow(2, 0); + //// } + //// permissionsType.PermissionBit = (int)nextBitValue; + //// Context.PermissionsTypes.Add(permissionsType); + //// Context.SaveChanges(); + //// transaction.Commit(); + //// result = true; + //// } + //// else + //// { + //// result = false; + //// } + + //// } + //// return Task.FromResult(result); + + //// } + + //// //11. (IPermissionService) get permission types for context + //// public Task>? GetPermissionTypesByContextIdAsync(Guid contextId) + //// { + //// return Context.PermissionsTypes.Where(x => x.ContextId == contextId).ToListAsync(); + //// } + + //// public Task GetPermissionFromPermissionType(PermissionsType pType) + //// { + //// if (Context.PermissionsTypes.FirstOrDefault(x => x.Id == pType.Id) != null) + //// { + //// return Task.FromResult(pType.PermissionBit); + //// } + //// else + //// { + //// return Task.FromResult(0); + //// } + //// } + + //// #endregion + + //// #region PermissionMappings + + //// public Task> GetPermissionsOfUserProductMappingsAndGroupsAsyncByContextId(Guid contextId) + //// { + //// List result = new List(); + + //// var UserProductMappings = Context.UserProductMappings.Where(x => x.ProductId == contextId).ToListAsync(); + + //// if (UserProductMappings.Result != null) + //// { + //// foreach (var item in UserProductMappings.Result) + //// { + //// var mappingRow = Context.PermissionContextMappings.Where(x => x.SubjectId == item.Id).ToListAsync(); + //// if (mappingRow.Result == null) + //// { + //// //user has no permission but is assigned... must be banned + + //// } + //// else if (mappingRow.Result.Count > 1) + //// { + //// //user has been assigned more than onece to same context + + //// } + //// else + //// { + //// foreach (var mapping in mappingRow.Result) + //// { + //// result.Add(new AssignedPermissionModel(item.ProductId, item.Id, mapping.SubjectType, item.UserId.ToString(), mapping.Permissions)); + //// } + //// } + + //// } + //// } + + //// var AssingedGroups = Context.PermissionGroups.Where(x => x.OwnerId == contextId).ToListAsync(); + + //// if (AssingedGroups.Result != null) + //// { + //// foreach (var group in AssingedGroups.Result) + //// { + //// var mappingRow = Context.PermissionContextMappings.Where(x => x.SubjectId == group.Id).ToListAsync(); + //// if (mappingRow.Result == null) + //// { + //// //group has no permission but is assigned... + + //// } + //// else if (mappingRow.Result.Count > 1) + //// { + //// //group has been assigned more than onece to same context + + //// } + //// else + //// { + //// foreach (var mapping in mappingRow.Result) + //// { + //// result.Add(new AssignedPermissionModel(group.OwnerId, group.Id, mapping.SubjectType, group.GroupName, mapping.Permissions)); + //// } + //// } + + //// } + //// } + //// foreach (var row in result) + //// { + //// Console.WriteLine($"GetPermissionsOfUserProductMappingsAndGroupsAsyncByContextId: {row.ContextId}, {row.SubjectId}, {row.SubjectType}, {row.Name}, {row.PermissionsValue}"); + //// } + //// return Task.FromResult(result); + //// } + + + + //// //12. (IPermissionService) get permission groups for context + //// public Task> GetPermissionsForContextByContextIdAsync(Guid contextId) + //// { + //// List permissionContextMappings = new List(); + //// //get all Groups where the contextId is the same + //// 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) + //// //{ + //// // //get permissioncontextmapping for the group if there is, so we know what permissions the group has + //// // var pCm = Context.PermissionContextMappings.FirstOrDefault(x => x.SubjectId == item.Id); + //// // permissionContextMappings.Add(pCm); + //// //} + //// return Task.FromResult(permissionContextMappings); + //// } + + //// //9. (IPermissionService) add user to permission group + //// public Task AddUserToPermissionGroupAsync(Guid permissionGroupId, Guid userId) + //// { + //// bool result = false; + //// using (var transaction = Context.Database.BeginTransaction()) + //// { + //// //do we need to check if PermissionContextMappingId exists? + //// var permissionGroupUserMapping = new PermissionGroupUserMapping(userId, permissionGroupId); + //// Context.PermissionGroupUserMappings.Add(permissionGroupUserMapping); + //// Context.SaveChanges(); + //// transaction.Commit(); + //// result = true; + //// } + //// return Task.FromResult(result); + //// } + + //// //8. (IPermissionService) create permission group + //// public Task CreatePermissionGroupAsync(PermissionGroup permissionGroup, TiamServiceProvider serviceProvider) + //// { + //// bool result = false; + //// using (var transaction = Context.Database.BeginTransaction()) + //// { + //// var existingPermissionGroup = Context.PermissionGroups.FirstOrDefault(x => x.GroupName == permissionGroup.GroupName)?.GroupName; + //// if (existingPermissionGroup == null) + //// { + //// //create permission type 1 for the group + //// var permissionType = new PermissionsType(serviceProvider.Id, "View"); + //// Context.CreatePermissionsType(permissionType); + + //// //Create PermissionContextMapping for the group + + //// //create Id for the group + //// Guid Id = Guid.NewGuid(); + //// permissionGroup.Id = Id; + //// var permissionContextMapping = new PermissionContextMapping(serviceProvider.Id, Id, PermissionContextMappingSubjectType.Group, 1, true); + //// Context.CreatePermissionContextMapping(permissionContextMapping); + //// Context.CreatePermissionGroup(permissionGroup); + //// Context.SaveChanges(); + //// transaction.Commit(); + //// result = true; + //// } + //// else + //// { + //// //group with same name already exists + //// result = false; + //// } + //// } + //// return Task.FromResult(result); + //// } + + //// public List GetUserProductMappingsInPermissionGroupByGroupId(Guid groupId) + //// { + //// return Context.GetUserProductMappingsByPermissionGroupId(groupId).ToList(); + //// //List userProductMappings = new List(); + + //// ////let's get the permissioncontextmapping for the group + //// //var pCm = Context.PermissionContextMappings.FirstOrDefault(x => x.SubjectId == groupId); + //// //Guid pCmId = pCm.Id; + + //// ////let's get the permissiongroupusermappings for the permissioncontextmapping + //// //var pGum = Context.PermissionGroupUserMappings.Where(x => x.PermissionContextMappingId == pCmId).ToList(); + //// //if (pGum.Count > 0) + //// //{ + //// // foreach (var group in pGum) + //// // { + //// // userProductMappings.Add(Context.UserProductMappings.FirstOrDefault(x => x.Id == group.UserProductMappingId)); + //// // } + + //// //} + + //// //return Task.FromResult(userProductMappings); + //// } + + //// #endregion + + //// #region Products + + //// //* 20. (IServiceProviderDataService) Update product + //// public Product UpdateProduct(Product product) + //// { + + //// var prod = Context.UpdateProduct(product); + //// Console.WriteLine($"Saving product to db {product.Id}, {product.Name}, {product.ServiceProviderId}"); + //// Context.SaveChanges(); + //// return prod; + //// } + + //// //* 21. (IServiceProviderDataService) delete product + //// public Task DeleteProductByIdAsync(Guid productId) + //// { + //// return TransactionAsync(ctx => + //// { + //// ctx.DeleteProductById(productId); + + //// return true; + //// }); + //// } + + //// //4. (IPermissionService) AssignPermissionToUserForContextAsync + //// public Task AssignPermissionToUserForContextAsync(UserProductMapping userProductMapping, PermissionsType permission) + //// { + //// var _assIgnedUser = Context.UserProductMappings.FirstOrDefault(x => x.Id == userProductMapping.Id); + + //// if (_assIgnedUser != null) + //// { + //// //user exists + //// var _permissionInt = GetPermissionFromPermissionType(permission); + + //// var permissionContextMapping = Context.PermissionContextMappings.FirstOrDefault(x => x.SubjectId == userProductMapping.Id); + //// var currentPermissions = permissionContextMapping.Permissions; + //// var newPermissions = currentPermissions + _permissionInt.Result; + //// permissionContextMapping.Permissions = newPermissions; + //// return Context.SaveChangesAsync().ContinueWith(x => x.Result > 0); + //// } + //// else + //// { + //// //user does not exist, let's create it + //// return Task.FromResult(false); + //// } + //// } + + //// #endregion + + + //// #region UserProductMappings + + //// //23. (IServiceProviderDataService) Get Assigned Users By ProductId + //// public Task> GetUserProductMappingsByProductIdAsync(Guid productId) + //// { + //// return Context.UserProductMappings.Where(x => x.ProductId == productId).ToListAsync(); + //// } + + + //// //24 . (IServiceProviderDataService) Remove Assigned Users By Product Id + //// public Task RemoveUserProductMappingsByContextId(Guid productId) + //// { + //// using (var transaction = Context.Database.BeginTransaction()) + //// { + //// var userProductMappings = Context.UserProductMappings.Where(x => x.ProductId == productId).ToList(); + //// //remove userProductMappings + + //// return Context.SaveChangesAsync().ContinueWith(x => x.Result > 0); + + //// } + //// } + + //// //25. (IServiceProviderDataService) Remove Assigned from product by userProductMappingId + //// public Task RemoveUserProductMappingAsync(UserProductMapping userProductMapping, bool removeFromGroups) + //// { + //// return TransactionAsync(ctx => + //// { + //// var result = false; + //// var userProductMappingToRemove = ctx.UserProductMappings.FirstOrDefault(x => x.Id == userProductMapping.Id); + + //// //remove userProductMappings + //// if (userProductMappingToRemove == null) return false; + + + //// if (removeFromGroups) + //// { + //// //remove permissiongroupusermappings + //// ctx.RemoveAssingedUserFromPermissionGroups(userProductMappingToRemove.Id); + //// } + + //// ctx.UserProductMappings.Remove(userProductMappingToRemove); + + + //// return result; + //// }); + //// } + + + //// #endregion + + ////} } diff --git a/TIAM.Database/DataLayers/ServiceProviders/ServiceProviderDalExtension.cs b/TIAM.Database/DataLayers/ServiceProviders/ServiceProviderDalExtension.cs index e0e3cef2..dbd95f89 100644 --- a/TIAM.Database/DataLayers/ServiceProviders/ServiceProviderDalExtension.cs +++ b/TIAM.Database/DataLayers/ServiceProviders/ServiceProviderDalExtension.cs @@ -15,189 +15,143 @@ using TIAM.Entities.Products; using TIAM.Entities.ServiceProviders; using TIAM.Entities.Users; -namespace TIAM.Database.DataLayers.ServiceProviders; +//namespace TIAM.Database.DataLayers.ServiceProviders; -public static class ServiceProviderDalExtension -{ - public static string ToJson(this T source) where T : class, IEntity - { - JsonSerializerSettings options = new() - { - ReferenceLoopHandling = ReferenceLoopHandling.Ignore, - NullValueHandling = NullValueHandling.Ignore - }; +//public static class ServiceProviderDalExtension +//{ +// //public static string ToJson(this T source) where T : class, IEntity +// //{ +// // JsonSerializerSettings options = new() +// // { +// // ReferenceLoopHandling = ReferenceLoopHandling.Ignore, +// // NullValueHandling = NullValueHandling.Ignore +// // }; - return JsonConvert.SerializeObject(source, options); - } +// // return JsonConvert.SerializeObject(source, options); +// //} - public static string ToJson(this IQueryable source) where T : class, IEntity - { - JsonSerializerSettings options = new() - { - ReferenceLoopHandling = ReferenceLoopHandling.Ignore, - NullValueHandling = NullValueHandling.Ignore - }; +// //public static string ToJson(this IQueryable source) where T : class, IEntity +// //{ +// // JsonSerializerSettings options = new() +// // { +// // ReferenceLoopHandling = ReferenceLoopHandling.Ignore, +// // NullValueHandling = NullValueHandling.Ignore +// // }; - return JsonConvert.SerializeObject(source, options); - } +// // return JsonConvert.SerializeObject(source, options); +// //} - public static IQueryable GetUserProductMappingsByPermissionGroupId(this IServiceProviderDbContext ctx, Guid permissionGroupId) - { - return ctx.UserProductMappings - .Where(user => ctx.PermissionGroupUserMappings - .Where(x => x.PermissionGroupId == permissionGroupId) - .Select(x => x.SubjectId) - .Contains(user.Id)); - } +// //public static IQueryable GetUserProductMappingsByPermissionGroupId(this IServiceProviderDbContext ctx, Guid permissionGroupId) +// //{ +// // return ctx.UserProductMappings +// // .Where(user => ctx.PermissionGroupUserMappings +// // .Where(x => x.PermissionGroupId == permissionGroupId) +// // .Select(x => x.SubjectId) +// // .Contains(user.Id)); +// //} - public static void CleanUpAndRemoveUserProductMappings(this IServiceProviderDbContext ctx, IEnumerable userProductMappings) - { - foreach (var userProductMapping in userProductMappings) - { - ctx.CleanUpAndRemoveAssignedUser(userProductMapping); - } - } +// //public static void CleanUpAndRemoveUserProductMappings(this IServiceProviderDbContext ctx, IEnumerable 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); +// //public static void CleanUpAndRemoveAssignedUser(this IServiceProviderDbContext ctx, UserProductMapping userProductMapping) +// //{ +// // ctx.RemoveContextMappingBySubjectId(userProductMapping.Id); +// // ctx.RemoveAssingedUserFromPermissionGroups(userProductMapping.Id); - ctx.UserProductMappings.Remove(userProductMapping); - } +// // ctx.UserProductMappings.Remove(userProductMapping); +// //} - public static bool CleanUpAndRemoveUserProductMappings(this IServiceProviderDbContext ctx, Guid userProductMappingId) - { - var userProductMapping = ctx.GetUserProductMappingById(userProductMappingId); +// //public static bool CleanUpAndRemoveUserProductMappings(this IServiceProviderDbContext ctx, Guid userProductMappingId) +// //{ +// // var userProductMapping = ctx.GetUserProductMappingById(userProductMappingId); - if (userProductMapping == null) return false; +// // if (userProductMapping == null) return false; - ctx.CleanUpAndRemoveAssignedUser(userProductMapping); +// // ctx.CleanUpAndRemoveAssignedUser(userProductMapping); - return true; - } +// // return true; +// //} - public static bool CreateAssignedUser(this IServiceProviderDbContext ctx, UserProductMapping userProductMapping) - { - if (userProductMapping == null) return false; +// //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; - ctx.UserProductMappings.Add(userProductMapping); +// // return existingUserProductMapping; - 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; +// //public static Product UpdateProduct(this IServiceProviderDbContext ctx, Product product) +// //{ +// // if (product == null) return null; - return existingUserProductMapping; +// // var existingProduct = ctx.Products.FirstOrDefault(u => u.Id == product.Id); +// // if (existingProduct == null) return null; - } - - public static bool CreateProduct(this IServiceProviderDbContext ctx, Product myproduct) - { - if (myproduct == null) return false; - //Automatically add assigneduser for owner - TiamServiceProvider? productOwner = ctx.ServiceProviders.FirstOrDefault(x => x.Id == myproduct.ServiceProviderId); - if(productOwner == null) return false; - var userProductMapping = new UserProductMapping(myproduct.Id, productOwner.OwnerId); - ctx.CreateAssignedUser(userProductMapping); - ctx.AddProduct(myproduct); - - return true; - } - - public static Product UpdateProduct(this IServiceProviderDbContext ctx, Product 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.ServiceProviderId = product.ServiceProviderId; - existingProduct.Description = product.Description; - existingProduct.Price = product.Price; - existingProduct.JsonDetails = product.JsonDetails; - //existingProduct.UserMediaId = product.UserMediaId; - existingProduct.ProductType = product.ProductType; +// // existingProduct.Name = product.Name; +// // existingProduct.ServiceProviderId = product.ServiceProviderId; +// // existingProduct.Description = product.Description; +// // existingProduct.Price = product.Price; +// // existingProduct.JsonDetails = product.JsonDetails; +// // //existingProduct.UserMediaId = product.UserMediaId; +// // existingProduct.ProductType = product.ProductType; - return existingProduct; - } +// // return existingProduct; +// //} - public static void DeleteProductById(this IServiceProviderDbContext ctx, Guid productId) - { - var product = ctx.Products.FirstOrDefault(u => u.Id == productId); - if (product == null) return; +// //public static void DeleteProductById(this IServiceProviderDbContext ctx, Guid productId) +// //{ +// // var product = ctx.Products.FirstOrDefault(u => u.Id == productId); +// // if (product == null) return; - ctx.CleanUpAndRemoveUserProductMappings(ctx.GetUserProductMappingsByProductId(productId)); - ctx.Products.Remove(product); - } +// // ctx.CleanUpAndRemoveUserProductMappings(ctx.GetUserProductMappingsByProductId(productId)); +// // ctx.Products.Remove(product); +// //} - public static bool CreatePermissionGroup(this IServiceProviderDbContext ctx, PermissionGroup permissionGroup) - { - if (permissionGroup == null) return false; +// //public static bool CreatePermissionGroup(this IServiceProviderDbContext ctx, PermissionGroup permissionGroup) +// //{ +// // if (permissionGroup == null) return false; - ctx.PermissionGroups.Add(permissionGroup); +// // ctx.PermissionGroups.Add(permissionGroup); - return true; - } +// // return true; +// //} - public static bool CreatePermissionContextMapping(this IServiceProviderDbContext ctx, PermissionContextMapping permissionContextMapping) - { - if (permissionContextMapping == null) return false; +// //public static bool CreatePermissionContextMapping(this IServiceProviderDbContext ctx, PermissionContextMapping permissionContextMapping) +// //{ +// // if (permissionContextMapping == null) return false; - ctx.PermissionContextMappings.Add(permissionContextMapping); +// // ctx.PermissionContextMappings.Add(permissionContextMapping); - return true; - } +// // return true; +// //} - public static bool CreatePermissionGroupUserMapping(this IServiceProviderDbContext ctx, PermissionGroupUserMapping permissionGroupUserMapping) - { - if (permissionGroupUserMapping == null) return false; +// //public static bool CreatePermissionGroupUserMapping(this IServiceProviderDbContext ctx, PermissionGroupUserMapping permissionGroupUserMapping) +// //{ +// // if (permissionGroupUserMapping == null) return false; - ctx.PermissionGroupUserMappings.Add(permissionGroupUserMapping); +// // ctx.PermissionGroupUserMappings.Add(permissionGroupUserMapping); - return true; - } +// // return true; +// //} - public static bool CreatePermissionsType(this IServiceProviderDbContext ctx, PermissionsType permissionType) - { - if (permissionType == null) return false; +// //public static bool CreatePermissionsType(this IServiceProviderDbContext ctx, PermissionsType permissionType) +// //{ +// // if (permissionType == null) return false; - ctx.PermissionsTypes.Add(permissionType); +// // 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; - } -} \ No newline at end of file +// // return true; +// //} +//} \ No newline at end of file diff --git a/TIAMMobileApp/Services/TransferDataService.cs b/TIAMMobileApp/Services/TransferDataService.cs deleted file mode 100644 index 9478a038..00000000 --- a/TIAMMobileApp/Services/TransferDataService.cs +++ /dev/null @@ -1,60 +0,0 @@ -using System.Net.Http.Json; -using TIAM.Entities.TransferDestinations; -using TIAMWebApp.Shared.Application.Interfaces; -using TIAMWebApp.Shared.Application.Models; -using TIAMWebApp.Shared.Application.Models.ClientSide; -using TIAMWebApp.Shared.Application.Models.ClientSide.UI.WizardModels; - -namespace TIAMMobileApp.Services -{ - - public class TransferDataService : ITransferDataService - { - private readonly HttpClient http; - - public TransferDataService(HttpClient http) - { - this.http = http; - } - - public async Task CreateTransferDestination(TransferDestinationWizardModel model) - { - var url = $"{Setting.BaseUrl}/{APIUrls.CreateTransferDestination}"; - var response = await http.PostAsJsonAsync(url, model); - - //var result = new WizardProcessorResult(); - - //if (response.IsSuccessStatusCode) - //{ - // result.IsSucces = true; - // result.ResultJson = await response.Content.ReadAsStringAsync(); - //} - - if (!response.IsSuccessStatusCode) - return null; - - var result = (TransferDestination)(await response.Content.ReadFromJsonAsync(typeof(TransferDestination)))!; - - return result; - } - - /// - /// calls the TransferDataAPI to get the list of destinations - public async Task GetDestinationsAsync() - { - var url = $"{Setting.BaseUrl}/{APIUrls.GetTransferDestinations}"; - return await http.GetFromJsonAsync(url); - } - - public Task GetTransferDestinationbyAddressAsync(string destinationId) - { - throw new NotImplementedException(); - } - - public async Task GetTransferDestinationbyCoordinatesAsync(string destinationId) - { - var url = $"{Setting.BaseUrl}/{APIUrls.GetTransferDestinationByCoordinates}"; - return await http.GetFromJsonAsync(url); - } - } -} diff --git a/TIAMMobileApp/TIAMMobileApp.csproj b/TIAMMobileApp/TIAMMobileApp.csproj index 36a70503..1a49aa23 100644 --- a/TIAMMobileApp/TIAMMobileApp.csproj +++ b/TIAMMobileApp/TIAMMobileApp.csproj @@ -52,6 +52,8 @@ + + diff --git a/TIAMMobileApp/wwwroot/index.html b/TIAMMobileApp/wwwroot/index.html index 703517a8..aac7bce8 100644 --- a/TIAMMobileApp/wwwroot/index.html +++ b/TIAMMobileApp/wwwroot/index.html @@ -11,11 +11,13 @@ + + @@ -32,7 +34,7 @@ - + diff --git a/TIAMResources/TIAMResources.Designer.cs b/TIAMResources/TIAMResources.Designer.cs index 2a11c46e..1d32329c 100644 --- a/TIAMResources/TIAMResources.Designer.cs +++ b/TIAMResources/TIAMResources.Designer.cs @@ -420,6 +420,15 @@ namespace TIAM.Resources { } } + /// + /// Looks up a localized string similar to Transfer destination object. + /// + public static string TransferDestination { + get { + return ResourceManager.GetString("TransferDestination", resourceCulture); + } + } + /// /// Looks up a localized string similar to New destination. /// diff --git a/TIAMResources/TIAMResources.hu.resx b/TIAMResources/TIAMResources.hu.resx index 42e71df7..47659a34 100644 --- a/TIAMResources/TIAMResources.hu.resx +++ b/TIAMResources/TIAMResources.hu.resx @@ -237,6 +237,9 @@ Müxik! + + Transzfer uticél + Új uticél diff --git a/TIAMResources/TIAMResources.resx b/TIAMResources/TIAMResources.resx index 0ab4d72a..525a9471 100644 --- a/TIAMResources/TIAMResources.resx +++ b/TIAMResources/TIAMResources.resx @@ -237,6 +237,9 @@ This works! + + Transfer destination object + New destination diff --git a/TIAMSharedUI/Pages/AppLaunch.razor b/TIAMSharedUI/Pages/AppLaunch.razor index 7baff830..8eb450d7 100644 --- a/TIAMSharedUI/Pages/AppLaunch.razor +++ b/TIAMSharedUI/Pages/AppLaunch.razor @@ -16,10 +16,25 @@ @inject HttpClient http;

AppLaunch

+@{ + if (string.IsNullOrWhiteSpace(TrackingId)) + { + TrackingId = ""; +

Loading...

+ } + else + { +

Loading with trackingId: @TrackingId

+ } +} + Loading.... @code { + [Parameter] + public string TrackingId { get; set; } + string userDetailsStr; string locale; @@ -42,7 +57,7 @@ Loading.... logToBrowserConsole = new LogToBrowserConsole(JSRuntime); //wait for 5 seconds - await Task.Delay(0001); + await Task.Delay(1000); if (!string.IsNullOrWhiteSpace(userDetailsStr)) { diff --git a/TIAMSharedUI/Pages/Components/AuthComponent.razor.cs b/TIAMSharedUI/Pages/Components/AuthComponent.razor.cs index 4cd5a498..24243fcd 100644 --- a/TIAMSharedUI/Pages/Components/AuthComponent.razor.cs +++ b/TIAMSharedUI/Pages/Components/AuthComponent.razor.cs @@ -26,12 +26,12 @@ namespace TIAMSharedUI.Pages.Components IsLoggedIn = sessionService.IsAuthenticated; await PopupMessageBox.ShowAsync("AuthComponent", "Initialized", null, null, null, PopupMessageBox.ButtonOk); - if (await PopupMessageBox.Show("Cancel", "Cancel this stuff", - PopupMessageBox.ButtonNo, PopupMessageBox.ButtonYes) == PopupMessageBox.ButtonNo) - { + //if (await PopupMessageBox.Show("Cancel", "Cancel this stuff", + //PopupMessageBox.ButtonNo, PopupMessageBox.ButtonYes) == PopupMessageBox.ButtonNo) + //{ //Something is cancelled //args.Cancel = true; - } + //} componentUpdateService.CallRequestRefresh(); StateHasChanged(); } diff --git a/TIAMSharedUI/Pages/Index.razor b/TIAMSharedUI/Pages/Index.razor index 01fe871c..60eb2bac 100644 --- a/TIAMSharedUI/Pages/Index.razor +++ b/TIAMSharedUI/Pages/Index.razor @@ -1,5 +1,6 @@ @page "/index" @using AyCode.Interfaces.StorageHandlers; +@using BlazorAnimation @using Newtonsoft.Json; @using TIAMWebApp.Shared.Application.Interfaces @using TIAMWebApp.Shared.Application.Models.ClientSide; @@ -21,58 +22,61 @@
- +

@localizer.GetString("Index.Title")

@localizer.GetString("Index.Subtitle")

-
- -
- - - -
- Card image -
- -

@localizer.GetString("Index.Transfer")

- -

@localizer.GetString("Index.Transfer.Desc")

- -
-
-
- - -
- Card image -
-

@localizer.GetString("Index.Tours")

-

@localizer.GetString("Index.Tours.Desc")

-
-
-
- -
- Card image -
-

@localizer.GetString("Index.Clubcards")

-

@localizer.GetString("Index.Clubcards.Desc")

- -
-
-
+
+ + + +
+ Card image +
+ +

@localizer.GetString("Index.Transfer")

+ +

@localizer.GetString("Index.Transfer.Desc")

+ +
+
+
+
+ + +
+ Card image +
+

@localizer.GetString("Index.Tours")

+

@localizer.GetString("Index.Tours.Desc")

+ +
+
+
+
+ + +
+ Card image +
+

@localizer.GetString("Index.Clubcards")

+

@localizer.GetString("Index.Clubcards.Desc")

+ +
+
+
+
@code { - + } diff --git a/TIAMSharedUI/Pages/User/HotelComponent.razor b/TIAMSharedUI/Pages/User/HotelComponent.razor index 4e477967..6b4ff38d 100644 --- a/TIAMSharedUI/Pages/User/HotelComponent.razor +++ b/TIAMSharedUI/Pages/User/HotelComponent.razor @@ -1,4 +1,5 @@ -@using TIAMSharedUI.Shared +@using BlazorAnimation +@using TIAMSharedUI.Shared @using TIAMWebApp.Shared.Application.Models; @using TIAMWebApp.Shared.Application.Interfaces; @using TIAMSharedUI.Pages.User; @@ -8,225 +9,273 @@
-
-
-
-
- Hotel details + +
+
+
+
+ Hotel details + +
+
+ +
+
+
+
+
+
+

Your QR code

+

Use this in printed material, to gain referrals

+
+
-
- + +
+

Hotel name: Example hotel

+

Address: Budapest, Minta u. 46

+

Phone number: +36 1 123 4567

+
+
+
-
-
-
-

Your QR code

-

Use this in printed material, to gain referrals

-
-
- -
- -
- -
-

Hotel name: Example hotel

-

Address: Budapest, Minta u. 46

-

Phone number: +36 1 123 4567

-
-
- -
+
-
-
-
-
- My orders + +
+
+
+
+ My orders + +
+ +
+
+
+
+ + + + + + @context.Value + + + + + + + + + +
-
-
All transfers
+ +
+

Some conclusion

+
+
+
-
-
+ +
+
+ +
+
+
+
+ Messagess - +
+ +
+
+
+
+ + + +
+ +

+ username + Donec id elit non mi porta gravida at eget metus... +

+
+
+ +

+ username + Donec id elit non mi porta gravida at eget metus... +

+
+
+ +

+ username + Donec id elit non mi porta gravida at eget metus... +

+
+
+ +

+ username + Donec id elit non mi porta gravida at eget metus... +

+
+ + + + +
+
+ +
+
+
+ +
+ +
+
+
+
+ Panel title +

Subtitle

+
+ +
+
+
+
+
+
Some info
+

Budapest, Dózsa György út 35, 1146

+
+
+ +
+ +
+
    +
  • + PLACED +
  • +
  • WAITING FOR PICK UP
  • +
  • + FINISHED +
  • +
+ +
+

Some conclusion

+
+
+ +
+
+
+
+ +
+
+
+
+ Affiliates +

Details

+
+ +
+
+
+ + + + - - - @context.Value - - - - - - + + + + + + + - -
+ -
-
-
-
-
-
- Hotel details - -
-
-
-
-
-
- -
-
- -
-
-
-
-
- Panel title -

Subtitle

-
- -
-
-
-
-
-
Some info
-

Budapest, Dózsa György út 35, 1146

-
-
- -
- -
-
    -
  • - PLACED -
  • -
  • WAITING FOR PICK UP
  • -
  • - FINISHED -
  • -
- -
-

Some conclusion

-
-
- -
-
-
-
-
-
-
- Affiliates -

Details

-
- -
-
-
- - - - - - - - - - - - - - - -
- -
+
diff --git a/TIAMSharedUI/Pages/User/HotelComponent.razor.cs b/TIAMSharedUI/Pages/User/HotelComponent.razor.cs index b1d9a57d..212a16ed 100644 --- a/TIAMSharedUI/Pages/User/HotelComponent.razor.cs +++ b/TIAMSharedUI/Pages/User/HotelComponent.razor.cs @@ -1,5 +1,7 @@ using Microsoft.AspNetCore.Components; +using SkiaSharp; using System; +using System.Buffers.Text; using System.Collections.Generic; using System.Linq; using System.Text; @@ -21,6 +23,9 @@ namespace TIAMSharedUI.Pages.User [Inject] IUserDataService UserDataService { get; set; } + [Inject] + IServiceProviderDataService ServiceProviderDataService { get; set; } + object? OrderData { get; set; } object? AffiliateData { get; set; } @@ -29,6 +34,8 @@ namespace TIAMSharedUI.Pages.User bool isUserLoggedIn; int userType = 0; + public string ImageSource { get; set; } = ""; + @@ -98,6 +105,9 @@ namespace TIAMSharedUI.Pages.User Phone = s.Phone }; }); + + //SKBitmap bitmap = await ServiceProviderDataService.GetQRCodeByProductIdAsync(Guid.NewGuid()); + ImageSource = await ServiceProviderDataService.GetQRCodeByProductIdAsync(Guid.NewGuid()); } [Parameter] public bool ShowSeriesPointMarkers { get; set; } [Parameter] public bool ShowSeriesLabels { get; set; } diff --git a/TIAMSharedUI/Pages/User/Messages.razor b/TIAMSharedUI/Pages/User/Messages.razor new file mode 100644 index 00000000..e208054c --- /dev/null +++ b/TIAMSharedUI/Pages/User/Messages.razor @@ -0,0 +1,44 @@ +
+
+ + + +
+ +

+ username + Donec id elit non mi porta gravida at eget metus... +

+
+
+ +

+ username + Donec id elit non mi porta gravida at eget metus... +

+
+
+ +

+ username + Donec id elit non mi porta gravida at eget metus... +

+
+
+ +

+ username + Donec id elit non mi porta gravida at eget metus... +

+
+ + + + +
+
+ + +@code { + +} diff --git a/TIAMSharedUI/Pages/User/Messages.razor.cs b/TIAMSharedUI/Pages/User/Messages.razor.cs new file mode 100644 index 00000000..860f7381 --- /dev/null +++ b/TIAMSharedUI/Pages/User/Messages.razor.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TIAMSharedUI.Pages.User +{ + public partial class Messages + { + } +} diff --git a/TIAMSharedUI/Pages/User/Profile.razor b/TIAMSharedUI/Pages/User/Profile.razor new file mode 100644 index 00000000..3e3be258 --- /dev/null +++ b/TIAMSharedUI/Pages/User/Profile.razor @@ -0,0 +1,16 @@ +@page "/user/profile" + +
+

Profile

+

Have a nice day!

+
+ +
+ + + +
+ +@code { + +} diff --git a/TIAMSharedUI/Pages/User/ProfileComponent.razor b/TIAMSharedUI/Pages/User/ProfileComponent.razor index b7d6d303..fe43ef5a 100644 --- a/TIAMSharedUI/Pages/User/ProfileComponent.razor +++ b/TIAMSharedUI/Pages/User/ProfileComponent.razor @@ -1,4 +1,171 @@ -

ProfileComponent

+ + + +
+
+
+
+ +
+
+
+ +
+
+
+
+
+
+
+
+
+
+ 140x140 +
+
+
+
+
+

John Smith

+

johnny.s

+
Last seen 2 hours ago
+
+ +
+
+
+ administrator +
Joined 09 Dec 2017
+
+
+
+ +
+
+
+
+
+
+
+
+ + +
+
+
+
+ + +
+
+
+
+
+
+ + +
+
+
+
+
+
+ + +
+
+
+
+
+
+
+
Change Password
+
+
+
+ + +
+
+
+
+
+
+ + +
+
+
+
+
+
+ + +
+
+
+
+
+
Keeping in Touch
+
+
+ +
+
+ + +
+
+ + +
+
+ + +
+
+
+
+
+
+
+
+ +
+
+
+ +
+
+
+
+
+
+ +
+ +
+
+
Support
+

Get fast, free help from our friendly assistants.

+ +
+
+
+
+ +
+
+ @code { diff --git a/TIAMSharedUI/Pages/User/TransferDestinations.razor b/TIAMSharedUI/Pages/User/TransferDestinations.razor new file mode 100644 index 00000000..986a50fa --- /dev/null +++ b/TIAMSharedUI/Pages/User/TransferDestinations.razor @@ -0,0 +1,104 @@ +@page "/user/destinations" +@using AyCode.Models.Messages +@using TIAM.Entities.ServiceProviders +@using TIAM.Resources +@using TIAMSharedUI.Pages.Components +@using TIAMSharedUI.Shared +@using TIAMWebApp.Shared.Application.Models +@using TIAMWebApp.Shared.Application.Models.ClientSide.UI.WizardModels +@using TIAMWebApp.Shared.Application.Models.ClientSide.Messages +@using TIAMWebApp.Shared.Application.Utility +@layout AdminLayout +@inject LogToBrowserConsole logToBrowserConsole +@inject IStringLocalizer localizer +Transfers + +
+

Destination management

+

Manage transfers here!

+
+ +
+
+
+

@localizer.GetString("TransferDestination")

+ + +
+
+ +
+ + + + + + + + @{ + var keyField = context.Value; + @context.Value + } + + + + + + + + + + + @{ + var transfer = (TransferDestinationWizardModel)EditFormContext.EditModel; + } + + + @EditFormContext.GetEditor("Name") + + + @EditFormContext.GetEditor("Destination") + + + @EditFormContext.GetEditor("AddressString") + + + @EditFormContext.GetEditor("Price") + + + + + + + + +
+ +
+ +
+
+ +
+
+ + +@code { + + +} diff --git a/TIAMSharedUI/Pages/User/TransferDestinations.razor.cs b/TIAMSharedUI/Pages/User/TransferDestinations.razor.cs new file mode 100644 index 00000000..09afd052 --- /dev/null +++ b/TIAMSharedUI/Pages/User/TransferDestinations.razor.cs @@ -0,0 +1,174 @@ +using DevExpress.Blazor; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using TIAMWebApp.Shared.Application.Models.ClientSide.UI.WizardModels; +using TIAMWebApp.Shared.Application.Models; +using TIAMWebApp.Shared.Application.Interfaces; +using Microsoft.AspNetCore.Components; +using TIAM.Entities.TransferDestinations; + +namespace TIAMSharedUI.Pages.User +{ + public partial class TransferDestinations + { + + IGrid Grid { get; set; } + //object? TransferData { get; set; } + + public TransferDestinationWizardModel myModel = new TransferDestinationWizardModel(); + + bool PopupVisible { get; set; } + public List ignoreList = new List + { + "ReceiverId" + }; + + public MessageWizardModel messageWizardModel = new MessageWizardModel(); + + [Inject] + public ITransferDataService transferDataService { get; set; } + + + object? TransferData = new TransferDestinationWizardModel[] + { + new TransferDestinationWizardModel(Guid.NewGuid(), "Liszt Ferenc Airport", "International airport of Budapest", "1185, Budapest, Liszt Ferenc Repülőtér" ), + new TransferDestinationWizardModel(Guid.NewGuid(), "Buda Castle", "Historical site in the heart of Budapest", "1014 Budapest, Szent György tér 2" ), + new TransferDestinationWizardModel(Guid.NewGuid(), "Hungarian National Museum", "Historical site in the heart of Budapest", "1088 Budapest, Múzeum krt. 14-16" ), + new TransferDestinationWizardModel(Guid.NewGuid(), "Parliament of Hungary", "Historical site in the heart of Budapest", "1055 Budapest, Kossuth Lajos tér 1-3" ), + new TransferDestinationWizardModel(Guid.NewGuid(), "Heroes square", "Historical site in the heart of Budapest", "1146 Budapest, Hősök tere" ), + new TransferDestinationWizardModel(Guid.NewGuid(), "Gellert Hill", "Historical site in the heart of Budapest", "1118 Budapest, Gellérthegy" ), + new TransferDestinationWizardModel(Guid.NewGuid(), "Margaret Island", "Historical site in the heart of Budapest", "1138 Budapest, Margitsziget" ), + }; + + object? TransferDataFromDb = new TransferDestinationWizardModel[] { }; + + void CancelCreateClick() + { + + + PopupVisible = false; + } + void EulaPopupClosed() + { + //cancel clicked + + } + void EulaPopupClosing(PopupClosingEventArgs args) + { + //myModel = new TransferWizardModel(); + messageWizardModel = new MessageWizardModel(); + } + + //----------------------------------------------------------------------------------- + + + public async Task SubmitForm(object Result) + { + //await WizardProcessor.ProcessWizardAsync(Result.GetType(), Result); + logToBrowserConsole.LogToBC($"Submitted nested form: {Result.GetType().FullName}"); + } + + + protected override async Task OnAfterRenderAsync(bool firstRender) + { + //if (firstRender) + // await Grid.StartEditRowAsync(0); + } + + void Grid_CustomizeEditModel(GridCustomizeEditModelEventArgs e) + { + if (e.IsNew) + { + var newDestination = (TransferDestinationWizardModel)e.EditModel; + newDestination.Id = Guid.NewGuid().ToString(); + newDestination.Name = "ghjgkg hkgh ghjkghgkjgh"; + newDestination.Description = "ghjgkg hkgh ghjkghgkjgh"; + newDestination.AddressString = "ghjgkg hkgh ghjkghgkjgh"; + + + } + } + + void Grid_CustomizeElement(GridCustomizeElementEventArgs e) + { + + } + + async Task Grid_EditModelSaving(GridEditModelSavingEventArgs e) + { + if (e.IsNew) + { + //add new row to grid + myModel = (TransferDestinationWizardModel)e.EditModel; + //add mymodel to transferData array + TransferData = ((TransferDestinationWizardModel[])TransferData).Append(myModel); + + //add new orderData to orderData array + logToBrowserConsole.LogToBC("New orderData added"); + //await NwindDataService.InsertEmployeeAsync((EditableEmployee)e.EditModel); + + } + else + { + logToBrowserConsole.LogToBC("orderData updated"); + //modify transferData where transferData.Id == e.EditModel.Id + //get transfer from TransferData by Id + + foreach (var transferToModify in (TransferDestinationWizardModel[])TransferData) + { + myModel = (TransferDestinationWizardModel)e.EditModel; + + if (transferToModify.Id == myModel.Id) + { + myModel = (TransferDestinationWizardModel)e.EditModel; + transferToModify.Name = myModel.Name; + transferToModify.Description = myModel.Description; + transferToModify.AddressString = myModel.AddressString; + transferToModify.Price = myModel.Price; + } + } + + } + + //await NwindDataService.UpdateEmployeeAsync((EditableEmployee)e.DataItem, (EditableEmployee)e.EditModel); + + await UpdateDataAsync(); + } + async Task Grid_DataItemDeleting(GridDataItemDeletingEventArgs e) + { + //await NwindDataService.RemoveEmployeeAsync((EditableEmployee)e.DataItem); + //remove orderData from orderData array + logToBrowserConsole.LogToBC("orderData deleted"); + //await UpdateDataAsync(); + } + async Task UpdateDataAsync() + { + //DataSource = await NwindDataService.GetEmployeesEditableAsync(); + //refresh grid + logToBrowserConsole.LogToBC("orderData grid refreshed"); + } + + protected override async Task OnInitializedAsync() + { + base.OnInitialized(); + var a = await transferDataService.GetDestinationsAsync(); + logToBrowserConsole.LogToBC($"TransferDataFromDb: {((TransferDestinationWizardModel[])TransferDataFromDb).Length}"); + foreach (var item in a) + { + //add new transferwizardmodel to transferData array + TransferDataFromDb = ((TransferDestinationWizardModel[])TransferDataFromDb).Append( + new TransferDestinationWizardModel(Guid.NewGuid(), item.Name, item.Description, item.AddressString)); + logToBrowserConsole.LogToBC($"TransferDataFromDb: {item.Name}"); + } + } + + void ColumnChooserButton_Click() + { + Grid.ShowColumnChooser(); + } + + } +} diff --git a/TIAMSharedUI/Shared/HeroSlider.razor b/TIAMSharedUI/Shared/HeroSlider.razor index 4fe7ba0e..e3d1b3bb 100644 --- a/TIAMSharedUI/Shared/HeroSlider.razor +++ b/TIAMSharedUI/Shared/HeroSlider.razor @@ -1,5 +1,6 @@ -
- +@using BlazorAnimation +
+ - +