Example #1
0
        public async Task LogoutEmployee(string userName)
        {
            Employee employee = await _usersContext.Employees.Where(e => e.Username == userName).SingleAsync();

            EmployeeConnectionUpdate update = new EmployeeConnectionUpdate
            {
                LoginStatus   = LoginStatus.LogOut,
                ServiceType   = employee.Role,
                StationNumber = employee.StationId.Value
            };
            Task updateQueueApiTask = _queueApiService.UpdateOnUserLogin(update);

            employee.Online    = false;
            employee.StationId = null;
            Task <int> saveChangesTask = _usersContext.SaveChangesAsync();
            await Task.WhenAll(saveChangesTask, updateQueueApiTask);
        }
Example #2
0
        public async Task <(bool isLoginSuccessful, EmployeeInfo employeeInfo)> TryLoginEmployee(EmployeeLogin employeeLogin)
        {
            Employee employee = await _usersContext.Employees.Where(e => e.Username == employeeLogin.Username).SingleAsync();

            EmployeeInfo employeeInfo = null;

            if (employee.Role != employeeLogin.ServiceType)
            {
                throw new InvalidOperationException("Received employee service type does not match his service type in DB.");
            }

            if (employee.Password != employeeLogin.Password || employee.Online)
            {
                return(false, employeeInfo);
            }

            Employee employeeInRequestedStation =
                await _usersContext.Employees.Where(e => e.StationId == employeeLogin.StationNumber).SingleOrDefaultAsync();

            if (employeeInRequestedStation != null)
            {
                return(false, employeeInfo);
            }

            employee.Online    = true;
            employee.StationId = employeeLogin.StationNumber;
            Task <int> saveChangesTask      = _usersContext.SaveChangesAsync();
            EmployeeConnectionUpdate update = new EmployeeConnectionUpdate
            {
                LoginStatus   = LoginStatus.LogIn,
                StationNumber = employee.StationId.Value,
                ServiceType   = employee.Role
            };
            Task updateQueueApiTask = _queueApiService.UpdateOnUserLogin(update);

            employeeInfo = new EmployeeInfo
            {
                EmployeeId = employee.EmployeeId,
                Firstname  = employee.Firstname,
                Lastname   = employee.Lastname
            };
            await Task.WhenAll(saveChangesTask, updateQueueApiTask);

            return(true, employeeInfo);
        }
Example #3
0
        public async Task <IActionResult> UpdateStationState([FromBody] EmployeeConnectionUpdate update)
        {
            if (update.Equals(default(EmployeeConnectionUpdate)) || update.ServiceType == ServiceType.none)
            {
                return(new BadRequestObjectResult("ServiceType is none"));
            }

            IQueueNotificationsHub group = _hubContext.Clients.Groups(update.ServiceType.ToString());

            if (group == null)
            {
                return(new BadRequestObjectResult($"group for {update.ServiceType.ToString()} not found"));
            }

            if (update.LoginStatus == LoginStatus.None)
            {
                return(new BadRequestObjectResult("LoginStatus is none"));
            }

            try
            {
                switch (update.LoginStatus)
                {
                case LoginStatus.LogIn:
                    await group.AddStation(update.StationNumber);

                    break;

                case LoginStatus.LogOut:
                    await group.RemoveStation(update.StationNumber);

                    break;
                }
            }
            catch (Exception)
            {
            }

            return(new OkResult());
        }
 public override Task UpdateOnUserLogin(EmployeeConnectionUpdate employeeConnectionUpdate)
 {
     return(Task.CompletedTask);
 }
        public virtual async Task UpdateOnUserLogin(EmployeeConnectionUpdate employeeConnectionUpdate)
        {
            HttpResponseMessage result = await HttpClient.PutAsJsonAsync(QueueControllerName, employeeConnectionUpdate);

            result.EnsureSuccessStatusCode();
        }