diff --git a/TIAM.Database/DataLayers/Admins/AdminDal.cs b/TIAM.Database/DataLayers/Admins/AdminDal.cs index 68cc0bf6..fdac07ce 100644 --- a/TIAM.Database/DataLayers/Admins/AdminDal.cs +++ b/TIAM.Database/DataLayers/Admins/AdminDal.cs @@ -39,9 +39,18 @@ namespace TIAM.Database.DataLayers.Users public Task UpdateUserAsync(User user) { - user.Modified = DateTime.UtcNow; - Ctx.Users.Update(user); - return Ctx.SaveChangesAsync().ContinueWith(x=>x.Result > 0); + var existingUser = Ctx.Users.FirstOrDefault(u => u.Email == user.Email); + 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; + Ctx.Users.Update(existingUser); + return Ctx.SaveChangesAsync().ContinueWith(x => x.Result > 0); + } + else + { + throw new Exception("User not found"); + } } } } diff --git a/TIAM.Database/DataLayers/ServiceProviders/ServiceProviderDal.cs b/TIAM.Database/DataLayers/ServiceProviders/ServiceProviderDal.cs new file mode 100644 index 00000000..9ffd4a15 --- /dev/null +++ b/TIAM.Database/DataLayers/ServiceProviders/ServiceProviderDal.cs @@ -0,0 +1,588 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using AyCode.Models.Enums; +using Microsoft.EntityFrameworkCore; +using TIAM.Database.DbContexts; +using TIAM.Entities.Permissions; +using TIAM.Entities.Products; +using TIAM.Entities.ServiceProviders; +using TIAM.Entities.Products.DTOs; +using TIAM.Entities.Users; + + +namespace TIAM.Database.DataLayers.ServiceProviders +{ + public class ServiceProviderDal : TiamDalBase + { + + public ServiceProviderDal() : base() + { + } + + public ServiceProviderDal(ServiceProviderDbContext _object) + { + } + + #region ServiceProviders + + //16. (IServiceProviderDataService) get all service providers + public Task> GetServiceProvidersAsync() + { + return Ctx.ServiceProviders.ToListAsync(); + } + + //18. (IServiceProviderDataService) get serviceProvider by Id + public virtual Task GetServiceProviderByIdAsync(Guid id) + { + Console.WriteLine($"Getting serviceProvider from db {id}"); + return Ctx.ServiceProviders.SingleOrDefaultAsync(x=>x.Id == id); + } + + //15. (IServiceProviderDataService) Create service provider + public Task CreateServiceProviderAsync(TiamServiceProvider serviceProvider) + { + if(serviceProvider.Name == Ctx.ServiceProviders.FirstOrDefault(x=>x.Name == serviceProvider.Name)?.Name) + { + throw new Exception("ServiceProvider already exists"); + } + else + { + + Ctx.ServiceProviders.Add(serviceProvider); + Console.WriteLine($"Saving serviceProvider to db {serviceProvider.Id}, {serviceProvider.Name}, {serviceProvider.OwnerId}"); + return Ctx.SaveChangesAsync().ContinueWith(x=>x.Result > 0); + + } + } + + //14. (IserviceProviderDataService) Update service provider + public Task UpdateServiceProviderAsync(TiamServiceProvider serviceProvider) + { + var dbServiceProvider = Ctx.ServiceProviders.FirstOrDefault(u => u.Id == serviceProvider.Id); + if (dbServiceProvider != null) + { + dbServiceProvider = serviceProvider; + Ctx.ServiceProviders.Update(dbServiceProvider); + return Ctx.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 = Ctx.Database.BeginTransaction()) + { + var dbServiceProvider = Ctx.ServiceProviders.FirstOrDefault(u => u.Id == id); + if (dbServiceProvider != null) + { + //get products for this provider + var products = Ctx.Products.Where(x => x.OwnerId == id).ToList(); + + /*foreach (var productItem in products) + { + //delete products + var permissionContextMappings = Ctx.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 = Ctx.PermissionGroupUserMappings.Where(x => x.PermissionContextMappingId == item.Id).ToList(); + //remove every row (users) from permissiongroup + foreach (var user in permissionGroupUserMapping) + { + Ctx.PermissionGroupUserMappings.Remove(user); + } + } + } + //remove permissioncontextmappings + Ctx.PermissionContextMappings.RemoveRange(permissionContextMappings); + }*/ + Ctx.Products.RemoveRange(products); + Ctx.ServiceProviders.Remove(dbServiceProvider); + return Ctx.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 = Ctx.Database.BeginTransaction()) + { + var existingPermission = Ctx.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 = Ctx.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; + Ctx.PermissionsTypes.Add(permissionsType); + Ctx.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 Ctx.PermissionsTypes.Where(x => x.ContextId == contextId).ToListAsync(); + } + + public Task GetPermissionFromPermissionType(PermissionsType pType) + { + if(Ctx.PermissionsTypes.FirstOrDefault(x=>x.Id == pType.Id) != null) + { + return Task.FromResult(pType.PermissionBit); + } + else + { + return Task.FromResult(0); + } + } + + #endregion + + #region PermissionMappings + + //2. get the contexts where the user has permission + public async Task> GetPermissionContextByUserIdAsync(Guid UserId) + { + List _permissions = new List(); + //get all assignedUsers + List assignedUsers = await Ctx.AssignedUsers.Where(x => x.EmployeeUserId == UserId).ToListAsync(); + //List _permissionContextMappings = new List(); + List _permissionGroupUserMappings = new List(); + //get contexts where the user has permission + foreach (var item in assignedUsers) + { + //get the product where the permissioncontextmapping is + var contextMapping = await Ctx.PermissionContextMappings.FirstOrDefaultAsync(x => x.SubjectId == item.Id); + if (contextMapping != null) + { + _permissions.Add(new AssignedPermissionModel(item.ContextId, item.Id, (short)PermissionContextMappingSubjectType.User, item.Id.ToString(), contextMapping.Permissions)); + } + //get permissiongroupusermappings where the user is in the group + _permissionGroupUserMappings = await Ctx.PermissionGroupUserMappings.Where(x => x.AssignedUserId == item.Id).ToListAsync(); + + foreach (var groupUserMapping in _permissionGroupUserMappings) + { + //get the permissioncontextmapping where the permissiongroup is + var contextMapping2 = await Ctx.PermissionContextMappings.FirstOrDefaultAsync(x => x.Id == groupUserMapping.PermissionContextMappingId); + if (contextMapping2 != null) + { + + //get the group so we have the contextId + var group = await Ctx.PermissionGroups.FirstOrDefaultAsync(x => x.Id == contextMapping2.SubjectId); + + _permissions.Add(new AssignedPermissionModel(group.ContextId, contextMapping2.SubjectId, (short)PermissionContextMappingSubjectType.Group, group.GroupName, contextMapping2.Permissions)); + } + } + + } + + return _permissions; + } + + //3. (IPermissionService) get permissions of assigned users and groups + public Task> GetPermissionsOfAssignedUsersAndGroupsAsyncByContextId(Guid contextId) + { + List result = new List(); + + var AssignedUsers = Ctx.AssignedUsers.Where(x => x.ContextId == contextId).ToListAsync(); + + if (AssignedUsers.Result != null) + { + foreach (var item in AssignedUsers.Result) + { + var mappingRow = Ctx.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.ContextId, item.Id, mapping.SubjectType, item.EmployeeUserId.ToString(), mapping.Permissions)); + } + } + + } + } + + var AssingedGroups = Ctx.PermissionGroups.Where(x => x.ContextId == contextId).ToListAsync(); + + if (AssingedGroups.Result != null) + { + foreach (var group in AssingedGroups.Result) + { + var mappingRow = Ctx.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.ContextId, group.Id, mapping.SubjectType, group.GroupName, mapping.Permissions)); + } + } + + } + } + foreach (var row in result) + { + Console.WriteLine($"GetPermissionsOfAssignedUsersAndGroupsAsyncByContextId: {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 = Ctx.PermissionGroups.Where(x => x.ContextId == contextId).ToListAsync(); + foreach (var item in groups.Result) + { + //get permissioncontextmapping for the group if there is, so we know what permissions the group has + var pCm = Ctx.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 = Ctx.Database.BeginTransaction()) + { + //do we need to check if PermissionContextMappingId exists? + var permissionGroupUserMapping = new PermissionGroupUserMapping(userId, permissionGroupId); + Ctx.PermissionGroupUserMappings.Add(permissionGroupUserMapping); + Ctx.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 = Ctx.Database.BeginTransaction()) + { + var existingPermissionGroup = Ctx.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"); + Ctx.PermissionsTypes.Add(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, (short)PermissionContextMappingSubjectType.Group, 1, true); + Ctx.PermissionContextMappings.Add(permissionContextMapping); + Ctx.PermissionGroups.Add(permissionGroup); + Ctx.SaveChanges(); + transaction.Commit(); + result = true; + } + else + { + //group with same name already exists + result = false; + } + } + return Task.FromResult(result); + } + + public Task> GetAssingedUsersInPermissionGroupByGroupId(Guid groupId) + { + List assignedUsers = new List(); + + //let's get the permissioncontextmapping for the group + var pCm = Ctx.PermissionContextMappings.FirstOrDefault(x => x.SubjectId == groupId); + Guid pCmId = pCm.Id; + + //let's get the permissiongroupusermappings for the permissioncontextmapping + var pGum = Ctx.PermissionGroupUserMappings.Where(x => x.PermissionContextMappingId == pCmId).ToList(); + if (pGum.Count > 0) + { + foreach (var group in pGum) + { + assignedUsers.Add(Ctx.AssignedUsers.FirstOrDefault(x => x.Id == group.AssignedUserId)); + } + + } + + return Task.FromResult(assignedUsers); + } + + #endregion + + #region Products + + //19. (IServiceProviderDataService) Create product + public Task CreateProductAsync(TiamProduct product) + { + + + + Ctx.Products.Add(product); + Console.WriteLine($"Saving product to db {product.Id}, {product.Name}, {product.OwnerId}"); + return Ctx.SaveChangesAsync().ContinueWith(x => x.Result > 0); + + } + + //20. (IServiceProviderDataService) Update product + public Task UpdateProductAsync(TiamProduct product) + { + var dbProduct = Ctx.Products.FirstOrDefault(u => u.Id == product.Id); + if (dbProduct != null) + { + dbProduct = product; + Ctx.Products.Update(dbProduct); + return Ctx.SaveChangesAsync().ContinueWith(x => x.Result > 0); + } + else + { + throw new Exception("Product not found"); + } + } + + //21. (IServiceProviderDataService) delete product + public Task DeleteProductAsync(Guid id) + { + using (var transaction = Ctx.Database.BeginTransaction()) + { + var dbProduct = Ctx.Products.FirstOrDefault(u => u.Id == id); + if (dbProduct != null) + { + //get assignedUsers for this product + var assignedUsers = Ctx.AssignedUsers.Where(x => x.ContextId == id).ToList(); + //remove assignedUsers + foreach (var item in assignedUsers) + { + RemoveAssignedUserByUserId(item.Id); + } + return Ctx.SaveChangesAsync().ContinueWith(x => x.Result > 0); + } + else + { + return Task.FromResult(false); + } + } + } + + //4. (IPermissionService) AssignPermissionToUserForContextAsync + public Task AssignPermissionToUserForContextAsync(AssignedUser assignedUser, PermissionsType permission) + { + var _assIgnedUser = Ctx.AssignedUsers.FirstOrDefault(x => x.Id == assignedUser.Id); + + if(_assIgnedUser != null) + { + //user exists + var _permissionInt = GetPermissionFromPermissionType(permission); + + var permissionContextMapping = Ctx.PermissionContextMappings.FirstOrDefault(x => x.SubjectId == assignedUser.Id); + var currentPermissions = permissionContextMapping.Permissions; + var newPermissions = currentPermissions + _permissionInt.Result; + permissionContextMapping.Permissions = newPermissions; + return Ctx.SaveChangesAsync().ContinueWith(x => x.Result > 0); + } + else + { + //user does not exist, let's create it + return Task.FromResult(false); + } + } + + #endregion + + + #region AssignedUsers + + //22. (IServiceProviderDataService) Create assignedUser + public Task CreateAssignedUserAsync(AssignedUser assignedUser) + { + Ctx.AssignedUsers.Add(assignedUser); + Console.WriteLine($"Saving assignedUser to db {assignedUser.Id}, {assignedUser.ContextId}, {assignedUser.EmployeeUserId}, {assignedUser.UserRoles}"); + return Ctx.SaveChangesAsync().ContinueWith(x => assignedUser); + } + + //23. (IServiceProviderDataService) Get Assigned Users By ProductId + public Task> GetAssignedUsersByProductIdAsync(Guid productId) + { + return Ctx.AssignedUsers.Where(x => x.ContextId == productId).ToListAsync(); + } + + + //24 . (IServiceProviderDataService) Remove Assigned Users By Product Id + public Task RemoveAssignedUsersByContextId(Guid contextId) + { + using (var transaction = Ctx.Database.BeginTransaction()) + { + var assignedUsers = Ctx.AssignedUsers.Where(x => x.ContextId == contextId).ToList(); + //remove assignedUsers + + return Ctx.SaveChangesAsync().ContinueWith(x => x.Result > 0); + + } + } + + //25. (IServiceProviderDataService) Remove Assigned from product by AssignedUserId + public Task RemoveAssignedUser(AssignedUser assignedUser, bool removeFromGroups) + { + using (var transaction = Ctx.Database.BeginTransaction()) + { + var assignedUserToRemove = Ctx.AssignedUsers.FirstOrDefault(x => x.Id == assignedUser.Id); + //remove assignedUsers + if (assignedUserToRemove != null) + { + if(removeFromGroups) + { + //remove permissiongroupusermappings + RemoveAssingedUserFromAllProductPermissionGroups(assignedUserToRemove.Id); + } + Ctx.AssignedUsers.Remove(assignedUserToRemove); + } + return Ctx.SaveChangesAsync().ContinueWith(x => x.Result > 0); + + } + } + + public Task RemoveAssignedUserByUserId(Guid assignedUserId) + { + + using (var transaction = Ctx.Database.BeginTransaction()) + { + var assignedUser = Ctx.AssignedUsers.FirstOrDefault(x => x.Id == assignedUserId); + //remove assignedUsers + if (assignedUser != null) + { + //CleanUp + //remove permissioncontextmappings + RemoveAssignedUserContextMappingByAssignedUserId(assignedUserId); + //remove permissiongroupusermappings + RemoveAssingedUserFromAllProductPermissionGroups(assignedUserId); + + } + return Ctx.SaveChangesAsync().ContinueWith(x => x.Result > 0); + + } + } + + public Task RemoveAssignedUserContextMappingByAssignedUserId(Guid AssignedUserId) + { + using (var transaction = Ctx.Database.BeginTransaction()) + { + PermissionContextMapping? contextMapping = Ctx.PermissionContextMappings.FirstOrDefault(x => x.SubjectId == AssignedUserId); + //remove assignedUsers + if(contextMapping != null) + { + Ctx.PermissionContextMappings.Remove(contextMapping); + } + return Ctx.SaveChangesAsync().ContinueWith(x => x.Result > 0); + + } + } + + + public Task RemoveAssingedUserFromAllProductPermissionGroups(Guid assignedUserId) + { + using (var transaction = Ctx.Database.BeginTransaction()) + { + var permissionGroupUserMapping = Ctx.PermissionGroupUserMappings.Where(x => x.AssignedUserId == assignedUserId); + //remove assignedUsers + + if (permissionGroupUserMapping != null) + { + foreach (var item in permissionGroupUserMapping) + { + Ctx.PermissionGroupUserMappings.Remove(item); + } + } + return Ctx.SaveChangesAsync().ContinueWith(x => x.Result > 0); + + } + } + + + #endregion + + } +} diff --git a/TIAM.Database/DataLayers/TransferDestinations/TransferDestinationDal.cs b/TIAM.Database/DataLayers/TransferDestinations/TransferDestinationDal.cs index effc716e..1d235a94 100644 --- a/TIAM.Database/DataLayers/TransferDestinations/TransferDestinationDal.cs +++ b/TIAM.Database/DataLayers/TransferDestinations/TransferDestinationDal.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using AyCode.Database; +using Microsoft.EntityFrameworkCore; using Microsoft.Identity.Client; using TIAM.Database.DbContexts; using TIAM.Entities.TransferDestinations; @@ -19,9 +20,23 @@ public class TransferDestinationDal : TiamDalBase public Task CreateTransferDestinationAsync(TransferDestination transferDestination) { - transferDestination.Created = DateTime.UtcNow; - transferDestination.Modified = DateTime.UtcNow; + //transferDestination.Created = DateTime.UtcNow; + //transferDestination.Modified = DateTime.UtcNow; Ctx.TransferDestinations.Add(transferDestination); return Ctx.SaveChangesAsync().ContinueWith(x => x.Result > 0); } + + public Task UpdateTransferDestinationAsync(TransferDestination transferDestination) + { + //transferDestination.Modified = DateTime.UtcNow; + Ctx.TransferDestinations.Update(transferDestination); + return Ctx.SaveChangesAsync().ContinueWith(x => x.Result > 0); + } + + public Task> GetTransferDestinations() + { + + return Ctx.TransferDestinations.ToListAsync(); + + } } \ No newline at end of file diff --git a/TIAM.Database/DbContexts/ServiceProviderDbContext.cs b/TIAM.Database/DbContexts/ServiceProviderDbContext.cs new file mode 100644 index 00000000..d6659e8c --- /dev/null +++ b/TIAM.Database/DbContexts/ServiceProviderDbContext.cs @@ -0,0 +1,50 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using AyCode.Database.DbContexts; +using Microsoft.EntityFrameworkCore; +using TIAM.Entities.Permissions; +using TIAM.Entities.Products; +using TIAM.Entities.ServiceProviders; +using TIAM.Entities.Users; + +namespace TIAM.Database.DbContexts +{ + public class ServiceProviderDbContext : TiamDbContextBase + { + public virtual DbSet ServiceProviders { get; set; } + public virtual DbSet Products { get; set; } + public virtual DbSet AssignedUsers { get; set; } + public virtual DbSet PermissionsTypes { get; set; } + public virtual DbSet PermissionGroups { get; set; } + public virtual DbSet PermissionGroupUserMappings { get; set; } + public virtual DbSet PermissionContextMappings { get; set; } + + public ServiceProviderDbContext() //: this(string.Empty) + { + + } + + public ServiceProviderDbContext(DbContextOptions options) //: this(string.Empty) + { + + } + + public ServiceProviderDbContext(string name) : base(name) + { + } + + public ServiceProviderDbContext(DbContextOptions options, string name) : base(options, name) + { + } + + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) + { + optionsBuilder.EnableDetailedErrors(true); + base.OnConfiguring(optionsBuilder); + } + + } +} diff --git a/TIAM.Database/DbContexts/UserDbContext.cs b/TIAM.Database/DbContexts/UserDbContext.cs index 68bd96b4..10114688 100644 --- a/TIAM.Database/DbContexts/UserDbContext.cs +++ b/TIAM.Database/DbContexts/UserDbContext.cs @@ -5,14 +5,14 @@ using System.Text; using System.Threading.Tasks; using AyCode.Database.DbContexts; using Microsoft.EntityFrameworkCore; -using TIAM.Entities.TransferDestinations; +using TIAM.Entities.Permissions; using TIAM.Entities.Users; namespace TIAM.Database.DbContexts { public class UserDbContext : TiamDbContextBase { - public virtual DbSet Users { get; set; } + public virtual DbSet Users { get; set; } public UserDbContext() //: this(string.Empty) { diff --git a/TIAM.Database/TIAM.Database.csproj b/TIAM.Database/TIAM.Database.csproj index 7f7e3735..ebe8d421 100644 --- a/TIAM.Database/TIAM.Database.csproj +++ b/TIAM.Database/TIAM.Database.csproj @@ -13,6 +13,7 @@ + diff --git a/TIAM.Entities/Groups/Group.cs b/TIAM.Entities/Groups/Group.cs new file mode 100644 index 00000000..a7071b6d --- /dev/null +++ b/TIAM.Entities/Groups/Group.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using AyCode.Entities.Groups; + +namespace TIAM.Entities.Groups +{ + public class Group : GroupBase + { + public Group() { } + public Group(bool isPublic) : this(Guid.NewGuid(), isPublic) { } + public Group(Guid id, bool isPublic) : base(id, isPublic) + { } + + } +} diff --git a/TIAM.Entities/Permissions/PermissionContextMapping.cs b/TIAM.Entities/Permissions/PermissionContextMapping.cs index 51ad39ac..ccddb74c 100644 --- a/TIAM.Entities/Permissions/PermissionContextMapping.cs +++ b/TIAM.Entities/Permissions/PermissionContextMapping.cs @@ -9,14 +9,23 @@ namespace TIAM.Entities.Permissions; public class PermissionContextMapping : IEntityGuid, ITimeStampInfo { [Key, DatabaseGenerated(DatabaseGeneratedOption.None)] - public Guid Id { get; set; } - public Guid ContextId { get; set; } - public Guid SubjectId { get; set; } + public Guid Id { get; set; } + public Guid SubjectId { get; set; } //group or user - public short SubjectType { get; set; } + public short SubjectType { get; set; } //1 for user, 2 for group public int Permissions { get; set; } public bool IsBuiltin { get; set; } public DateTime Created { get; set; } public DateTime Modified { get; set; } + + public PermissionContextMapping(Guid subjectId, short subjectType, int permissions, bool isBuiltin) : this(Guid.NewGuid(), subjectId, subjectType, permissions, isBuiltin) { } + public PermissionContextMapping(Guid id, Guid subjectId, short subjectType, int permissions, bool isBuiltin) + { + Id = id; + SubjectId = subjectId; + SubjectType = subjectType; + Permissions = permissions; + IsBuiltin = isBuiltin; + } } \ No newline at end of file diff --git a/TIAM.Entities/Permissions/PermissionGroup.cs b/TIAM.Entities/Permissions/PermissionGroup.cs index c4724737..7f46fdb4 100644 --- a/TIAM.Entities/Permissions/PermissionGroup.cs +++ b/TIAM.Entities/Permissions/PermissionGroup.cs @@ -1,19 +1,30 @@ using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; +using AyCode.Entities.Groups; using AyCode.Interfaces.Entities; using AyCode.Interfaces.TimeStampInfo; +using TIAM.Entities.Groups; namespace TIAM.Entities.Permissions; [Table("PermissionGroups")] -public class PermissionGroup : IEntityGuid, ITimeStampInfo +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) + { + Id = id; + ContextId = contextId; + IsPublic = isPublic; + GroupName = groupName; + IsBuiltin = isBuiltin; + } + [Key, DatabaseGenerated(DatabaseGeneratedOption.None)] public Guid Id { get; set; } - - string GroupName { get; set; } - bool IsBuiltin { get; set; } - - public DateTime Created { get; set; } - public DateTime Modified { get; set; } + public Guid ContextId { get; set; } + public bool IsPublic { get; set; } + public string? GroupName { get; set; } + public bool IsBuiltin { get; set; } } \ No newline at end of file diff --git a/TIAM.Entities/Permissions/PermissionGroupUserMapping.cs b/TIAM.Entities/Permissions/PermissionGroupUserMapping.cs index c0bd4dbc..bb9edbd7 100644 --- a/TIAM.Entities/Permissions/PermissionGroupUserMapping.cs +++ b/TIAM.Entities/Permissions/PermissionGroupUserMapping.cs @@ -10,9 +10,20 @@ public class PermissionGroupUserMapping : IEntityGuid, ITimeStampInfo { [Key, DatabaseGenerated(DatabaseGeneratedOption.None)] public Guid Id { get; set; } - public Guid UserId { get; set; } + public Guid AssignedUserId { get; set; } public Guid PermissionContextMappingId { get; set; } public DateTime Created { get; set; } public DateTime Modified { get; set; } + + public PermissionGroupUserMapping(Guid assignedUserId, Guid permissionContectMappingId) : this (Guid.NewGuid(), assignedUserId, permissionContectMappingId) + { } + + public PermissionGroupUserMapping(Guid id, Guid assignedUserId, Guid permissionContectMappingId) + { + Id = id; + AssignedUserId = assignedUserId; + PermissionContextMappingId = permissionContectMappingId; + } + } \ No newline at end of file diff --git a/TIAM.Entities/Permissions/PermissionGroup_Old.cs b/TIAM.Entities/Permissions/PermissionGroup_Old.cs new file mode 100644 index 00000000..ef40e449 --- /dev/null +++ b/TIAM.Entities/Permissions/PermissionGroup_Old.cs @@ -0,0 +1,20 @@ +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using AyCode.Interfaces.Entities; +using AyCode.Interfaces.TimeStampInfo; + +namespace TIAM.Entities.Permissions; + +//[Table("PermissionGroups")] +public class PermissionGroup_Old : IEntityGuid, ITimeStampInfo +{ + [Key, DatabaseGenerated(DatabaseGeneratedOption.None)] + public Guid Id { get; set; } + public Guid ContextId { get; set; } //Kell egy ownerID (ami itt contextId), mert különben létrehozás után nem tudjuk kié a csoport + + string? GroupName { get; set; } + bool IsBuiltin { get; set; } + + public DateTime Created { get; set; } + public DateTime Modified { get; set; } +} \ No newline at end of file diff --git a/TIAM.Entities/Permissions/PermissionsType.cs b/TIAM.Entities/Permissions/PermissionsType.cs index 6742b048..3971a6a2 100644 --- a/TIAM.Entities/Permissions/PermissionsType.cs +++ b/TIAM.Entities/Permissions/PermissionsType.cs @@ -18,4 +18,12 @@ public class PermissionsType : IEntityGuid, ITimeStampInfo public DateTime Created { get; set; } public DateTime Modified { get; set; } + + public PermissionsType(Guid contextId, string permissionName) : this(Guid.NewGuid(), contextId, permissionName) { } + public PermissionsType(Guid id, Guid contextId, string permissionName) + { + Id = Guid.NewGuid(); + ContextId = contextId; + PermissionName = permissionName; + } } \ No newline at end of file diff --git a/TIAM.Entities/Products/DTOs/AssignedPermissionModel.cs b/TIAM.Entities/Products/DTOs/AssignedPermissionModel.cs new file mode 100644 index 00000000..a7b7bbd7 --- /dev/null +++ b/TIAM.Entities/Products/DTOs/AssignedPermissionModel.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Security.AccessControl; +using System.Text; +using System.Threading.Tasks; + +namespace TIAM.Entities.Products.DTOs +{ + public class AssignedPermissionModel + { + public Guid ContextId { get; set; } + public Guid SubjectId { get; set; } //user or group id + public short SubjectType { get; set; } //user or group + public string Name { get; set; } //user email or group name + public int PermissionsValue { get; set; } + + public AssignedPermissionModel(Guid contextId, Guid subjectId, short subjectType, string name, int permissionsValue) + { + ContextId = contextId; + SubjectId = subjectId; + SubjectType = subjectType; + Name = name; + PermissionsValue = permissionsValue; + } + + } +} diff --git a/TIAM.Entities/Products/Product.cs b/TIAM.Entities/Products/Product.cs index e0702072..bef6eb86 100644 --- a/TIAM.Entities/Products/Product.cs +++ b/TIAM.Entities/Products/Product.cs @@ -6,7 +6,7 @@ using TIAM.Core; namespace TIAM.Entities.Products; -[Table("Product")] + public class Product : IEntityGuid, ITimeStampInfo { [Key, DatabaseGenerated(DatabaseGeneratedOption.None)] @@ -22,4 +22,17 @@ public class Product : IEntityGuid, ITimeStampInfo public DateTime Created { get; set; } public DateTime Modified { get; set; } + + public Product(Guid id, ProductType type, Guid userMediaId, string name, string description, float price, string jsonDetails) + { + Id = id; + ProductType = type; + UsermediaId = userMediaId; + Name = name; + Description = description; + Price = price; + JsonDetails = jsonDetails; + Created = DateTime.Now; + Modified = DateTime.Now; + } } \ No newline at end of file diff --git a/TIAM.Entities/Products/TiamProduct.cs b/TIAM.Entities/Products/TiamProduct.cs new file mode 100644 index 00000000..e7f4b46c --- /dev/null +++ b/TIAM.Entities/Products/TiamProduct.cs @@ -0,0 +1,24 @@ +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using AyCode.Interfaces.Entities; +using AyCode.Interfaces.TimeStampInfo; +using TIAM.Core; + +namespace TIAM.Entities.Products; + +[Table("Products")] +public class TiamProduct : Product +{ + [Key, DatabaseGenerated(DatabaseGeneratedOption.None)] + + public Guid OwnerId { get; set; } + + public TiamProduct(Guid ownerId, ProductType type, Guid userMediaId, string name, string description, float price, string jsonDetails) : this(Guid.NewGuid(), ownerId, type, userMediaId, name, description, price, jsonDetails) { } + public TiamProduct(Guid id, Guid ownerId, ProductType type, Guid userMediaId, string name, string description, float price, string jsonDetails) : base(id, type, userMediaId, name, description, price, jsonDetails) + { + OwnerId = ownerId; + } + + + +} \ No newline at end of file diff --git a/TIAM.Entities/ServiceProviders/TiamServiceProvider.cs b/TIAM.Entities/ServiceProviders/TiamServiceProvider.cs new file mode 100644 index 00000000..87b81ad4 --- /dev/null +++ b/TIAM.Entities/ServiceProviders/TiamServiceProvider.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using AyCode.Entities.ServiceProviders; + + +namespace TIAM.Entities.ServiceProviders +{ + public class TiamServiceProvider : ServiceProviderBase + { + public TiamServiceProvider() { } + public TiamServiceProvider(string name, Guid ownerId) : this(Guid.NewGuid(), name, ownerId) { } + public TiamServiceProvider(Guid id, string name, Guid ownerId) : base(id, name, ownerId) + { + + } + + + } +} diff --git a/TIAM.Entities/Users/AssignedUser.cs b/TIAM.Entities/Users/AssignedUser.cs index 20948080..2945e10a 100644 --- a/TIAM.Entities/Users/AssignedUser.cs +++ b/TIAM.Entities/Users/AssignedUser.cs @@ -10,11 +10,24 @@ public class AssignedUser : IEntityGuid, ITimeStampInfo { [Key, DatabaseGenerated(DatabaseGeneratedOption.None)] public Guid Id { get; set; } - public Guid ProductId { 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; + } } \ No newline at end of file diff --git a/TIAMMobileApp/MauiProgram.cs b/TIAMMobileApp/MauiProgram.cs index 47990a92..c089e9ba 100644 --- a/TIAMMobileApp/MauiProgram.cs +++ b/TIAMMobileApp/MauiProgram.cs @@ -3,7 +3,7 @@ using TIAMMobileApp.Services; using TIAMWebApp.Shared.Application.Interfaces; using DevExpress.Blazor; using TIAMMobilApp.Services; -using TIAMWebApp.Shared.Application.Utility; +using System.Resources; using AyCode.Interfaces.StorageHandlers; namespace TIAMMobileApp @@ -26,6 +26,7 @@ namespace TIAMMobileApp #if DEBUG builder.Services.AddBlazorWebViewDeveloperTools(); builder.Logging.AddDebug(); + builder.Services.AddLocalization(); #endif var handler = new HttpClientHandler(); handler.ServerCertificateCustomValidationCallback = (message, certificate, chain, sslPolicyErrors) => true; @@ -47,8 +48,9 @@ namespace TIAMMobileApp builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); - builder.Services.AddScoped(); - + builder.Services.AddScoped(); + builder.Services.AddSingleton(); + builder.Services.AddSingleton(x => new ResourceManager("TIAMWebApp.Shared.Application.Resources", typeof(Main).Assembly)); return builder.Build(); } } diff --git a/TIAMMobileApp/Services/ComponentUpdateServiceWeb.cs b/TIAMMobileApp/Services/ComponentUpdateServiceWeb.cs new file mode 100644 index 00000000..24b18390 --- /dev/null +++ b/TIAMMobileApp/Services/ComponentUpdateServiceWeb.cs @@ -0,0 +1,13 @@ +using TIAMWebApp.Shared.Application.Interfaces; +namespace TIAMMobileApp.Services +{ + public class ComponentUpdateServiceMobile : IComponentUpdateService + { + public event Action RefreshRequested; + + public void CallRequestRefresh() + { + RefreshRequested?.Invoke(); + } + } +} diff --git a/TIAMMobileApp/Services/SessionServiceMobile.cs b/TIAMMobileApp/Services/SessionServiceMobile.cs index 1538c95c..e2ebd9fc 100644 --- a/TIAMMobileApp/Services/SessionServiceMobile.cs +++ b/TIAMMobileApp/Services/SessionServiceMobile.cs @@ -9,5 +9,6 @@ namespace TIAMMobileApp.Services public string? SessionId { get; set; } public UserSessionModel? User { get; set; } public IPAddress? IPAddress { get; set; } + public bool IsAuthenticated { get; set; } } } diff --git a/TIAMMobileApp/_Imports.razor b/TIAMMobileApp/_Imports.razor index 38f304a6..23f507cb 100644 --- a/TIAMMobileApp/_Imports.razor +++ b/TIAMMobileApp/_Imports.razor @@ -6,3 +6,4 @@ @using Microsoft.JSInterop @using TIAMMobileApp @using TIAMMobileApp.Services +@using AyCode.Interfaces.StorageHandlers; diff --git a/TIAMSharedUI/Pages/AppLaunch.razor b/TIAMSharedUI/Pages/AppLaunch.razor new file mode 100644 index 00000000..f4f19107 --- /dev/null +++ b/TIAMSharedUI/Pages/AppLaunch.razor @@ -0,0 +1,130 @@ +@page "/"; +@using TIAMWebApp.Shared.Application.Interfaces +@using TIAMWebApp.Shared.Application.Models +@using TIAMWebApp.Shared.Application.Utility +@using Newtonsoft.Json +@using System.IdentityModel.Tokens.Jwt +@using TIAMWebApp.Shared.Application.Models.ClientSide +@using AyCode.Interfaces.StorageHandlers; +@using System.Globalization; +@inject NavigationManager NavManager +@inject IJSRuntime JSRuntime +@inject LogToBrowserConsole logToBrowserConsole +@inject IUserDataService UserDataService +@inject ISecureStorageHandler SecureStorageHandler +@inject ISessionService sessionService; +@inject HttpClient http; +

AppLaunch

+ +Loading.... + +@code { + + string userDetailsStr; + string locale; + + protected async override Task OnInitializedAsync() + { + var (_userDetailStr, _locale) = await GetLocalSettings(); + + userDetailsStr = _userDetailStr; + + if(_locale != null) + { + locale = _locale; + Culture = new CultureInfo(locale); + logToBrowserConsole.LogToBC("Locale from settings: " + locale); + } + else + { + logToBrowserConsole.LogToBC("Default locale:" + Culture.Name); + } + + logToBrowserConsole = new LogToBrowserConsole(JSRuntime); + //wait for 5 seconds + await Task.Delay(1000); + + if (!string.IsNullOrWhiteSpace(userDetailsStr)) + { + logToBrowserConsole.LogToBC(userDetailsStr); + var userBasicDetail = JsonConvert.DeserializeObject(userDetailsStr); + + var handler = new JwtSecurityTokenHandler(); + var jsontoken = handler.ReadToken(userBasicDetail?.AccessToken) as JwtSecurityToken; + + if(userBasicDetail!= null) + Setting.UserBasicDetails = userBasicDetail; + + if (jsontoken?.ValidTo < DateTime.UtcNow) + { + logToBrowserConsole.LogToBC("Token needs to be refreshed"); + bool isTokenRefreshed = await UserDataService.RefreshToken(); + + if (isTokenRefreshed) + { + logToBrowserConsole.LogToBC("Token refreshed"); + + } + else + { + logToBrowserConsole.LogToBC("Couldn't refresh token"); + SignOut(); + NavManager.NavigateTo("/index"); + return; + } + + + } + else + { + logToBrowserConsole.LogToBC("Valid token found"); + + } + + string _userId = jsontoken.Claims.First(claim => claim.Type == JwtRegisteredClaimNames.NameId).Value; + string _email = jsontoken.Claims.First(claim => claim.Type == JwtRegisteredClaimNames.Email).Value; + var user = await UserDataService.IsLoggedInAsync(Guid.Parse(_userId)); + sessionService.User = user; + logToBrowserConsole.LogToBC($"Saved user in db is: {user.Email}, setting autenthicated state"); + sessionService.IsAuthenticated = true; + NavManager.NavigateTo("/index"); + } + else + { + logToBrowserConsole.LogToBC("No token stored yet"); + NavManager.NavigateTo("/index"); + } + + } + + public async Task<(string, string)> GetLocalSettings() + { + string userDetailsStr = await SecureStorageHandler.GetFromSecureStorageAsync(nameof(Setting.UserBasicDetails)); + string locale = await SecureStorageHandler.GetFromSecureStorageAsync(nameof(Setting.Locale)); + return (userDetailsStr, locale); + } + + private void SignOut() + { + SecureStorageHandler.ClearAllSecureStorageAsync(); + sessionService.User = null; + sessionService.IsAuthenticated = false; + } + + CultureInfo Culture + { + get => CultureInfo.CurrentCulture; + set + { + if (CultureInfo.CurrentCulture != value) + { + Thread.CurrentThread.CurrentCulture = value; + Thread.CurrentThread.CurrentUICulture = value; + CultureInfo.DefaultThreadCurrentCulture = value; + CultureInfo.DefaultThreadCurrentUICulture = value; + } + } + } + + +} diff --git a/TIAMSharedUI/Pages/ChooseDestination.razor.cs b/TIAMSharedUI/Pages/ChooseDestination.razor.cs index 75818932..90d3aa01 100644 --- a/TIAMSharedUI/Pages/ChooseDestination.razor.cs +++ b/TIAMSharedUI/Pages/ChooseDestination.razor.cs @@ -1,4 +1,5 @@ -using Microsoft.AspNetCore.Components; +using AyCode.Blazor.Components; +using Microsoft.AspNetCore.Components; using System; using System.Collections.Generic; using System.Linq; diff --git a/TIAMSharedUI/Pages/Clubcards.razor b/TIAMSharedUI/Pages/Clubcards.razor index 7f5b02e5..48504150 100644 --- a/TIAMSharedUI/Pages/Clubcards.razor +++ b/TIAMSharedUI/Pages/Clubcards.razor @@ -4,7 +4,7 @@ -
+
diff --git a/TIAMSharedUI/Pages/Components/AuctionComponent.cs b/TIAMSharedUI/Pages/Components/AuctionComponent.razor.cs similarity index 70% rename from TIAMSharedUI/Pages/Components/AuctionComponent.cs rename to TIAMSharedUI/Pages/Components/AuctionComponent.razor.cs index 7d92c2be..0528dfa2 100644 --- a/TIAMSharedUI/Pages/Components/AuctionComponent.cs +++ b/TIAMSharedUI/Pages/Components/AuctionComponent.razor.cs @@ -1,4 +1,5 @@ -using Microsoft.AspNetCore.Components; + +using Microsoft.AspNetCore.Components; using System; using System.Collections.Generic; using System.Linq; @@ -7,7 +8,7 @@ using System.Threading.Tasks; namespace TIAMSharedUI.Pages.Components { - public partial class AuctionComponent + public partial class AuctionComponent : ComponentBase { [Parameter] public Guid UserId { get; set; } diff --git a/TIAMSharedUI/Pages/Components/AuctionItemComponent.cs b/TIAMSharedUI/Pages/Components/AuctionItemComponent.razor.cs similarity index 89% rename from TIAMSharedUI/Pages/Components/AuctionItemComponent.cs rename to TIAMSharedUI/Pages/Components/AuctionItemComponent.razor.cs index 233eca4f..9e380a89 100644 --- a/TIAMSharedUI/Pages/Components/AuctionItemComponent.cs +++ b/TIAMSharedUI/Pages/Components/AuctionItemComponent.razor.cs @@ -1,4 +1,5 @@ -using Microsoft.AspNetCore.Components; +using AyCode.Blazor.Components; +using Microsoft.AspNetCore.Components; using System; using System.Collections.Generic; using System.Linq; @@ -8,7 +9,7 @@ using TIAMWebApp.Shared.Application.Models; namespace TIAMSharedUI.Pages.Components { - public partial class AuctionItemComponent + public partial class AuctionItemComponent : ComponentBase { [Parameter] public int AuctionItemId { get; set; } diff --git a/TIAMSharedUI/Pages/Components/AuthComponent.razor b/TIAMSharedUI/Pages/Components/AuthComponent.razor new file mode 100644 index 00000000..bb1eec69 --- /dev/null +++ b/TIAMSharedUI/Pages/Components/AuthComponent.razor @@ -0,0 +1,9 @@ + + +
+

AuthComponent:

Logged in: @IsLoggedIn

+
+ +@code { + +} diff --git a/TIAMSharedUI/Pages/Components/AuthComponent.razor.cs b/TIAMSharedUI/Pages/Components/AuthComponent.razor.cs new file mode 100644 index 00000000..a182e74f --- /dev/null +++ b/TIAMSharedUI/Pages/Components/AuthComponent.razor.cs @@ -0,0 +1,32 @@ +using Microsoft.AspNetCore.Components; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using TIAMWebApp.Shared.Application.Interfaces; + +namespace TIAMSharedUI.Pages.Components +{ + public partial class AuthComponent : ComponentBase + { + [Inject] + public ISessionService sessionService { get; set; } + public bool IsLoggedIn = false; + + protected override async Task OnInitializedAsync() + { + await base.OnInitializedAsync(); + IsLoggedIn = sessionService.IsAuthenticated; + StateHasChanged(); + } + + protected override void OnAfterRender(bool firstRender) + { + base.OnAfterRender(firstRender); + + + } + + } +} diff --git a/TIAMSharedUI/Pages/Components/InputWizard.razor b/TIAMSharedUI/Pages/Components/InputWizard.razor new file mode 100644 index 00000000..95a7a868 --- /dev/null +++ b/TIAMSharedUI/Pages/Components/InputWizard.razor @@ -0,0 +1,31 @@ +@using System.Linq.Expressions +@using System.ComponentModel.DataAnnotations + +

Edit Form

+
+
+ + +
+

Register with DevExpress

+

+ Create a new account to see it in action +

+
+
+ @CreateEditFormFields() +
+
+
+
+

+ @FormSubmitResult +

+ +@code { + + +} \ No newline at end of file diff --git a/TIAMSharedUI/Pages/Components/InputWizard.razor.cs b/TIAMSharedUI/Pages/Components/InputWizard.razor.cs new file mode 100644 index 00000000..3004a9e7 --- /dev/null +++ b/TIAMSharedUI/Pages/Components/InputWizard.razor.cs @@ -0,0 +1,149 @@ +using AyCode.Entities.Users; +using DevExpress.Blazor; +using Microsoft.AspNetCore.Components; +using Microsoft.AspNetCore.Components.Forms; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Linq.Expressions; +using System.Text; +using System.Threading.Tasks; +using TIAM.Entities.TransferDestinations; + +namespace TIAMSharedUI.Pages.Components +{ + public partial class InputWizard : ComponentBase + { + + string FormSubmitResult = ""; + //TestUserData Data { get; set; } = new TestUserData(); + TransferDestination Data { get; set; } = new TransferDestination(); + + string PhoneMask { get; set; } = "(999)000-0000"; + + void HandleValidSubmit() + { + FormSubmitResult = "You have been registred successully."; + } + void HandleInvalidSubmit() + { + FormSubmitResult = "Please correct all errors"; + } + + public RenderFragment CreateEditFormFields() => formLayoutBuilder => + { + var propertyList = typeof(TransferDestination).GetProperties(); + formLayoutBuilder.OpenComponent(0); + formLayoutBuilder.AddAttribute(1, "ChildContent", (RenderFragment)((layoutItemBuilder) => + { + int i = 0; + foreach (var property in propertyList) + { + + var attrList = (DataTypeAttribute)property.GetCustomAttributes(typeof(DataTypeAttribute), false).First(); + DisplayAttribute displayLabel = (DisplayAttribute)property.GetCustomAttributes(typeof(DisplayAttribute), false).First(); + layoutItemBuilder.OpenComponent(i++); + layoutItemBuilder.AddAttribute(i++, "Caption", displayLabel.Name); + layoutItemBuilder.AddAttribute(i++, "ColSpanMd", 12); + //layoutItemBuilder.AddAttribute(i++, "CssClass", "form-field"); + var access = Expression.Property(Expression.Constant(Data), property.Name); + var lambda = Expression.Lambda(typeof(Func<>).MakeGenericType(property.PropertyType), access); + layoutItemBuilder.AddAttribute(i++, "Template", (RenderFragment)((context) => ((editor) => + { + var j = 0; + switch (attrList.DataType) + { + case DataType.Text: + { + editor.OpenComponent(j++); + editor.AddAttribute(j++, "Text", property.GetValue(Data)); + editor.AddAttribute(j++, "TextExpression", lambda); + editor.AddAttribute(j++, "CssClass", "form-field"); + editor.AddAttribute(j++, "TextChanged", EventCallback.Factory.Create(this, str => { property.SetValue(Data, str); })); + editor.CloseComponent(); + break; + } + case DataType.Password: + { + + editor.OpenComponent(j++); + editor.AddAttribute(j++, "Password", true); + editor.AddAttribute(j++, "NullText", "Password"); + editor.AddAttribute(j++, "Text", property.GetValue(Data)); + editor.AddAttribute(j++, "TextExpression", lambda); + editor.AddAttribute(j++, "TextChanged", EventCallback.Factory.Create(this, str => { property.SetValue(Data, str); })); + editor.CloseComponent(); + break; + } + case DataType.PhoneNumber: + { + editor.OpenComponent>(j++); + editor.AddAttribute(j++, "Value", property.GetValue(Data)); + editor.AddAttribute(j++, "Mask", PhoneMask); + editor.AddAttribute(j++, "ValueExpression", lambda); + editor.AddAttribute(j++, "ValueChanged", EventCallback.Factory.Create(this, str => { property.SetValue(Data, str); })); + editor.CloseComponent(); + break; + } + case DataType.Date: + { + editor.OpenComponent>(j); + editor.AddAttribute(j++, "Date", property.GetValue(Data)); + editor.AddAttribute(j++, "DateExpression", lambda); + editor.AddAttribute(j++, "DateChanged", EventCallback.Factory.Create(this, str => { property.SetValue(Data, str); })); + editor.CloseComponent(); + break; + + } + case DataType.Custom: + { + editor.OpenComponent>(j); + editor.AddAttribute(j++, "Data", AdditionalData.Occupations); + editor.AddAttribute(j++, "Value", property.GetValue(Data)); + editor.AddAttribute(j++, "ValueExpression", lambda); + editor.AddAttribute(j++, "ValueChanged", EventCallback.Factory.Create(this, str => { property.SetValue(Data, str); })); + editor.CloseComponent(); + break; + + } + case DataType.MultilineText: + { + editor.OpenComponent(j); + editor.AddAttribute(j++, "Text", property.GetValue(Data)); + editor.AddAttribute(j++, "TextExpression", lambda); + editor.AddAttribute(j++, "TextChanged", EventCallback.Factory.Create(this, str => { property.SetValue(Data, str); })); + editor.CloseComponent(); + break; + + } + default: + break; + } + }))); + + layoutItemBuilder.CloseComponent(); + layoutItemBuilder.OpenElement(i++, "div"); + layoutItemBuilder.AddAttribute(i++, "class", "text-danger"); + layoutItemBuilder.OpenComponent(i++, typeof(ValidationMessage<>).MakeGenericType(property.PropertyType)); + layoutItemBuilder.AddAttribute(i++, "For", lambda); + layoutItemBuilder.CloseComponent(); + layoutItemBuilder.CloseElement(); + } + layoutItemBuilder.OpenComponent(i++); + layoutItemBuilder.AddAttribute(i++, "Template", (RenderFragment)((context) => ((editor) => + { + + editor.OpenComponent(i++); + editor.AddAttribute(i++, "SubmitFormOnClick", true); + editor.AddAttribute(i++, "Text", "Register"); + editor.CloseComponent(); + }))); + + layoutItemBuilder.CloseComponent(); + })); + formLayoutBuilder.CloseComponent(); + }; + + } +} diff --git a/TIAMSharedUI/Pages/Components/SettingsBasic.razor b/TIAMSharedUI/Pages/Components/SettingsBasic.razor new file mode 100644 index 00000000..a7ab8d7d --- /dev/null +++ b/TIAMSharedUI/Pages/Components/SettingsBasic.razor @@ -0,0 +1,20 @@ +@using System.Globalization + +

SettingsBasic

+ +
+ +

@localizer["Settings.Language"] : @Culture.DisplayName

+
+ + +
+
+
+ +@code { + +} diff --git a/TIAMSharedUI/Pages/Components/SettingsBasic.razor.cs b/TIAMSharedUI/Pages/Components/SettingsBasic.razor.cs new file mode 100644 index 00000000..fa10e689 --- /dev/null +++ b/TIAMSharedUI/Pages/Components/SettingsBasic.razor.cs @@ -0,0 +1,107 @@ +using AyCode.Blazor.Components; +using AyCode.Interfaces.StorageHandlers; +using DevExpress.XtraPrinting.Native; +using Microsoft.AspNetCore.Components; +using Microsoft.EntityFrameworkCore.Metadata.Conventions; +using Microsoft.Extensions.Localization; +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using TIAMSharedUI.Resources; +using TIAMWebApp.Shared.Application.Interfaces; +using TIAMWebApp.Shared.Application.Models; +using TIAMWebApp.Shared.Application.Models.ClientSide; +using TIAMWebApp.Shared.Application.Utility; + +namespace TIAMSharedUI.Pages.Components +{ + public partial class SettingsBasic : ComponentBase + { + [Inject] + public ISecureStorageHandler? secureStorageHandler { get; set; } + + [Inject] + public IStringLocalizer? localizer { get; set; } + [Inject] + public NavigationManager navigationManager { get; set; } + [Inject] + public LogToBrowserConsole logToBrowserConsole { get; set; } + [Inject] + public IComponentUpdateService componentUpdateService { get; set; } + + public CultureInfo SelectedCulture { get; set; } + IEnumerable Data { get; set; } + + [Parameter] + public EventCallback LanguageChanged { get; set; } + + private Task? GetCurrentSettings() + { + return secureStorageHandler?.GetFromSecureStorageAsync("Locale"); + } + + private void SaveSettings() + { + + secureStorageHandler?.SaveToSecureStorageAsync(nameof(Setting.Locale), SelectedCulture.Name); + componentUpdateService.CallRequestRefresh(); + } + + + protected override async Task OnInitializedAsync() + { + Data = culture.ToList(); + string? current = await GetCurrentSettings(); + if (!string.IsNullOrEmpty(current)) + { + logToBrowserConsole.LogToBC(current); + + //SelectedCulture = culture.FirstOrDefault(x => x.Name == Setting.Locale); + foreach (var item in culture) + { + logToBrowserConsole.LogToBC(item.Name); + if (item.Name == current) + { + SelectedCulture = item; + break; + } + } + + logToBrowserConsole.LogToBC("Selected: " + SelectedCulture.Name); + } + else + { + SelectedCulture = culture[0]; + } + + + } + + CultureInfo[] culture = new[] + { + new CultureInfo("en-US"), + new CultureInfo("hu-HU") + }; + + CultureInfo Culture + { + get => CultureInfo.CurrentCulture; + set + { + if (CultureInfo.CurrentCulture != value) + { + Thread.CurrentThread.CurrentCulture = value; + Thread.CurrentThread.CurrentUICulture = value; + CultureInfo.DefaultThreadCurrentCulture = value; + CultureInfo.DefaultThreadCurrentUICulture = value; + SelectedCulture = value; + SaveSettings(); + } + } + } + + } +} diff --git a/TIAMSharedUI/Pages/Components/SettingsMember.razor b/TIAMSharedUI/Pages/Components/SettingsMember.razor new file mode 100644 index 00000000..75bb9246 --- /dev/null +++ b/TIAMSharedUI/Pages/Components/SettingsMember.razor @@ -0,0 +1,11 @@ +

Member settings

+
+ + +
+
+ + +@code { + +} diff --git a/TIAMSharedUI/Pages/Components/SettingsMember.razor.cs b/TIAMSharedUI/Pages/Components/SettingsMember.razor.cs new file mode 100644 index 00000000..97cb6795 --- /dev/null +++ b/TIAMSharedUI/Pages/Components/SettingsMember.razor.cs @@ -0,0 +1,9 @@ + +using Microsoft.AspNetCore.Components; + +namespace TIAMSharedUI.Pages.Components +{ + public partial class SettingsMember : ComponentBase + { + } +} diff --git a/TIAMSharedUI/Pages/Components/TestUserData.cs b/TIAMSharedUI/Pages/Components/TestUserData.cs new file mode 100644 index 00000000..65ad41ca --- /dev/null +++ b/TIAMSharedUI/Pages/Components/TestUserData.cs @@ -0,0 +1,106 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Text.RegularExpressions; +using System.Threading.Tasks; + +namespace TIAMSharedUI.Pages.Components +{ + public class TestUserData + { + [Required(ErrorMessage = "The Username value should be specified.")] + [DataType(DataType.Text)] + [Display(Name = "User Name")] + public string Username { get; set; } + + [Required(ErrorMessage = "The Password value should be specified.")] + [MinPasswordLength(6, "The Password must be at least 6 characters long.")] + [DataType(DataType.Password)] + [Display(Name = "Password")] + public string Password { get; set; } + + + [Required(ErrorMessage = "The Email value should be specified.")] + [Email(ErrorMessage = "The Email value is invalid.")] + [DataType(DataType.Text)] + [Display(Name = "Email Address")] + public string Email { get; set; } + + [Required(ErrorMessage = "The Phone value should be specified.")] + [DataType(DataType.PhoneNumber)] + [Display(Name = "Phone Number")] + public string Phone { get; set; } + + [DataType(DataType.Date)] + [Display(Name = "Birth Date")] + public DateTime BirthDate { get; set; } = new DateTime(1970, 1, 1); + + [DataType("ComboBox")] + [Display(Name = "Occupation")] + public string Occupation { get; set; } + + [DataType(DataType.MultilineText)] + [Display(Name = "Notes")] + public string Notes { get; set; } + + } + + public class AdditionalData + { + public static IEnumerable Occupations { get; set; } = new List() { + "Academic", + "Administrative", + "Art/Entertainment", + "College Student", + "Community & Social", + "Computers", + "Education", + "Engineering", + "Financial Services", + "Government", + "High School Student", + "Law", + "Managerial", + "Manufacturing", + "Medical/Health", + "Military", + "Non-government Organization", + "Other Services", + "Professional", + "Retail", + "Science & Research", + "Sports", + "Technical", + "University Student", + "Web Building", + }; + } + + [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter, AllowMultiple = false)] + public class MinPasswordLengthAttribute : ValidationAttribute + { + int MinLength { get; } + public MinPasswordLengthAttribute(int minLength, string errorMsg) : base(errorMsg) + { + MinLength = minLength; + } + + public override bool IsValid(object value) + { + return ((string)value).Length >= MinLength; + } + } + + [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter, AllowMultiple = false)] + public class EmailAttribute : ValidationAttribute + { + public override bool IsValid(object value) + { + return Regex.IsMatch((string)value, @"^[\w!#$%&'*+\-/=?\^_`{|}~]+(\.[\w!#$%&'*+\-/=?\^_`{|}~]+)*" + + "@" + + @"((([\-\w]+\.)+[a-zA-Z]{2,4})|(([0-9]{1,3}\.){3}[0-9]{1,3}))$"); + } + } +} diff --git a/TIAMSharedUI/Pages/Components/TransferStep0.razor b/TIAMSharedUI/Pages/Components/TransferStep0.razor new file mode 100644 index 00000000..587f3b21 --- /dev/null +++ b/TIAMSharedUI/Pages/Components/TransferStep0.razor @@ -0,0 +1,54 @@ +@using TIAMWebApp.Shared.Application.Interfaces; +@using TIAMWebApp.Shared.Application.Models.PageModels; +@using TIAMWebApp.Shared.Application.Models; +@inject ISessionService sessionService; + + + + +

Step 1

+
+ + + + + + +
+ + + +
+ + +@code { + + [Parameter] + public AuctionBidModel auctionBidModel { get; set; } + [Parameter] + public int TargetProductId { get; set; } + [Parameter] + public EventCallback onNext { get; set; } + [Parameter] + public EventCallback auctionBidModelChanged { get; set; } + + public Guid UserId { get; set; } + + private string spinnerClass = ""; + + private async Task GoToNextStep() + { + spinnerClass = "spinner-border spinner-border-sm"; + await Task.Delay(500); + auctionBidModel.Id = Guid.NewGuid(); + auctionBidModel.OwnerId = sessionService.User.UserId; + auctionBidModel.TargetProductId = TargetProductId; + spinnerClass = ""; + await auctionBidModelChanged.InvokeAsync(auctionBidModel); + await onNext.InvokeAsync(); + } + +} \ No newline at end of file diff --git a/TIAMSharedUI/Pages/Components/TransferStep1.razor b/TIAMSharedUI/Pages/Components/TransferStep1.razor new file mode 100644 index 00000000..09807b1b --- /dev/null +++ b/TIAMSharedUI/Pages/Components/TransferStep1.razor @@ -0,0 +1,73 @@ +@using TIAMWebApp.Shared.Application.Models.PageModels; +@using TIAMWebApp.Shared.Application.Models; +@using TIAMWebApp.Shared.Application.Interfaces; +@inject ISessionService sessionService; + + + + +

Step 1

+
+ + + + + + + +
+ + + + +
+ + + +@code { + [Parameter] + public AuctionBidModel? auctionBidModel { get; set; } + + public string Email { get; set; } = "test@test.com"; + + [Parameter] + public EventCallback onNext { get; set; } + + [Parameter] + public EventCallback auctionBidModelChanged { get; set; } + + IEnumerable PredefinedPlaceholders { get; set; } = new List() { '_', '#' }; + + string EmailMask { get; set; } = @"(\w|[.-])+@(\w|-)+\.(\w|-){2,4}"; + MaskAutoCompleteMode AutoCompleteMode { get; set; } = MaskAutoCompleteMode.Strong; + char Placeholder { get; set; } = '_'; + bool PlaceholderVisible { get; set; } = false; + + private string spinnerClass = ""; + + private async Task GoToNextStep() + { + spinnerClass = "spinner-border spinner-border-sm"; + await Task.Delay(500); + auctionBidModel.Email = Email; + spinnerClass = ""; + await auctionBidModelChanged.InvokeAsync(auctionBidModel); + await onNext.InvokeAsync(); + } + + protected override async Task OnInitializedAsync() + { + Email = sessionService.User.Email; + await base.OnInitializedAsync(); + } + +} \ No newline at end of file diff --git a/TIAMSharedUI/Pages/Components/TransferStep3.razor b/TIAMSharedUI/Pages/Components/TransferStep3.razor new file mode 100644 index 00000000..83d71134 --- /dev/null +++ b/TIAMSharedUI/Pages/Components/TransferStep3.razor @@ -0,0 +1,72 @@ +@using System.Globalization; +@using TIAMWebApp.Shared.Application.Models.PageModels; +@using TIAMWebApp.Shared.Application.Models; +

Step 3: Password

+ + + + + + + +
+ + + + + + + + +
+ + + Previous + + +
+ + +@code { + [Parameter] + public AuctionBidModel auctionBidModel { get; set; } + + [Parameter] + public EventCallback AuctionBidModelChanged { get; set; } + + [Parameter] + public EventCallback onPrev { get; set; } + + [Parameter] + public EventCallback onSubmit { get; set; } + + private string spinnerClass = ""; + + public async Task SubmitRegistration() + { + + spinnerClass = "spinner-border spinner-border-sm"; + await Task.Delay(500); + spinnerClass = ""; + + await AuctionBidModelChanged.InvokeAsync(auctionBidModel); + await onSubmit.InvokeAsync(); + } + + private async Task GoToPreviousStep() + { + + await onPrev.InvokeAsync(); + } + + + + + +} + diff --git a/TIAMSharedUI/Pages/DbTestComponent.razor.cs b/TIAMSharedUI/Pages/DbTestComponent.razor.cs index 12f84567..f1180454 100644 --- a/TIAMSharedUI/Pages/DbTestComponent.razor.cs +++ b/TIAMSharedUI/Pages/DbTestComponent.razor.cs @@ -1,4 +1,5 @@ -using Microsoft.AspNetCore.Components; +using AyCode.Blazor.Components; +using Microsoft.AspNetCore.Components; using System; using System.Collections.Generic; using System.Linq; @@ -10,7 +11,7 @@ using TIAMWebApp.Shared.Application.Models; namespace TIAMSharedUI.Pages { - public partial class DbTestComponent: ComponentBase + public partial class DbTestComponent { [Parameter] public string EmailAddress diff --git a/TIAMSharedUI/Pages/Index.razor b/TIAMSharedUI/Pages/Index.razor index b103267e..01fe871c 100644 --- a/TIAMSharedUI/Pages/Index.razor +++ b/TIAMSharedUI/Pages/Index.razor @@ -1,4 +1,4 @@ -@page "/" +@page "/index" @using AyCode.Interfaces.StorageHandlers; @using Newtonsoft.Json; @using TIAMWebApp.Shared.Application.Interfaces @@ -7,26 +7,26 @@ @using TIAMWebApp.Shared.Application.Models; @using TIAMWebApp.Shared.Application.Utility; @using System.IdentityModel.Tokens.Jwt; +@using TIAMSharedUI.Pages.Components; @inject NavigationManager NavManager @inject IUserDataService UserDataService; @inject IJSRuntime jsRuntime; @inject ISecureStorageHandler SecureStorageHandler @inject ISessionService sessionService; +@inject IStringLocalizer localizer; @using TIAMSharedUI.Shared Index - - - -
+ +
-

Welcome

-

Please select!

+

@localizer.GetString("Index.Title")

+

@localizer.GetString("Index.Subtitle")

@@ -37,9 +37,9 @@ Card image
-

Transfer

- -

Do you need a lift? Book a transfer now!

+

@localizer.GetString("Index.Transfer")

+ +

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

@@ -49,8 +49,8 @@
Card image
-

Tours

-

Are you curious about the wonderful sights of Budapest or Hungary? Book a guided tour now!

+

@localizer.GetString("Index.Tours")

+

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

@@ -60,8 +60,8 @@
Card image
-

Clubcards

-

Join the club, and enjoy great offers during your stay!

+

@localizer.GetString("Index.Clubcards")

+

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

@@ -72,71 +72,7 @@ @code { - bool isUserLoggedIn; - int userType = 0; - int currentUserRole = 249; - public UserSessionModel MyUser; - //add a new dictionary for the role types - - protected async override Task OnInitializedAsync() - { - //old - - - var logToBrowserConsole = new LogToBrowserConsole(jsRuntime); - //wait for 5 seconds - //await Task.Delay(5000); - - string userDetailsStr = await SecureStorageHandler.GetFromSecureStorageAsync(nameof(Setting.UserBasicDetails)); - logToBrowserConsole.LogToBC(userDetailsStr); - if (!string.IsNullOrWhiteSpace(userDetailsStr)) - { - var userBasicDetail = JsonConvert.DeserializeObject(userDetailsStr); - - var handler = new JwtSecurityTokenHandler(); - var jsontoken = handler.ReadToken(userBasicDetail?.AccessToken) as JwtSecurityToken; - - if (userBasicDetail != null) - Setting.UserBasicDetails = userBasicDetail; - - if (jsontoken?.ValidTo < DateTime.UtcNow) - { - logToBrowserConsole.LogToBC("Token needs to be refreshed"); - bool isTokenRefreshed = await UserDataService.RefreshToken(); - - if (isTokenRefreshed) - { - logToBrowserConsole.LogToBC("Token refreshed"); - var myId = Guid.Parse(jsontoken.Claims.First(claim => claim.Type == JwtRegisteredClaimNames.NameId).Value); - //UserDataService.User.Email = jsontoken.Claims.First(claim => claim.Type == JwtRegisteredClaimNames.Email).Value; - MyUser = await UserDataService.IsLoggedInAsync(myId); - logToBrowserConsole.LogToBC(MyUser.UserId.ToString()); - } - else - { - logToBrowserConsole.LogToBC("Couldn't refresh token"); - } - - } - else - { - logToBrowserConsole.LogToBC("Valid token found"); - - var myId = Guid.Parse(jsontoken.Claims.First(claim => claim.Type == JwtRegisteredClaimNames.NameId).Value); - logToBrowserConsole.LogToBC(myId.ToString()); - //UserDataService.User.Email = jsontoken.Claims.First(claim => claim.Type == JwtRegisteredClaimNames.Email).Value; - MyUser = await UserDataService.IsLoggedInAsync(myId); - logToBrowserConsole.LogToBC(MyUser.UserId.ToString()); - sessionService.User = MyUser; - logToBrowserConsole.LogToBC($"{sessionService.User.UserId.ToString()}, {sessionService.User.Email}."); - } - } - else - { - logToBrowserConsole.LogToBC("No token stored yet"); - } - - } + } diff --git a/TIAMSharedUI/Pages/Components/AppLaunch.razor b/TIAMSharedUI/Pages/LaunchAdmin.razor similarity index 98% rename from TIAMSharedUI/Pages/Components/AppLaunch.razor rename to TIAMSharedUI/Pages/LaunchAdmin.razor index b96fdf9e..722a89b7 100644 --- a/TIAMSharedUI/Pages/Components/AppLaunch.razor +++ b/TIAMSharedUI/Pages/LaunchAdmin.razor @@ -1,4 +1,4 @@ -@page "/admin"; +@page "/adminstart"; @using TIAMWebApp.Shared.Application.Interfaces @using TIAMWebApp.Shared.Application.Models @using TIAMWebApp.Shared.Application.Utility diff --git a/TIAMSharedUI/Pages/Login.razor b/TIAMSharedUI/Pages/Login.razor index ed89d9ad..637ac896 100644 --- a/TIAMSharedUI/Pages/Login.razor +++ b/TIAMSharedUI/Pages/Login.razor @@ -1,73 +1,65 @@ -@page "/login_old" +@page "/login" +@using System.IdentityModel.Tokens.Jwt; +@using System.Security.Claims; +@using Newtonsoft.Json.Linq; +@using System.Text.Json; +@using System.Reflection; @using TIAMWebApp.Shared.Application.Interfaces; -@using TIAMWebApp.Shared.Application.Models; @using TIAMWebApp.Shared.Application.Models.PageModels; -@inject NavigationManager navManager -@inject IUserDataService userDataService +@using TIAMSharedUI.Pages.Components; +@using TIAMWebApp.Shared.Application.Models.ClientSide; +@using TIAMWebApp.Shared.Application.Models; +@using TIAMWebApp.Shared.Application.Utility; +@using AyCode.Interfaces.StorageHandlers; + + Login
- -
- Tour I Am -
- - - -
-
- - - -
-
- - - -
-
- - -
- - - -
-
-

@isUserLoggedIn

@CurrentValue

- + +
+ @localizer["LoginTitleText"] +
+
+
+ @switch (currentStep) + { + case 1: + + ; + break; + + case 2: + + ; + break; + } +
+ + +
+

@currentStep

+ @{ + if (!loggedIn) + { + +
+ +

@localizer["LoginEmail"]: @loginModel.Email

+ +

@loginModel.Password

+
+ } + } +
+ No account yet? Sign up here! +
+
@code { - LoginModel loginModel = new(); + LoginModel loginModel = new LoginModel("test@test", "test1234"); - bool isUserLoggedIn; - int CurrentValue = 0; - - public async Task next() - { - //var user = await userDataService.IsLoggedInAsync(); - //user.IsLoggedIn = true; - //isUserLoggedIn = user.IsLoggedIn; - //user.UserType = (UserType)CurrentValue; - //navManager.NavigateTo("home"); - - } - - public void Submit() - { - - } -} + +} \ No newline at end of file diff --git a/TIAMSharedUI/Pages/Login.razor.cs b/TIAMSharedUI/Pages/Login.razor.cs new file mode 100644 index 00000000..6f6e6a36 --- /dev/null +++ b/TIAMSharedUI/Pages/Login.razor.cs @@ -0,0 +1,165 @@ +using Microsoft.AspNetCore.Components; +using System.IdentityModel.Tokens.Jwt; +using System.Text.Json; +using TIAMWebApp.Shared.Application.Models.ClientSide; +using TIAMWebApp.Shared.Application.Models; +using TIAMWebApp.Shared.Application.Interfaces; +using TIAMWebApp.Shared.Application.Utility; +using Microsoft.JSInterop; +using AyCode.Interfaces.StorageHandlers; +using System.ComponentModel.DataAnnotations; +using TIAMSharedUI.Resources; +using System.Resources; +using Microsoft.Extensions.Localization; +using AyCode.Blazor.Components; +using Azure.Core; + +namespace TIAMSharedUI.Pages +{ + public partial class Login : ComponentBase + { + + [Inject] + public NavigationManager navManager { get; set; } + [Inject] + public IUserDataService userDataService { get; set; } + [Inject] + public LogToBrowserConsole logToBrowserConsole { get; set; } + [Inject] + public IJSRuntime jsRuntime { get; set; } + [Inject] + public ISecureStorageHandler secureStorageHandler { get; set; } + [Inject] + public IStringLocalizer localizer { get; set; } + [Inject] + public ISessionService sessionService { get; set; } + + //fill loginmodel with fake but valid data + + //LoginModel loginModel = new(); + + //[Display(Name = "LoginTitleText", ResourceType = typeof(MyResources))] + public string TitleText { get; set; } = "dda,mnd,amn,a"; + private int currentStep = 1; + bool loggedIn = false; + + + private void GoToNextStep() + { + currentStep++; + } + + private void GoToPreviousStep() + { + currentStep--; + } + + private async void SubmitLogin() + { + + + currentStep = 1; + logToBrowserConsole.LogToBC("Login started: " + "Email: " + loginModel.Email + ", Password: " + loginModel.Password); + var response = await userDataService.AuthenticateUser(loginModel); + //var response = await UserDataservice.TestUserApi(30); + logToBrowserConsole.LogToBC("Login started"); + logToBrowserConsole.LogToBC(response); + if (!string.IsNullOrEmpty(response)) + { + //get token and save to local storage + //parse to Mainresponse from json string + + + //var Mainresponse = JsonSerializer.Deserialize(response); + var Mainresponse = JsonSerializer.Deserialize(response, new JsonSerializerOptions { PropertyNameCaseInsensitive = true }); + + if (Mainresponse != null) + { + + //check for bad request + //TODO: fix hacky solution + string AuthResponseJson = JsonSerializer.Serialize(Mainresponse.Content); + + var AuthResponse = JsonSerializer.Deserialize(AuthResponseJson, new JsonSerializerOptions { PropertyNameCaseInsensitive = true }); + + string accessToken = AuthResponse.AccessToken; + + var token = ProcessToken(accessToken); + + string _userId = token.Claims.First(claim => claim.Type == JwtRegisteredClaimNames.NameId).Value; + string _email = token.Claims.First(claim => claim.Type == JwtRegisteredClaimNames.Email).Value; + + var myId = Guid.Parse(_userId); + //userDataService.User.Email = _email; + + var userBasicDetails = new UserBasicDetails(_userId, _email, AuthResponse.AccessToken, AuthResponse.RefreshToken); + + string userBasicDetailsJson = JsonSerializer.Serialize(userBasicDetails); + + + //save to local storage + await secureStorageHandler.SaveToSecureStorageAsync(nameof(Setting.UserBasicDetails), userBasicDetailsJson); + + + + + if (!Mainresponse.IsSuccess) + { + //await App.Current.MainPage.DisplayAlert("Error", "Invalid credentials", "Ok"); + //display error message via jsinterop + logToBrowserConsole.LogToBC("Invalid credentials"); + navManager.NavigateTo("login"); + } + else + { + //await App.Current.MainPage.DisplayAlert("Success", "Successful login", "Ok"); + //display success message via jsinterop + logToBrowserConsole.LogToBC("Successful login"); + var user = await userDataService.IsLoggedInAsync(myId); + SaveToSessionInfo(user); + user.UserType = UserType.Admin; + navManager.NavigateTo("index"); + } + + } + + } + else + { + //api error + //await App.Current.MainPage.DisplayAlert("Error", "An error occured while trying to login", "Ok"); + //display error message via jsinterop + logToBrowserConsole.LogToBC("An error occured while trying to login"); + navManager.NavigateTo("login"); + } + + } + + protected override void OnInitialized() + { + + base.OnInitialized(); + if(sessionService.IsAuthenticated) + { + navManager.NavigateTo("index"); + } + + } + + public JwtSecurityToken ProcessToken(string accessToken) + { + var handler = new JwtSecurityTokenHandler(); + var token = handler.ReadJwtToken(accessToken) as JwtSecurityToken; + return token; + } + /// + /// This method stores the user data in the session service so we know during navigation that the user is logged in. + /// + /// + protected void SaveToSessionInfo(UserSessionModel user) + { + sessionService.User = user; + sessionService.IsAuthenticated = true; + } + } +} diff --git a/TIAMSharedUI/Pages/Login.razor.css b/TIAMSharedUI/Pages/Login.razor.css index a35d1811..8f676d9d 100644 --- a/TIAMSharedUI/Pages/Login.razor.css +++ b/TIAMSharedUI/Pages/Login.razor.css @@ -1,7 +1,3 @@ -.wrapper{ - max-width:400px; +.wrapper { + max-width: 400px; } - -select :focus-visible { - border-color: transparent !important; -} \ No newline at end of file diff --git a/TIAMSharedUI/Pages/Login2.razor b/TIAMSharedUI/Pages/Login2.razor deleted file mode 100644 index edb05e42..00000000 --- a/TIAMSharedUI/Pages/Login2.razor +++ /dev/null @@ -1,165 +0,0 @@ -@page "/login" -@using System.IdentityModel.Tokens.Jwt; -@using System.Security.Claims; -@using Newtonsoft.Json.Linq; -@using System.Text.Json; -@using System.Reflection; -@using TIAMWebApp.Shared.Application.Interfaces; -@using TIAMWebApp.Shared.Application.Models.PageModels; -@using TIAMSharedUI.Pages.Components; -@using TIAMWebApp.Shared.Application.Models.ClientSide; -@using TIAMWebApp.Shared.Application.Models; -@using TIAMWebApp.Shared.Application.Utility; -@using AyCode.Interfaces.StorageHandlers; -@inject NavigationManager navManager -@inject LogToBrowserConsole logToBrowserConsole -@inject IUserDataService userDataService -@inject IJSRuntime jsRuntime -@inject ISecureStorageHandler SecureStorageHandler - -Login - -
- -
- Let's get you inside! -
-
-
- @switch (currentStep) - { - case 1: - - ; - break; - - case 2: - - ; - break; - } -
- - -
-

@currentStep

- @{ - if (!loggedIn) - { - -
- -

@loginModel.Email

- -

@loginModel.Password

-
- } - } -
- No account yet? Sign up here! -
-
- -@code { - - LoginModel loginModel = new(); - - private int currentStep = 1; - - bool loggedIn = false; - - - private void GoToNextStep() - { - currentStep++; - } - - private void GoToPreviousStep() - { - currentStep--; - } - - private async void SubmitLogin() - { - - - currentStep = 1; - logToBrowserConsole.LogToBC("Login started: " + "Email: " + loginModel.Email + ", Password: " + loginModel.Password); - var response = await userDataService.AuthenticateUser(loginModel); - //var response = await UserDataservice.TestUserApi(30); - logToBrowserConsole.LogToBC("Login started"); - logToBrowserConsole.LogToBC(response); - if (!string.IsNullOrEmpty(response)) - { - //get token and save to local storage - //parse to Mainresponse from json string - - - //var Mainresponse = JsonSerializer.Deserialize(response); - var Mainresponse = JsonSerializer.Deserialize(response, new JsonSerializerOptions { PropertyNameCaseInsensitive = true }); - - if (Mainresponse != null) - { - - //check for bad request - - string AuthResponseJson = JsonSerializer.Serialize(Mainresponse.Content); - - var AuthResponse = JsonSerializer.Deserialize(AuthResponseJson, new JsonSerializerOptions { PropertyNameCaseInsensitive = true }); - - string accessToken = AuthResponse.AccessToken; - - var handler = new JwtSecurityTokenHandler(); - var token = handler.ReadJwtToken(accessToken) as JwtSecurityToken; - - string _userId = token.Claims.First(claim => claim.Type == JwtRegisteredClaimNames.NameId).Value; - string _email = token.Claims.First(claim => claim.Type == JwtRegisteredClaimNames.Email).Value; - - var myId = Guid.Parse(_userId); - //userDataService.User.Email = _email; - - var userBasicDetails = new UserBasicDetails(_userId, _email, AuthResponse.AccessToken, AuthResponse.RefreshToken); - - string userBasicDetailsJson = JsonSerializer.Serialize(userBasicDetails); - - - //save to local storage - await SecureStorageHandler.SaveToSecureStorageAsync(nameof(Setting.UserBasicDetails), userBasicDetailsJson); - - - if (!Mainresponse.IsSuccess) - { - //await App.Current.MainPage.DisplayAlert("Error", "Invalid credentials", "Ok"); - //display error message via jsinterop - logToBrowserConsole.LogToBC("Invalid credentials"); - navManager.NavigateTo("login"); - } - else - { - //await App.Current.MainPage.DisplayAlert("Success", "Successful login", "Ok"); - //display success message via jsinterop - logToBrowserConsole.LogToBC("Successful login"); - var user = await userDataService.IsLoggedInAsync(myId); - - user.UserType = UserType.Admin; - navManager.NavigateTo("home"); - } - - } - - } - else - { - //api error - //await App.Current.MainPage.DisplayAlert("Error", "An error occured while trying to login", "Ok"); - //display error message via jsinterop - logToBrowserConsole.LogToBC("An error occured while trying to login"); - navManager.NavigateTo("login"); - } - - } - - -} \ No newline at end of file diff --git a/TIAMSharedUI/Pages/Login2.razor.css b/TIAMSharedUI/Pages/Login2.razor.css deleted file mode 100644 index 8f676d9d..00000000 --- a/TIAMSharedUI/Pages/Login2.razor.css +++ /dev/null @@ -1,3 +0,0 @@ -.wrapper { - max-width: 400px; -} diff --git a/TIAMSharedUI/Pages/Login_old.razor b/TIAMSharedUI/Pages/Login_old.razor new file mode 100644 index 00000000..7b56e9d8 --- /dev/null +++ b/TIAMSharedUI/Pages/Login_old.razor @@ -0,0 +1,73 @@ +@page "/login_old" +@using TIAMWebApp.Shared.Application.Interfaces; +@using TIAMWebApp.Shared.Application.Models; +@using TIAMWebApp.Shared.Application.Models.PageModels; +@inject NavigationManager navManager +@inject IUserDataService userDataService +Login + +
+ +
+ Tour I Am +
+ + + +
+
+ + + +
+
+ + + +
+
+ + +
+ + + +
+
+

@isUserLoggedIn

@CurrentValue

+ +
+ +@code { + LoginModel loginModel = new LoginModel("", ""); + + bool isUserLoggedIn; + int CurrentValue = 0; + + public async Task next() + { + //var user = await userDataService.IsLoggedInAsync(); + //user.IsLoggedIn = true; + //isUserLoggedIn = user.IsLoggedIn; + //user.UserType = (UserType)CurrentValue; + //navManager.NavigateTo("home"); + + } + + public void Submit() + { + + } +} diff --git a/TIAMSharedUI/Pages/Login_old.razor.css b/TIAMSharedUI/Pages/Login_old.razor.css new file mode 100644 index 00000000..a35d1811 --- /dev/null +++ b/TIAMSharedUI/Pages/Login_old.razor.css @@ -0,0 +1,7 @@ +.wrapper{ + max-width:400px; +} + +select :focus-visible { + border-color: transparent !important; +} \ No newline at end of file diff --git a/TIAMSharedUI/Pages/Settings.razor b/TIAMSharedUI/Pages/Settings.razor new file mode 100644 index 00000000..776aa6a0 --- /dev/null +++ b/TIAMSharedUI/Pages/Settings.razor @@ -0,0 +1,26 @@ +@page "/settings" +@using TIAMSharedUI.Pages.Components +@using TIAMSharedUI.Pages.User +@using TIAMWebApp.Shared.Application.Models.ClientSide; + +
+ +

@localizer["Settings.Title"]

+
+ + +
+ + @if (@UserIsLoggedIn) + { +
+
+ +
+ } + +
+ +@code { + +} diff --git a/TIAMSharedUI/Pages/Settings.razor.cs b/TIAMSharedUI/Pages/Settings.razor.cs new file mode 100644 index 00000000..2dca2026 --- /dev/null +++ b/TIAMSharedUI/Pages/Settings.razor.cs @@ -0,0 +1,50 @@ +using AyCode.Blazor.Components; +using AyCode.Interfaces.StorageHandlers; +using Microsoft.AspNetCore.Components; +using Microsoft.Extensions.Localization; +using TIAMSharedUI.Pages.Components; +using TIAMSharedUI.Resources; +using TIAMWebApp.Shared.Application.Interfaces; +using TIAMWebApp.Shared.Application.Models.ClientSide; + +namespace TIAMSharedUI.Pages +{ + public partial class Settings : ComponentBase + { + [Inject] + public ISecureStorageHandler? secureStorageHandler { get; set; } + + [Inject] + public IStringLocalizer? localizer { get; set; } + + [Inject] + public ISessionService sessionService { get; set; } + + public string Language { get; set; } = "en-US"; + private AuthComponent Auth; + private bool UserIsLoggedIn = false; + + protected override async Task OnInitializedAsync() + { + base.OnInitialized(); + UserIsLoggedIn = sessionService.IsAuthenticated; + GetCurrentSettings(); + } + + public void SaveSettings() + { + secureStorageHandler.SaveToSecureStorageAsync(Setting.Locale, "hu-HU"); + + } + + public void GetCurrentSettings() + { + secureStorageHandler.GetFromSecureStorageAsync(Setting.Locale); + } + + public void ResetSettings() + { + secureStorageHandler.DeleteFromSecureStorageAsync(Setting.Locale); + } + } +} diff --git a/TIAMSharedUI/Pages/TestPage.razor b/TIAMSharedUI/Pages/TestPage.razor index da7e5f6e..5c74e925 100644 --- a/TIAMSharedUI/Pages/TestPage.razor +++ b/TIAMSharedUI/Pages/TestPage.razor @@ -1,10 +1,13 @@ @page "/dbtest" +@using TIAMSharedUI.Pages.Components

TestPage


+ + @code { diff --git a/TIAMSharedUI/Pages/Tours.razor b/TIAMSharedUI/Pages/Tours.razor index 08a915a2..6407f943 100644 --- a/TIAMSharedUI/Pages/Tours.razor +++ b/TIAMSharedUI/Pages/Tours.razor @@ -1,10 +1,9 @@ @page "/tours" @using TIAMSharedUI.Shared - -
+
diff --git a/TIAMSharedUI/Pages/User/Admin.razor b/TIAMSharedUI/Pages/User/Admin.razor new file mode 100644 index 00000000..77b76f38 --- /dev/null +++ b/TIAMSharedUI/Pages/User/Admin.razor @@ -0,0 +1,833 @@ +@page "/admin" +@using TIAMSharedUI.Shared +@using TIAMWebApp.Shared.Application.Models; +@using TIAMWebApp.Shared.Application.Interfaces; +@layout AdminLayout +@inject IPopulationStructureDataProvider DataProvider +@inject ISupplierService SupplierService +@inject IUserDataService UserDataService +Transfer + +
+

Dashboard

+

Have a nice day!

+
+ + + +
+ + @{ + if(userType == 4) + { + +
+
+
+
+
+
+ Transfers +

Summary

+
+ +
+
+
+ +
New
+

12

+
Scheduled
+

182

+
Finished
+

15665

+ +
+ + + + +
+
+
+
+
+
+
+ Service providers +

Summary

+
+ +
+
+
+ +
Guides
+

32

+
Hotels
+

82

+
Restaurants
+

15

+
Transfer company
+

1

+ +
+ +
+
+
+
+
+
+
+ Finances +

Summary

+
+ +
+
+
+ +
Income
+

$32 456

+
Comission to be paid
+

$5 345

+
Service fees to be paid
+

$23 871

+
Revenue
+

$3 240

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

Summary

+
+ +
+
+
+ +
Top affiliate
+

Hotel Bambara

+
Comission Earned
+

$1 315

+
+
Top referred item
+

Buda castle tour

+
+
Level 1 affiliates
+

132

+ +
+ +
+
+
+
+
+
+
+ Hotel details + +
+ +
+
+
+
+ + + + + + + + + + + + + +
+
+ +
+
+
+
+
+
+
+ Population Data +

12,March 2020

+
+ +
+
+
+
+ + + + + + + + + +
+
@context.Point.Argument
+
Age Group: @context.Point.SeriesName
+
Population: @($"{context.Point.Value:N0}")
+
+
+
+ + + +
+ +
+ +
+ + + + + +
+
+
+
+
+
+ Affiliates +

Details

+
+ +
+
+
+ + + + + + + + + + + + + + + +
+ +
+
+
+ + + + + } + + else if(userType == 1) + { +
+ +
+
+
+
+
+ Hotel details + +
+ +
+
+
+
+
+
Your QR code
+

Use this in printed material, to gain referrals

+
+
+ +
+ +
+ +
+

Some conclusion

+
+
+ +
+
+
+
+
+
+
+ My orders + +
+ +
+
+
+
+ + + + + + @context.Value + + + + + + + + + + + +
+ +
+

Some conclusion

+
+
+ +
+
+
+
+
+
+
+ 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

+
+ +
+
+
+ + + + + + + + + + + + + + + +
+ +
+
+ +
+ + + } + } + + + + + + + + +
+
+
+
+
+
+ Panel title +

Subtitle

+
+ +
+
+
+
+
+
Some info
+

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

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

Some conclusion

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

Subtitle

+
+ +
+
+
+
+
+
Some info
+

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

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

Some conclusion

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

Subtitle

+
+ +
+
+
+
+
+
Some info
+

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

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

Some conclusion

+
+
+ +
+
+
+ +
+ +
+ +
+ + +@code { + + object? OrderData { get; set; } + object? AffiliateData { get; set; } + + IEnumerable? ChartsData; + + object? Data { get; set; } + + bool isUserLoggedIn; + int userType = 0; + + + + + protected override async Task OnInitializedAsync() + { + base.OnInitialized(); + + OrderData = new object[] + { + new { + Date = DateTime.Now.AddDays(3), + Income = "$5", + TransactionId = "POX987532582", + Status = "Finished" + }, + new { + Date = DateTime.Today.AddDays(-2), + Income = "$5", + TransactionId = "POX645646382", + Status = "Finished" + }, + new { + Date = DateTime.Today.AddDays(-6), + Income = "$8", + TransactionId = "POX645766311", + Status = "Finished" + }, + }; + + AffiliateData = new object[] + { + new { + AffiliateId = 1, + IncomeThisMonth = "$5", + IncomeAlltime = "9425", + CompanyName = "Upgen Ltd.", + Status = "Active" + }, + new { + AffiliateId = 2, + IncomeThisMonth = "$538", + IncomeAlltime = "13425", + CompanyName = "Kovacs hotel Ltd.", + Status = "Active" + }, + new { + AffiliateId = 3, + IncomeThisMonth = "$0", + IncomeAlltime = "134200", + CompanyName = "Innosaurus Ltd.", + Status = "Passive" + }, + }; + + + ChartsData = await DataProvider.QueryData(); + + var suppliers = await SupplierService.GetSuppliersAsync(); + Data = suppliers.Select(s => + { + return new + { + CompanyName = s.CompanyName, + ContactName = s.ContactName, + ContactTitle = s.ContactTitle, + Country = s.Country, + City = s.City, + Address = s.Address, + Phone = s.Phone + }; + }); + } + [Parameter] public bool ShowSeriesPointMarkers { get; set; } + [Parameter] public bool ShowSeriesLabels { get; set; } +} + diff --git a/TIAMSharedUI/Pages/User/Admin.razor.cs b/TIAMSharedUI/Pages/User/Admin.razor.cs new file mode 100644 index 00000000..b8ba5846 --- /dev/null +++ b/TIAMSharedUI/Pages/User/Admin.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 Home + { + } +} diff --git a/TIAMSharedUI/Pages/User/Properties.razor b/TIAMSharedUI/Pages/User/Properties.razor new file mode 100644 index 00000000..bed59c28 --- /dev/null +++ b/TIAMSharedUI/Pages/User/Properties.razor @@ -0,0 +1,5 @@ +

Properties

+ +@code { + +} diff --git a/TIAMSharedUI/Resources/MyResources.Designer.cs b/TIAMSharedUI/Resources/MyResources.Designer.cs new file mode 100644 index 00000000..2760776f --- /dev/null +++ b/TIAMSharedUI/Resources/MyResources.Designer.cs @@ -0,0 +1,279 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace TIAMSharedUI.Resources { + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + public class MyResources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal MyResources() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + public static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("TIAMSharedUI.Resources.MyResources", typeof(MyResources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + public static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// Looks up a localized string similar to Blehhhh. + /// + public static string Bleh { + get { + return ResourceManager.GetString("Bleh", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Clubcards. + /// + public static string Index_Clubcards { + get { + return ResourceManager.GetString("Index.Clubcards", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Join the club, and enjoy great offers during your stay!. + /// + public static string Index_Clubcards_Desc { + get { + return ResourceManager.GetString("Index.Clubcards.Desc", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Please select!. + /// + public static string Index_Subtitle { + get { + return ResourceManager.GetString("Index.Subtitle", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Welcome!. + /// + public static string Index_Title { + get { + return ResourceManager.GetString("Index.Title", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Tours. + /// + public static string Index_Tours { + get { + return ResourceManager.GetString("Index.Tours", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Are you curious about the wonderful sights of Budapest or Hungary? Book a guided tour now!. + /// + public static string Index_Tours_Desc { + get { + return ResourceManager.GetString("Index.Tours.Desc", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Transfer. + /// + public static string Index_Transfer { + get { + return ResourceManager.GetString("Index.Transfer", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Do you need a lift? Book a transfer now!. + /// + public static string Index_Transfer_Desc { + get { + return ResourceManager.GetString("Index.Transfer.Desc", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Email. + /// + public static string LoginEmail { + get { + return ResourceManager.GetString("LoginEmail", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Password. + /// + public static string LoginPassword { + get { + return ResourceManager.GetString("LoginPassword", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Let's get you inside!. + /// + public static string LoginTitleText { + get { + return ResourceManager.GetString("LoginTitleText", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Home. + /// + public static string NavMenu_Home { + get { + return ResourceManager.GetString("NavMenu.Home", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Login. + /// + public static string NavMenu_Login { + get { + return ResourceManager.GetString("NavMenu.Login", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Settings. + /// + public static string NavMenu_Settings { + get { + return ResourceManager.GetString("NavMenu.Settings", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Sign out. + /// + public static string NavMenu_SignOut { + get { + return ResourceManager.GetString("NavMenu.SignOut", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Transfer. + /// + public static string NavMenu_Transfer { + get { + return ResourceManager.GetString("NavMenu.Transfer", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Register. + /// + public static string RegisterRegister { + get { + return ResourceManager.GetString("RegisterRegister", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Language. + /// + public static string Settings_Language { + get { + return ResourceManager.GetString("Settings.Language", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Settings. + /// + public static string Settings_Title { + get { + return ResourceManager.GetString("Settings.Title", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Next. + /// + public static string Transfer_Next { + get { + return ResourceManager.GetString("Transfer.Next", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Previous. + /// + public static string Transfer_Previous { + get { + return ResourceManager.GetString("Transfer.Previous", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Start typing or swipe to select a preset destination!. + /// + public static string Transfer_Subtitle { + get { + return ResourceManager.GetString("Transfer.Subtitle", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Book a transfer. + /// + public static string Transfer_Title { + get { + return ResourceManager.GetString("Transfer.Title", resourceCulture); + } + } + } +} diff --git a/TIAMSharedUI/Resources/MyResources.hu.resx b/TIAMSharedUI/Resources/MyResources.hu.resx new file mode 100644 index 00000000..d383b021 --- /dev/null +++ b/TIAMSharedUI/Resources/MyResources.hu.resx @@ -0,0 +1,192 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Blehhhh + + + Klubkártyák + + + Csatlakozz a klubhoz, és élvezd az klubtagság nyújtotta előnyöket az ittléted alatt! + + + Válassz az alábbiak közül! + + + Üdvözlünk! + + + Vezetett túrák + + + Megnéznéd Budapest vagy Magyarország legszebb látványosságait? Foglalj vezetett túrát most! + + + Transzfer + + + Kéne egy fuvar? Foglalj most! + + + E-mail + + + Jelszó + + + Lépjünk csak be! + + + Főoldal + + + Belépés + + + Beállítások + + + Kijelentkezés + + + Transzfer + + + Regisztráció + + + Nyelv + + + Beállítások + + + Tovább + + + Vissza + + + Írj be valamit, vagy húzz balra előre elmentett uticélokért + + + Foglalj transzfert! + + \ No newline at end of file diff --git a/TIAMSharedUI/Resources/MyResources.resx b/TIAMSharedUI/Resources/MyResources.resx new file mode 100644 index 00000000..ee387179 --- /dev/null +++ b/TIAMSharedUI/Resources/MyResources.resx @@ -0,0 +1,192 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Blehhhh + + + Clubcards + + + Join the club, and enjoy great offers during your stay! + + + Please select! + + + Welcome! + + + Tours + + + Are you curious about the wonderful sights of Budapest or Hungary? Book a guided tour now! + + + Transfer + + + Do you need a lift? Book a transfer now! + + + Email + + + Password + + + Let's get you inside! + + + Home + + + Login + + + Settings + + + Sign out + + + Transfer + + + Register + + + Language + + + Settings + + + Next + + + Previous + + + Start typing or swipe to select a preset destination! + + + Book a transfer + + \ No newline at end of file diff --git a/TIAMSharedUI/Shared/Components/Navbar.razor b/TIAMSharedUI/Shared/Components/Navbar.razor new file mode 100644 index 00000000..03e2fe66 --- /dev/null +++ b/TIAMSharedUI/Shared/Components/Navbar.razor @@ -0,0 +1,74 @@ +@using TIAMSharedUI.Pages.Components +@using TIAMWebApp.Shared.Application.Interfaces +@using AyCode.Interfaces.StorageHandlers +@using Microsoft.Extensions.Localization +@inject ISecureStorageHandler SecureStorageHandler +@inject ISessionService sessionService; +@inject IStringLocalizer localizer + + + +@code { + +} diff --git a/TIAMSharedUI/Shared/Components/Navbar.razor.cs b/TIAMSharedUI/Shared/Components/Navbar.razor.cs new file mode 100644 index 00000000..9031007d --- /dev/null +++ b/TIAMSharedUI/Shared/Components/Navbar.razor.cs @@ -0,0 +1,64 @@ +using Microsoft.AspNetCore.Components; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using TIAMWebApp.Shared.Application.Interfaces; + +namespace TIAMSharedUI.Shared.Components +{ + public partial class Navbar : ComponentBase + { + + [Inject] + public NavigationManager navigationManager { get; set; } + + [Inject] + public IComponentUpdateService componentUpdateService { get; set; } + + private bool collapseNavMenu = true; + private bool myUser = false; + private string? NavMenuCssClass => collapseNavMenu ? "collapse" : null; + + //componentUpdateService.RefreshRequested += RefreshMe; + + + private void RefreshMe() + { + StateHasChanged(); + } + + private void ToggleNavMenu() + { + collapseNavMenu = !collapseNavMenu; + } + + private void NavigateBack() + { + + } + + private void SignOut() + { + SecureStorageHandler.ClearAllSecureStorageAsync(); + sessionService.User = null; + sessionService.IsAuthenticated = false; + } + + protected override void OnInitialized() + { + base.OnInitialized(); + if (sessionService.User != null) + { + myUser = true; + } + else + { + myUser = false; + } + componentUpdateService.RefreshRequested += RefreshMe; + } + + } +} diff --git a/TIAMSharedUI/Shared/Components/Navbar.razor.css b/TIAMSharedUI/Shared/Components/Navbar.razor.css new file mode 100644 index 00000000..cbb81c4c --- /dev/null +++ b/TIAMSharedUI/Shared/Components/Navbar.razor.css @@ -0,0 +1,80 @@ +.navbar-toggler { + background-color: rgba(255, 255, 255, 0.1); + padding: 0px; +} + +.top-row { + height: 3.5rem; +} + +.navbar-brand { + font-size: 1.1rem; +} + +.oi { + width: 2rem; + font-size: 1.1rem; + vertical-align: text-top; + top: -2px; +} + +.oi-2 { + width: 2rem; + font-size: 1.1rem; + vertical-align: text-top; + top: -2px; +} + +.nav-item { + font-size: large; + margin: auto; + display: flex; + align-content: center; +} + + /*.nav-item:first-of-type { + padding-top: 1rem; + } + + .nav-item:last-of-type { + padding-bottom: 1rem; + }*/ + + .nav-item ::deep a { + color: #58457b; + /*border-radius: 15px;*/ + height: 3rem; + display: flex; + align-items: center; + line-height: 3rem; + margin: auto; + padding-left: 30px; + padding-right: 30px; + } + + .nav-item ::deep a.active { + /*background-color: #475bd6;*/ + color: #475bd6; + } + + .nav-item ::deep a:hover { + /*background-color: #f7279f;*/ + color: #f7279f; + } + +@media (min-width: 641px) { + .navbar-toggler { + display: none; + } + + .collapse { + /* Never collapse the sidebar for wide screens */ + display: block; + } + + .nav-scrollable { + /* Allow sidebar to scroll for tall menus */ + height: calc(100vh - 3.5rem); + overflow-y: auto; + } +} diff --git a/TIAMSharedUI/Shared/MainLayout.razor b/TIAMSharedUI/Shared/MainLayout.razor index d256323f..9c6109c8 100644 --- a/TIAMSharedUI/Shared/MainLayout.razor +++ b/TIAMSharedUI/Shared/MainLayout.razor @@ -1,6 +1,7 @@ @inherits LayoutComponentBase @using AyCode.Interfaces.StorageHandlers; @using Newtonsoft.Json; +@using TIAMSharedUI.Shared.Components @using TIAMWebApp.Shared.Application.Interfaces @using TIAMWebApp.Shared.Application.Models.ClientSide; @using AyCode.Blazor.Components; @@ -8,23 +9,23 @@ @using TIAMWebApp.Shared.Application.Utility; @using System.IdentityModel.Tokens.Jwt; @inject NavigationManager NavManager -@inject IUserDataService UserDataService; @inject IJSRuntime jsRuntime; @inject ISecureStorageHandler SecureStorageHandler @inject ISessionService sessionService; -
+ + +
-
+ +
- @if (Setting.UserBasicDetails != null) - { - - } + + @Body
@@ -35,4 +36,5 @@ @code { + } diff --git a/TIAMSharedUI/Shared/NavMenu.razor b/TIAMSharedUI/Shared/NavMenu.razor index e0a7b03d..1779cda6 100644 --- a/TIAMSharedUI/Shared/NavMenu.razor +++ b/TIAMSharedUI/Shared/NavMenu.razor @@ -1,6 +1,8 @@ @using TIAMWebApp.Shared.Application.Interfaces -@using AyCode.Interfaces.StorageHandlers; +@using AyCode.Interfaces.StorageHandlers +@using Microsoft.Extensions.Localization @inject ISecureStorageHandler SecureStorageHandler +@inject IStringLocalizer localizer