Exemple #1
0
        public async Task <Guid> CreateAsync(UserAccountForCreateModel userAccountForCreateModel)
        {
            _logger.Information($"Creating user account with login '{userAccountForCreateModel.Login}'...");

            if (userAccountForCreateModel.Login.Contains(':') ||
                userAccountForCreateModel.Password.Contains(':'))
            {
                throw new UserAccountException("User account login and password must not contain following characters: ':'");
            }

            var currentDateTime = DateTime.UtcNow;

            var userAccount = new UserAccountDataModel
            {
                Login               = userAccountForCreateModel.Login,
                PasswordHash        = userAccountForCreateModel.Password.GetSHA256().ToBase64(),
                Guid                = Guid.NewGuid(),
                Status              = UserAccountStatusEnum.Active,
                DateOfCreationUtc   = currentDateTime,
                DateOfLastChangeUtc = currentDateTime
            };

            var wasRecordSaved = await _repository.SaveAsync(userAccount);

            if (!wasRecordSaved)
            {
                throw new DataModelOperationException($"Error while creating user account");
            }

            _logger.Information($"User account was successfully created ({userAccount.ToJson()})");

            return(userAccount.Guid);
        }
Exemple #2
0
        public async Task <int> SaveAsync(ParticipantModel participantModel)
        {
            _logger.Information($"Saving participant ({participantModel.ToJson()})...");

            var participant    = _mapper.Map <ParticipantDataModel>(participantModel);
            var wasRecordSaved = await _repository.SaveAsync(participant);

            if (!wasRecordSaved)
            {
                throw new DataModelOperationException($"Error while saving participant");
            }

            _logger.Information($"Participant was successfully saved (id = {participant.Id})");

            return(participant.Id);
        }
Exemple #3
0
        public async Task <int> SaveAsync(ReportForSaveModel reportForSaveModel)
        {
            _logger.Information($"Saving report ({reportForSaveModel.ToJson()})...");

            var report = new ReportDataModel
            {
                ParticipantCount  = reportForSaveModel.ParticipantCount,
                DateOfCreationUtc = DateTime.UtcNow
            };

            var wasRecordSaved = await _repository.SaveAsync(report);

            if (!wasRecordSaved)
            {
                throw new DataModelOperationException($"Error while saving report");
            }

            _logger.Information($"Report was successfully saved ({report.ToJson()})");

            return(report.Id);
        }