예제 #1
0
        public async Task <string> GeneratePasswordResetToken(string connectionString, string email)
        {
            if (string.IsNullOrEmpty(connectionString))
            {
                throw new ArgumentException("connection string not provided!");
            }

            var printingBIDbContextFactory = new PrintingBIDbContextFactory();
            var context = printingBIDbContextFactory.Create(connectionString);

            var user = context.PrinterBIUsers.FirstOrDefault(m => m.Email == email);

            if (user == null)
            {
                return(string.Empty);
            }

            string token = Guid.NewGuid().ToString();

            user.Token           = token;
            user.TokenExpiryDate = DateTime.Now.AddHours(3);
            context.Update(user);
            await context.SaveChangesAsync();

            return(token);
        }
예제 #2
0
        public async Task <string> ResetUserPassByToken(string connectionString, string email, string token, string password)
        {
            if (string.IsNullOrEmpty(connectionString))
            {
                throw new ArgumentException("connection string not provided!");
            }

            var printingBIDbContextFactory = new PrintingBIDbContextFactory();
            var context = printingBIDbContextFactory.Create(connectionString);

            var user = context.PrinterBIUsers.FirstOrDefault(m => m.Email == email);

            if (user != null)
            {
                if (user.Token == token && user.TokenExpiryDate > DateTime.Now)
                {
                    user.Password        = password;
                    user.Token           = null;
                    user.TokenExpiryDate = null;

                    context.Update(user);
                    await context.SaveChangesAsync();

                    return(string.Empty);
                }
                return("Invalid Token or Token is expired");
            }
            return("Invalid Email");
        }
예제 #3
0
        public async Task <IEnumerable <PrinterBIReportMaster> > GetAllReports(string connectionString)
        {
            if (string.IsNullOrEmpty(connectionString))
            {
                throw new ArgumentException("connection string not provided!");
            }

            var printingBIDbContextFactory = new PrintingBIDbContextFactory();
            var context = printingBIDbContextFactory.Create(connectionString);

            return(await context.PrinterBIReportMaster.ToListAsync());
        }
예제 #4
0
        public async Task <List <PrinterBIDepartment> > GetDepartmentList(string connectionString)
        {
            if (string.IsNullOrEmpty(connectionString))
            {
                throw new ArgumentException("connection string not provided!");
            }

            var printingBIDbContextFactory = new PrintingBIDbContextFactory();
            var context = printingBIDbContextFactory.Create(connectionString);

            return(await context.PrinterBIDepartments.ToListAsync());
        }
예제 #5
0
        public async Task <bool> AuthenticateUserByEmail(string connectionString, string Email)
        {
            if (string.IsNullOrEmpty(connectionString))
            {
                throw new ArgumentException("connection string not provided!");
            }

            var printingBIDbContextFactory = new PrintingBIDbContextFactory();
            var context = printingBIDbContextFactory.Create(connectionString);

            bool result = context.PrinterBIUsers.Any(m => m.Email == Email);

            return(result);
        }
예제 #6
0
        public async Task <(bool, string)> DeProvision(string connectionString)
        {
            if (string.IsNullOrEmpty(connectionString))
            {
                throw new ArgumentException("connection string not provided!");
            }

            var printingBIDbContextFactory = new PrintingBIDbContextFactory();
            var context = printingBIDbContextFactory.Create(connectionString);

            var tablesToDrop = CreateDropTablesScript();
            await context.Database.ExecuteSqlCommandAsync(tablesToDrop);

            return(true, "De-Provisioned successfully.");
        }
예제 #7
0
        public async Task Insert(string connectionString, IEnumerable <PrinterBIDepartment> departments)
        {
            if (string.IsNullOrEmpty(connectionString))
            {
                throw new ArgumentException("connection string not provided!");
            }

            var printingBIDbContextFactory = new PrintingBIDbContextFactory();
            var context = printingBIDbContextFactory.Create(connectionString);

            var oldDepts = await context.PrinterBIDepartments.ToListAsync();

            context.PrinterBIDepartments.RemoveRange(oldDepts);
            await context.SaveChangesAsync();

            await context.PrinterBIDepartments.AddRangeAsync(departments);

            await context.SaveChangesAsync();
        }
예제 #8
0
        public async Task <bool> ValidateDBInfo(string connectionString)
        {
            try
            {
                if (string.IsNullOrEmpty(connectionString))
                {
                    throw new ArgumentException("connection string not provided!");
                }

                var printingBIDbContextFactory = new PrintingBIDbContextFactory();
                var context = printingBIDbContextFactory.Create(connectionString);

                bool result = context.Database.CanConnect();

                return(result);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
예제 #9
0
        public async Task <(bool, string)> Provision(string connectionString)
        {
            if (string.IsNullOrEmpty(connectionString))
            {
                throw new ArgumentException("connection string not provided!");
            }

            var printingBIDbContextFactory = new PrintingBIDbContextFactory();
            var context = printingBIDbContextFactory.Create(connectionString);

            // Drop table if exists here

            //var tablesToDrop = await File.ReadAllTextAsync("ProvisionScripts/DropTablesIfExists.sql");

            var tablesToDrop = CreateDropTablesScript();
            await context.Database.ExecuteSqlCommandAsync(tablesToDrop);

            var createAllTablesScript = context.Database.GenerateCreateScript();
            await context.Database.ExecuteSqlCommandAsync(createAllTablesScript);

            return(true, "Provisioned successfully.");
        }
예제 #10
0
        public async Task Insert(string connectionString, IEnumerable <PrinterBIUser> users)
        {
            if (string.IsNullOrEmpty(connectionString))
            {
                throw new ArgumentException("connection string not provided!");
            }

            var printingBIDbContextFactory = new PrintingBIDbContextFactory();
            var context = printingBIDbContextFactory.Create(connectionString);

            var oldUsers = await context
                           .PrinterBIUsers
                           .Where(w => !w.IsSuperAdmin)
                           .ToListAsync();

            context.PrinterBIUsers.RemoveRange(oldUsers);
            await context.SaveChangesAsync();

            await context.PrinterBIUsers.AddRangeAsync(users);

            await context.SaveChangesAsync();
        }
예제 #11
0
        public async Task <bool> SyncReports(string connectionString, IEnumerable <PrinterBIReportMaster> newReports)
        {
            if (string.IsNullOrEmpty(connectionString))
            {
                throw new ArgumentException("connection string not provided!");
            }

            var printingBIDbContextFactory = new PrintingBIDbContextFactory();
            var context = printingBIDbContextFactory.Create(connectionString);

            var oldReports = await context
                             .PrinterBIReportMaster
                             .ToListAsync();

            context.PrinterBIReportMaster.RemoveRange(oldReports);
            await context.SaveChangesAsync();

            await context.PrinterBIReportMaster.AddRangeAsync(newReports);

            await context.SaveChangesAsync();

            return(true);
        }
예제 #12
0
        public async Task <bool> ChangeUserPassword(string connectionString, string email, string oldPass, string newPass)
        {
            if (string.IsNullOrEmpty(connectionString))
            {
                throw new ArgumentException("connection string not provided!");
            }

            var printingBIDbContextFactory = new PrintingBIDbContextFactory();
            var context = printingBIDbContextFactory.Create(connectionString);

            var user = context.PrinterBIUsers.FirstOrDefault(m => m.Email == email && m.Password == oldPass);

            if (user != null)
            {
                user.Password     = newPass;
                user.IsPassChange = true;

                context.Update(user);
                await context.SaveChangesAsync();

                return(true);
            }
            return(false);
        }
예제 #13
0
        public async Task <AuthenticateUserResultDto> AuthenticateUser(string connectionString, string userNameOrEmail, string password, int refreshTokenExpiry)
        {
            if (string.IsNullOrEmpty(connectionString))
            {
                throw new ArgumentException("connection string not provided!");
            }


            var printingBIDbContextFactory = new PrintingBIDbContextFactory();
            var context = printingBIDbContextFactory.Create(connectionString);

            var user = context.PrinterBIUsers
                       .FirstOrDefault(m => m.UserName.ToLower() == userNameOrEmail.ToLower() ||
                                       m.Email.ToLower() == userNameOrEmail.ToLower());

            if (user == null)
            {
                return new AuthenticateUserResultDto {
                           IsAuthenticated = false, IsSuperAdmin = false, IsPasswordChange = false
                }
            }
            ;

            if (user.Password != password)
            {
                return new AuthenticateUserResultDto {
                           IsAuthenticated = false, IsSuperAdmin = false, IsPasswordChange = false
                }
            }
            ;

            else
            {
                string refreshToken = Guid.NewGuid().ToString();

                user.RefreshToken           = refreshToken;
                user.RefreshTokenExpiryDate = DateTime.Now.AddMinutes(refreshTokenExpiry);
                context.PrinterBIUsers.Update(user);
                context.SaveChanges();

                AuthenticateUserResultDto obj = new AuthenticateUserResultDto();
                obj.IsAuthenticated = true;
                obj.RefreshToken    = refreshToken;
                obj.Email           = user.Email;
                obj.FullName        = user.FullName;
                obj.UserName        = user.UserName;
                obj.UserId          = user.Id;

                if (user.DepartmentId.HasValue)
                {
                    obj.DepartmentId = user.DepartmentId.ToString();
                }

                if (user.RoleRightsId.HasValue)
                {
                    obj.RoleRightsId = user.RoleRightsId.ToString();
                }

                if (user.IsSuperAdmin)
                {
                    obj.IsSuperAdmin = true;
                }
                else
                {
                    obj.IsSuperAdmin = false;
                }

                if (user.IsPassChange)
                {
                    obj.IsPasswordChange = true;
                }
                else
                {
                    obj.IsPasswordChange = false;
                }
                return(obj);
            }
        }
예제 #14
0
        public CustomerDbContext(ICustomerDbInfo customerDbInfo)
        {
            var printingBIDbContextFactory = new PrintingBIDbContextFactory();

            Context = printingBIDbContextFactory.Create(customerDbInfo.GetCustomerDbConnectionString());
        }