Ejemplo n.º 1
0
        public async Task HandleAsync(CreateAccessRecord message, IRequestInfo requestInfo)
        {
            IUserDocument userDocument = await _userRepository.GetByCodeAsync(message.Code);

            if (userDocument is null)
            {
                _publisher.PublishEvent(new AccessRecordRejected(Codes.InvalidId, "The code used is invalid."), requestInfo);
                _logger.LogError($"User with code: {message.Code} could not be found.");
                return;
            }


            if (!await _servicesRepository.IsSiteIdValid(message.SiteId))
            {
                _publisher.PublishEvent(new AccessRecordRejected(Codes.InvalidId, "The site could not be found."), requestInfo);
                _logger.LogError($"Site with id: {message.SiteId} could not be found.");
                return;
            }

            await _userStatusService.Update(userDocument.Id, message.Action, message.SiteId);

            var record = _factory.Create(userDocument.Id, message.SiteId, message.Action, userDocument.BusinessId);
            await _accessRecordRepository.AddAsync(record);

            _publisher.PublishEvent(new AccessRecordCreated(), requestInfo);

            string action = message.Action == AccessAction.In ? "in" : "out";

            _logger.LogInformation($"{userDocument.FirstName + " " + userDocument.SecondName} signed {action} on : {record.TimeStamp}.", LoggingCategories.Access);
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Edit(AdminUserStatusEditViewModel viewModel)
        {
            UserStatus userStatus = await userStatusService.GetByIDAsync(viewModel.ID);

            if (userStatus == null)
            {
                return(NotFound());
            }

            userStatus.Id   = viewModel.ID;
            userStatus.Name = viewModel.Name;

            userStatusService.Update(userStatus);
            return(RedirectToAction("Index"));
        }