Esempio n. 1
0
        private void MakeStaffAbsent(AttendanceDbContext dbContext, DateTime processDate)
        {
            //DateTime processDate = DateTime.Now.Date;
            if (!dbContext.StaffAttendences.Any(x => x.date == processDate))
            {
                logger.Info($"Make Staff Absent (Date: {processDate}) - Start".ToUpper());
                var staffs             = dbContext.Staffs.Where(x => x.is_active > 0).ToList();
                int attendance_type_id = GetAttendanceType(false, dbContext, processDate);

                foreach (var staff in staffs)
                {
                    dbContext.StaffAttendences.Add(new Data.Models.StaffAttendence
                    {
                        staff_id = staff.id,
                        staff_attendance_type_id = attendance_type_id,
                        date       = processDate,
                        is_active  = 0,
                        remark     = "",
                        created_at = DateTime.Now,
                        updated_at = DateTime.Now
                    });
                }

                dbContext.SaveChanges();
                logger.Info($"Make Staff Absent - End".ToUpper());
            }
        }
Esempio n. 2
0
        public static void SeedHostDb(AttendanceDbContext context)
        {
            context.SuppressAutoSetTenantId = true;

            //Host seed
            new InitialHostDbBuilder(context).Create();

            //Default tenant seed (in host database).
            new DefaultTenantBuilder(context).Create();
            new TenantRoleAndUserBuilder(context, 1).Create();

            if (!context.SystemConfigurations.Any())
            {
                var systemConfigurationToAdd = new SystemConfiguration();
                systemConfigurationToAdd.TotalPermissionNumberPerDay   = 0;
                systemConfigurationToAdd.TotalPermissionNumberPerMonth = 0;
                systemConfigurationToAdd.TotalPermissionNumberPerWeek  = 0;
                systemConfigurationToAdd.TotalPermissionHoursPerWeek   = 0;
                systemConfigurationToAdd.TotalPermissionHoursPerDay    = 0;
                systemConfigurationToAdd.TotalPermissionHoursPerMonth  = 0;

                context.SystemConfigurations.Add(systemConfigurationToAdd);
                context.SaveChanges();
            }
        }
Esempio n. 3
0
        private void MakeStudentAbsent(AttendanceDbContext dbContext, DateTime processDate)
        {
            //DateTime processDate = DateTime.Now.Date;
            if (!dbContext.StudentAttendences.Any(x => x.date == processDate))
            {
                logger.Info($"Make Student Absent (Date: {processDate}) - Start".ToUpper());

                var students = dbContext.Students.Where(x => x.is_active == "yes")
                               .Include(x => x.StudentSessions)
                               .ToList();

                int attendance_type_id = GetAttendanceType(true, dbContext, processDate);

                foreach (var student in students)
                {
                    int sessionId = student.StudentSessions.Last().id;

                    dbContext.StudentAttendences.Add(new Data.Models.StudentAttendence
                    {
                        student_session_id = sessionId,
                        attendence_type_id = attendance_type_id,
                        date       = processDate,
                        is_active  = "no",
                        remark     = "",
                        created_at = DateTime.Now,
                        updated_at = DateTime.Now
                    });
                }

                dbContext.SaveChanges();
                logger.Info($"Make Student Absent - End".ToUpper());
            }
        }
        public virtual int InsertWithReturn(TEntity entity)
        {
            var newRecord = dbSet.Add(entity);

            context.SaveChanges();
            return(newRecord.Entity.Id);
        }
Esempio n. 5
0
        public void Create()
        {
            new TestOrganizationUnitsBuilder(_context, _tenantId).Create();
            new TestSubscriptionPaymentBuilder(_context, _tenantId).Create();
            new TestEditionsBuilder(_context).Create();

            _context.SaveChanges();
        }
Esempio n. 6
0
        public void Create()
        {
            new DefaultEditionCreator(_context).Create();
            new DefaultLanguagesCreator(_context).Create();
            new HostRoleAndUserCreator(_context).Create();
            new DefaultSettingsCreator(_context).Create();

            _context.SaveChanges();
        }
Esempio n. 7
0
        private void AddSettingIfNotExists(string name, string value, int?tenantId = null)
        {
            if (_context.Settings.IgnoreQueryFilters().Any(s => s.Name == name && s.TenantId == tenantId && s.UserId == null))
            {
                return;
            }

            _context.Settings.Add(new Abp.Configuration.Setting(tenantId, null, name, value));
            _context.SaveChanges();
        }
Esempio n. 8
0
        private void AddLanguageIfNotExists(ApplicationLanguage language)
        {
            if (_context.Languages.IgnoreQueryFilters().Any(l => l.TenantId == language.TenantId && l.Name == language.Name))
            {
                return;
            }

            _context.Languages.Add(language);

            _context.SaveChanges();
        }
        private OrganizationUnit CreateOrganizationUnit(string displayName, string code, long?parentId = null)
        {
            var organizationUnit = _context.OrganizationUnits.Add(new OrganizationUnit(_tenantId, displayName, parentId)
            {
                Code = code
            }).Entity;

            _context.SaveChanges();

            return(organizationUnit);
        }
Esempio n. 10
0
        private void CreateDefaultTenant()
        {
            //Default tenant

            var defaultTenant = _context.Tenants.IgnoreQueryFilters().FirstOrDefault(t => t.TenancyName == MultiTenancy.Tenant.DefaultTenantName);

            if (defaultTenant == null)
            {
                defaultTenant = new MultiTenancy.Tenant(AbpTenantBase.DefaultTenantName, AbpTenantBase.DefaultTenantName);

                var defaultEdition = _context.Editions.IgnoreQueryFilters().FirstOrDefault(e => e.Name == EditionManager.DefaultEditionName);
                if (defaultEdition != null)
                {
                    defaultTenant.EditionId = defaultEdition.Id;
                }

                _context.Tenants.Add(defaultTenant);
                _context.SaveChanges();
            }
        }
Esempio n. 11
0
        private void CreateEditions()
        {
            var defaultEdition = _context.Editions.IgnoreQueryFilters().FirstOrDefault(e => e.Name == EditionManager.DefaultEditionName);

            if (defaultEdition == null)
            {
                defaultEdition = new SubscribableEdition {
                    Name = EditionManager.DefaultEditionName, DisplayName = EditionManager.DefaultEditionName
                };
                _context.Editions.Add(defaultEdition);
                _context.SaveChanges();

                /* Add desired features to the standard edition, if wanted... */
            }

            if (defaultEdition.Id > 0)
            {
                CreateFeatureIfNotExists(defaultEdition.Id, AppFeatures.ChatFeature, true);
                CreateFeatureIfNotExists(defaultEdition.Id, AppFeatures.TenantToTenantChatFeature, true);
                CreateFeatureIfNotExists(defaultEdition.Id, AppFeatures.TenantToHostChatFeature, true);
            }
        }
Esempio n. 12
0
        private void CreateHostRoleAndUsers()
        {
            //Admin role for host

            var adminRoleForHost = _context.Roles.IgnoreQueryFilters().FirstOrDefault(r => r.TenantId == null && r.Name == StaticRoleNames.Host.Admin);

            if (adminRoleForHost == null)
            {
                adminRoleForHost = _context.Roles.Add(new Role(null, StaticRoleNames.Host.Admin, StaticRoleNames.Host.Admin)
                {
                    IsStatic = true, IsDefault = true
                }).Entity;
                _context.SaveChanges();
            }

            //admin user for host

            var adminUserForHost = _context.Users.IgnoreQueryFilters().FirstOrDefault(u => u.TenantId == null && u.UserName == AbpUserBase.AdminUserName);

            if (adminUserForHost == null)
            {
                var user = new User
                {
                    TenantId         = null,
                    UserName         = AbpUserBase.AdminUserName,
                    Name             = "admin",
                    Surname          = "admin",
                    EmailAddress     = "*****@*****.**",
                    IsEmailConfirmed = true,
                    ShouldChangePasswordOnNextLogin = false,
                    IsActive = true,
                    Password = "******" //123qwe
                };

                user.SetNormalizedNames();

                adminUserForHost = _context.Users.Add(user).Entity;
                _context.SaveChanges();

                //Assign Admin role to admin user
                _context.UserRoles.Add(new UserRole(null, adminUserForHost.Id, adminRoleForHost.Id));
                _context.SaveChanges();

                //User account of admin user
                _context.UserAccounts.Add(new UserAccount
                {
                    TenantId     = null,
                    UserId       = adminUserForHost.Id,
                    UserName     = AbpUserBase.AdminUserName,
                    EmailAddress = adminUserForHost.EmailAddress
                });

                _context.SaveChanges();

                //Notification subscriptions
                _context.NotificationSubscriptions.Add(new NotificationSubscriptionInfo(SequentialGuidGenerator.Instance.Create(), null, adminUserForHost.Id, AppNotificationNames.NewTenantRegistered));
                _context.NotificationSubscriptions.Add(new NotificationSubscriptionInfo(SequentialGuidGenerator.Instance.Create(), null, adminUserForHost.Id, AppNotificationNames.NewUserRegistered));

                _context.SaveChanges();
            }
        }
Esempio n. 13
0
        private void CreateRolesAndUsers()
        {
            //Admin role

            var adminRole = _context.Roles.IgnoreQueryFilters().FirstOrDefault(r => r.TenantId == _tenantId && r.Name == StaticRoleNames.Tenants.Admin);

            if (adminRole == null)
            {
                adminRole = _context.Roles.Add(new Role(_tenantId, StaticRoleNames.Tenants.Admin, StaticRoleNames.Tenants.Admin)
                {
                    IsStatic = true
                }).Entity;
                _context.SaveChanges();
            }

            //User role

            var userRole = _context.Roles.IgnoreQueryFilters().FirstOrDefault(r => r.TenantId == _tenantId && r.Name == StaticRoleNames.Tenants.User);

            if (userRole == null)
            {
                _context.Roles.Add(new Role(_tenantId, StaticRoleNames.Tenants.User, StaticRoleNames.Tenants.User)
                {
                    IsStatic = true, IsDefault = true
                });
                _context.SaveChanges();
            }

            //admin user

            var adminUser = _context.Users.IgnoreQueryFilters().FirstOrDefault(u => u.TenantId == _tenantId && u.UserName == AbpUserBase.AdminUserName);

            if (adminUser == null)
            {
                adminUser                  = User.CreateTenantAdminUser(_tenantId, "*****@*****.**");
                adminUser.Password         = new PasswordHasher <User>(new OptionsWrapper <PasswordHasherOptions>(new PasswordHasherOptions())).HashPassword(adminUser, "123qwe");
                adminUser.IsEmailConfirmed = true;
                adminUser.ShouldChangePasswordOnNextLogin = false;
                adminUser.IsActive = true;

                _context.Users.Add(adminUser);
                _context.SaveChanges();

                //Assign Admin role to admin user
                _context.UserRoles.Add(new UserRole(_tenantId, adminUser.Id, adminRole.Id));
                _context.SaveChanges();

                //User account of admin user
                if (_tenantId == 1)
                {
                    _context.UserAccounts.Add(new UserAccount
                    {
                        TenantId     = _tenantId,
                        UserId       = adminUser.Id,
                        UserName     = AbpUserBase.AdminUserName,
                        EmailAddress = adminUser.EmailAddress
                    });
                    _context.SaveChanges();
                }

                //Notification subscription
                _context.NotificationSubscriptions.Add(new NotificationSubscriptionInfo(SequentialGuidGenerator.Instance.Create(), _tenantId, adminUser.Id, AppNotificationNames.NewUserRegistered));
                _context.SaveChanges();
            }
        }
Esempio n. 14
0
        private void ProcessDailyAttendanceLog()
        {
            bool isValidTimeRange = ((DateTime.Now.TimeOfDay > this.AttendanceConfig.job_start_time &&
                                      DateTime.Now.TimeOfDay < this.AttendanceConfig.job_end_time) ||
                                     DateTime.Now.TimeOfDay > (new TimeSpan(23, 54, 00)));

            if (!(isValidTimeRange &&
                  this.ProcessAttendanceLog_LastRunTime.AddMinutes(this.AttendanceConfig.interval_minute) < DateTime.Now &&
                  !this.IsBusy))
            {
                return;
            }

            logger.Info($"Process Attendance Log - Start".ToUpper());

            this.IsBusy = true;


            this.ProcessAttendanceLog_LastRunTime = DateTime.Now;
            DateTime lastProcessDate = DateTime.MinValue;
            ICollection <BiometricLogModel> biometricLogData = new HashSet <BiometricLogModel>();



            try
            {
                logger.Info($"Get Biometric Data - Start");


                using (ZkTecoClient biometricClient = new ZkTecoClient("basecampzkteco.ddns.net"))
                {
                    biometricLogData         = biometricClient.GetBiometricData();
                    SentBiometricDeviceError = false;
                    logger.Info($"{biometricLogData.Count} records found.");
                }

                logger.Info("Get Biometric Data - End");

                using (AttendanceDbContext dbContext = new AttendanceDbContext())
                {
                    if (dbContext.BiometricLogs.Any())
                    {
                        lastProcessDate = dbContext.BiometricLogs.Max(x => x.datetime_record);
                    }

                    biometricLogData = biometricLogData.Where(x => x.DateTimeRecord > lastProcessDate)
                                       .OrderBy(x => x.DateTimeRecord).ToList();


                    try
                    {
                        foreach (var log in biometricLogData)
                        {
                            dbContext.BiometricLogs.Add(new Data.Models.BiometricLog
                            {
                                machine_id      = log.MachineNumber,
                                ind_reg_iD      = log.IndRegID,
                                datetime_record = log.DateTimeRecord
                            });
                        }

                        ///Save BiometricLogs
                        dbContext.SaveChanges();

                        ICollection <BiometricLog> unprocessedBiometricLogData = dbContext.BiometricLogs
                                                                                 .Where(x => !x.is_processed).OrderBy(x => x.datetime_record).ToList();

                        foreach (DateTime date in unprocessedBiometricLogData.Select(x => x.datetime_record.Date).Distinct())
                        {
                            this.MakeStudentAbsent(dbContext, date);
                            this.MakeStaffAbsent(dbContext, date);
                        }

                        foreach (var log in unprocessedBiometricLogData)
                        {
                            try
                            {
                                bool isStudentLog = this.UpdateStudentAttendanceStatus(log, dbContext);
                                if (!isStudentLog)
                                {
                                    this.UpdateStaffAttendanceStatus(log, dbContext);
                                }

                                log.is_processed = true;

                                dbContext.SaveChanges();
                            }
                            catch (Exception ex)
                            {
                                logger.Info(ex.Message, ex);
                            }
                        }
                        //Update Student/Staff Attendance Status
                        dbContext.SaveChanges();
                    }
                    catch (Exception ex)
                    {
                        logger.Info(ex.Message, ex);
                    }
                }
            }
            catch (ZkTecoClientException ex)
            {
                if (!this.SentBiometricDeviceError)
                {
                    this.SentBiometricDeviceError = true;
                    this.SendServiceStetusSms(ex.Message);
                }

                logger.Error(ex.Message, ex);
            }
            catch (Exception ex)
            {
                logger.Error(ex.Message, ex);
            }
            finally
            {
                this.IsBusy = false;
                logger.Info($"Process Attendance Log - End".ToUpper());
            }
        }
 public void Commit()
 {
     _dbContext.SaveChanges();
 }
Esempio n. 16
0
 public bool Commit()
 {
     return(_dbContext.SaveChanges() >= 0);
 }
 public void Add(T entity)
 {
     _dbContext.Set <T>().Add(entity);
     _dbContext.SaveChanges();
 }