Ejemplo n.º 1
0
 public AccountController(LockerDbContext lockerDbContext, IUserService userService, IAdminService adminService)
 {
     _userService  = userService;
     _adminService = adminService;
     _dbContext    = lockerDbContext;
     _accountRepo  = new AccountRepository(_dbContext);
 }
Ejemplo n.º 2
0
        protected override string Schedule => "*/1 * * * *"; // every minute

        public override Task ProcessInScope(IServiceProvider serviceProvider, DbContextOptions <LockerDbContext> dbOption)
        {
            try
            {
                _dbContext = new LockerDbContext(dbOption);

                TimeZoneInfo zone     = TimeZoneInfo.FindSystemTimeZoneById("SE Asia Standard Time");
                DateTime     dateTime = TimeZoneInfo.ConvertTime(DateTime.Now, zone);

                //get active reservation
                var reservelist = from row in _dbContext.reservations
                                  where row.IsActive == true
                                  select row;

                if (reservelist == null)
                {
                    Log.Information("Check five mins every minute {0} No data to set.", dateTime);
                }
                else
                {
                    foreach (var run in reservelist)
                    {
                        //if there is no notification in each reservation
                        if (_dbContext.notifications.FirstOrDefault(x => x.Id_reserve == run.Id_reserve && x.Id_content == _appSettings.FiveContent) == null)
                        {
                            //check different time = 5 minutes
                            TimeSpan diff = (run.EndDay - dateTime).Duration();
                            if (diff.TotalMinutes < 6 && diff.TotalMinutes > 4)
                            {
                                Notification notification = new Notification()
                                {
                                    Id_account = run.Id_account,
                                    CreateTime = dateTime,
                                    Id_content = _appSettings.FiveContent,
                                    Id_reserve = run.Id_reserve,
                                    IsShow     = true,
                                    Read       = false
                                };
                                _dbContext.notifications.Add(notification);
                                _dbContext.SaveChanges();
                                SendPushNotification(_dbContext.accounts.FirstOrDefault(x => x.Id_account == run.Id_account).ExpoToken);
                                Log.Information("Check five mins every 1 mins {0} {1} Data to be set and create notification.", dateTime, run.Id_reserve);
                            }
                        }
                    }
                }
            }
            catch
            {
                TimeZoneInfo zone     = TimeZoneInfo.FindSystemTimeZoneById("SE Asia Standard Time");
                DateTime     dateTime = TimeZoneInfo.ConvertTime(DateTime.Now, zone);
                Log.Information("Check five mins every minute {0} Error.", dateTime);
            }
            return(Task.CompletedTask);
        }
        public Guid? GetLockerBankByCode(string lockerBankCode)
        {
            LockerDbContext context = new LockerDbContext(_connectionStringFactory.GetConnectionString());

            var lockerBankId = context.LockerBanks
                                    .Where(bank => bank.LockerBankCode.ToLower() == lockerBankCode.ToLower())
                                    .Select(bank => bank.LockerBankId)
                                    .FirstOrDefault();

            return lockerBankId;
        }
        public List<LockerDto> GetAllLockers(Guid lockerBankId)
        {
            LockerDbContext context = new LockerDbContext(_connectionStringFactory.GetConnectionString());

            var lockersList = context.Lockers
                            .Where(locker => locker.LockerBankId == lockerBankId && locker.State != LockerState.Deleted)
                            .Select(locker => new LockerDto
                            {
                                LockerId = locker.LockerId,
                                LockerBankId = locker.LockerBankId,
                                LockerOfflineReasonId = locker.LockerOfflineReasonId,
                                Size = locker.Size,
                                State = locker.State,
                                Column=locker.Column,
                                LockerNumber=locker.LockerNumber,
                                DeviceSerialNumber=locker.DevicesInLocker.Select(lToD=>lToD.DeviceData.SerialNumber).FirstOrDefault()
                            }).ToList();

            return lockersList;
        }
        public LockerAndDeviceDto GetDeviceSerialNumberForLocker(Guid lockerBankId, Guid lockerId)
        {
            LockerDbContext context = new LockerDbContext(_connectionStringFactory.GetConnectionString());

            var lockerBank = context.LockerBanks
                                    .Where(bank => bank.LockerBankId == lockerBankId)
                                    .FirstOrDefault();

            var deviceAddress = context.LockerToDevices
                                        .Where(loc => loc.LockerId == lockerId)
                                        .Select(loc => loc.DeviceData.SerialNumber)
                                        .FirstOrDefault();

            var dto = new LockerAndDeviceDto
            {
                LockerBankId = lockerBank.LockerBankId,
                LockerBankCode = lockerBank.LockerBankCode,
                LockerBankIpAddress = lockerBank.IpAddress,
                DeviceSerialNumber = deviceAddress

            };

            return dto;
        }
Ejemplo n.º 6
0
 public LockerMetadataController(LockerDbContext lockerDbContext)
 {
     _dbContext  = lockerDbContext;
     _lockerRepo = new LockerMetadataRepository(_dbContext);
 }
Ejemplo n.º 7
0
 public AccountRepository(LockerDbContext dbContext)
 {
     _dbContext = dbContext;
 }
Ejemplo n.º 8
0
 public AdminService(LockerDbContext dbContext, IOptions <AppSettings> appSettings)
 {
     _dbContext   = dbContext;
     _appSettings = appSettings.Value;
 }
Ejemplo n.º 9
0
 public ContentController(LockerDbContext lockerDbContext)
 {
     _dbContext   = lockerDbContext;
     _contentRepo = new ContentRepository(_dbContext);
 }
Ejemplo n.º 10
0
 public ReservationRepository(LockerDbContext dbContext)
 {
     _dbContext = dbContext;
 }
Ejemplo n.º 11
0
 public ContentRepository(LockerDbContext dbContext)
 {
     _dbContext = dbContext;
 }
        public void UpdateLockerAsOccupied(Guid lockerBankId, Guid lockerId)
        {
            LockerDbContext context = new LockerDbContext(_connectionStringFactory.GetConnectionString());

            var locker=context.Lockers.FirstOrDefault(lo => lo.LockerId == lockerId && lo.LockerBankId == lockerBankId);

            if(locker==null)
            {
                throw new ApplicationException("Locker not present in system for update");
            }

            locker.State = LockerState.Occupied;

            context.SaveChanges();
        }
        public bool IsLockerAvailable(Guid lockerBankId, Guid lockerId)
        {
            LockerDbContext context = new LockerDbContext(_connectionStringFactory.GetConnectionString());

            return context.Lockers.Any(lo => lo.LockerId == lockerId && lo.LockerBankId == lockerBankId && lo.State == LockerState.Available);
        }
Ejemplo n.º 14
0
 public LockerCasesController(LockerDbContext context)
 {
     _context = context;
 }
        public LockerDto GetLockerById(Guid lockerBankId, Guid lockerId)
        {
            LockerDbContext context = new LockerDbContext(_connectionStringFactory.GetConnectionString());

            var lockerData = context.Lockers
                            .Where(locker => locker.LockerBankId == lockerBankId && locker.LockerId == lockerId)
                            .Select(locker => new LockerDto
                            {
                                LockerId = locker.LockerId,
                                LockerBankId = locker.LockerBankId,
                                LockerOfflineReasonId = locker.LockerOfflineReasonId,
                                Size = locker.Size,
                                State = locker.State
                            }).FirstOrDefault();

            return lockerData;
        }
Ejemplo n.º 16
0
 public VacancyRepository(LockerDbContext dbContext)
 {
     _dbContext = dbContext;
 }
Ejemplo n.º 17
0
 public HardwareController(LockerDbContext lockerDbContext, ILogger <AccountController> logger)
 {
     _dbContext    = lockerDbContext;
     _hardwareRepo = new HardwareRepository(_dbContext);
 }
Ejemplo n.º 18
0
 public AccountController(LockerDbContext lockerDbContext)
 {
     _dbContext   = lockerDbContext;
     _accountRepo = new AccountRepository(_dbContext);
 }
Ejemplo n.º 19
0
 public MessageDetailRepository(LockerDbContext dbContext)
 {
     _dbContext = dbContext;
 }
Ejemplo n.º 20
0
 /// <summary>
 ///     Initialize EmployeeController with a specific database context
 /// </summary>
 /// <param name="lockerDbContext">the targeted database context</param>
 public EmployeeController(LockerDbContext lockerDbContext)
 {
     _dbContext = lockerDbContext;
     _empRepo   = new EmployeeRepository(_dbContext);
 }
Ejemplo n.º 21
0
 public EmployeesController(LockerDbContext context)
 {
     _context = context;
 }
Ejemplo n.º 22
0
 public EmployeeRepository(LockerDbContext dbContext)
 {
     _dbContext = dbContext;
 }
Ejemplo n.º 23
0
 public NotificationController(LockerDbContext lockerDbContext)
 {
     _dbContext = lockerDbContext;
     _notiRepo  = new NotificationRepository(_dbContext);
 }
 public AssignedEmployeeLockerCasesController(LockerDbContext context)
 {
     _context = context;
 }
Ejemplo n.º 25
0
 public LockerMetadataRepository(LockerDbContext dbContext)
 {
     _dbContext = dbContext;
 }
Ejemplo n.º 26
0
 public NotificationRepository(LockerDbContext dbContext)
 {
     _dbContext = dbContext;
 }
Ejemplo n.º 27
0
 public VacancyController(LockerDbContext lockerDbContext)
 {
     _dbContext   = lockerDbContext;
     _vacancyRepo = new VacancyRepository(_dbContext);
 }
Ejemplo n.º 28
0
        protected override string Schedule => "*/1 * * * *"; // every minute

        public override Task ProcessInScope(IServiceProvider serviceProvider, DbContextOptions <test2.DatabaseContext.LockerDbContext> dbOption)
        {
            //var processor = serviceProvider.GetRequiredService();
            try
            {
                TimeZoneInfo zone     = TimeZoneInfo.FindSystemTimeZoneById("SE Asia Standard Time");
                DateTime     dateTime = TimeZoneInfo.ConvertTime(DateTime.Now, zone);
                _dbContext = new LockerDbContext(dbOption);
                var reservelist = from list in _dbContext.reservations
                                  where list.EndDay < dateTime && list.IsActive == true && list.Status == Status.Use
                                  select list;

                if (reservelist == null)
                {
                    Log.Information("Use Time up every 1 mins {0} No data to set.", dateTime);
                }
                else
                {
                    foreach (var run in reservelist)
                    {
                        _dbContext.reservations.FirstOrDefault(x => x.Id_reserve == run.Id_reserve).IsActive = false;
                        _dbContext.SaveChanges();
                        Notification notification = new Notification()
                        {
                            Id_account = run.Id_account,
                            CreateTime = dateTime,
                            Id_content = _appSettings.EndContent,
                            Id_reserve = run.Id_reserve,
                            IsShow     = true,
                            Read       = false
                        };
                        _dbContext.notifications.Add(notification);
                        _dbContext.SaveChanges();
                        SendPushNotification(_dbContext.accounts.FirstOrDefault(x => x.Id_account == run.Id_account).ExpoToken);
                        if (_dbContext.accounts.FirstOrDefault(x => x.Id_account == run.Id_account).Point <= 0)
                        {
                            _dbContext.accounts.FirstOrDefault(x => x.Id_account == run.Id_account).Point = 0;
                            _dbContext.SaveChanges();
                            Notification p_notification = new Notification()
                            {
                                Id_account = run.Id_account,
                                CreateTime = dateTime,
                                Id_content = _appSettings.PenaltyContent,
                                IsShow     = true,
                                Read       = false
                            };
                            _dbContext.notifications.Add(p_notification);
                            _dbContext.accounts.FirstOrDefault(x => x.Id_account == run.Id_account).Point = 0;
                            _dbContext.SaveChanges();

                            SendPushNotificationP(_dbContext.accounts.FirstOrDefault(x => x.Id_account == run.Id_account).ExpoToken);

                            Log.Information("Create noti point {0} {1}.", dateTime, run.Id_account);
                            Log.Information("Set point to zero {0} {1}.", dateTime, run.Id_account);
                        }
                        Log.Information("Use Time up every 1 mins {0} {1} Data to be set and create notification.", dateTime, run.Id_reserve);
                    }
                }
            }
            catch
            {
                TimeZoneInfo zone     = TimeZoneInfo.FindSystemTimeZoneById("SE Asia Standard Time");
                DateTime     dateTime = TimeZoneInfo.ConvertTime(DateTime.Now, zone);
                Log.Information("Use Time up every 1 mins {0} Error.", dateTime);
            }


            return(Task.CompletedTask);
        }
Ejemplo n.º 29
0
        protected override string Schedule => "*/5 * * * *"; //every 5 minute

        public override Task ProcessInScope(IServiceProvider serviceProvider, DbContextOptions <LockerDbContext> dbOption)
        {
            try
            {
                _dbContext = new LockerDbContext(dbOption);
                var reservelist = (from row in _dbContext.reservations
                                   where row.Status == Status.Timeup
                                   select row.Id_account).Distinct();

                TimeZoneInfo zone     = TimeZoneInfo.FindSystemTimeZoneById("SE Asia Standard Time");
                DateTime     dateTime = TimeZoneInfo.ConvertTime(DateTime.Now, zone);

                if (reservelist == null)
                {
                    Log.Information("Set Expire every 5 min {0} No data to set.", dateTime);
                }
                else
                {
                    foreach (var run in reservelist)
                    {
                        int timeupcount = _dbContext.reservations.Count(x => x.Id_account == run.ToString() && x.Status == Status.Timeup);
                        int penalty     = timeupcount / 4;
                        if (penalty == 0)
                        {
                            Log.Information("Set Expire every 5 min {0} {1} No data to set.", dateTime, run.ToString());
                        }
                        else
                        {
                            int i;
                            for (i = 0; i < 4 * penalty; i++)
                            {
                                _dbContext.reservations.FirstOrDefault(x => x.Id_account == run.ToString() && x.Status == Status.Timeup).Status = Status.Expire;
                                _dbContext.SaveChanges();
                                Log.Information("Set Expire every 1 hour {0} {1} Data to be set", dateTime, run.ToString());
                            }
                            _dbContext.accounts.FirstOrDefault(x => x.Id_account == run.ToString()).Point -= _appSettings.PenaltyPoint * penalty;
                            _dbContext.SaveChanges();

                            // point less than 0
                            if (_dbContext.accounts.FirstOrDefault(x => x.Id_account == run.ToString()).Point <= 0)
                            {
                                Notification notification = new Notification()
                                {
                                    Id_account = run.ToString(),
                                    CreateTime = dateTime,
                                    Id_content = _appSettings.PenaltyContent,
                                    IsShow     = true,
                                    Read       = false
                                };
                                _dbContext.notifications.Add(notification);
                                _dbContext.accounts.FirstOrDefault(x => x.Id_account == run.ToString()).Point = 0;
                                _dbContext.SaveChanges();
                                SendPushNotification(_dbContext.accounts.FirstOrDefault(x => x.Id_account == run.ToString()).ExpoToken);
                                Log.Information("Create noti point {0} {1}.", dateTime, run.ToString());
                            }
                            Log.Information("Set Expire every 1 hour {0} {1} Data to be set", dateTime, run.ToString());
                        }
                    }
                }
            }
            catch
            {
                TimeZoneInfo zone     = TimeZoneInfo.FindSystemTimeZoneById("SE Asia Standard Time");
                DateTime     dateTime = TimeZoneInfo.ConvertTime(DateTime.Now, zone);
                Log.Information("Set Expire every 1 hour {0} Error.", dateTime);
            }

            return(Task.CompletedTask);
        }
Ejemplo n.º 30
0
 public HardwareRepository(LockerDbContext dbContext)
 {
     _dbContext = dbContext;
 }
Ejemplo n.º 31
0
 public ReservationController(LockerDbContext lockerDbContext)
 {
     _dbContext   = lockerDbContext;
     _reserveRepo = new ReservationRepository(_dbContext);
 }