Exemplo n.º 1
0
        public async Task <IActionResult> CreateRecord(RecordCreateDTO recordCreateDTO)
        {
            if (!ModelState.IsValid)
            {
                return(View(recordCreateDTO));
            }

            try
            {
                string currentUserName = HttpContext.User.Identity.Name;

                User user = await _userManager.FindByNameAsync(currentUserName);

                byte[] ivKey = _aesCryptoProvider.GenerateIV();

                recordCreateDTO.Created  = DateTime.Now;
                recordCreateDTO.Modified = DateTime.Now;
                recordCreateDTO.IvKey    = ivKey;
                recordCreateDTO.UserId   = user.Id;

                Record record = _mapper.Map <Record>(recordCreateDTO);

                record.Text = _aesCryptoProvider.EncryptValue(recordCreateDTO.Content, user.CryptoKey, ivKey);

                Record newRecord = await _recordService.CreateAsync(record);

                if (recordCreateDTO.NewFiles != null)
                {
                    List <UploadedFile> uploadedFiles =
                        AddFiles(recordCreateDTO.NewFiles, newRecord.Id, currentUserName);

                    foreach (var file in uploadedFiles)
                    {
                        await _uploadedFileService.CreateAsync(file);
                    }
                }

                return(RedirectToAction("Index", "Home"));
            }
            catch (DbUpdateException ex)
            {
                ModelState.AddModelError("", ex.Message);
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", ex.Message);
            }

            return(View(recordCreateDTO));
        }
Exemplo n.º 2
0
        public async Task <RecordVM> Handle(UpdateRecordCommand request, CancellationToken cancellationToken)
        {
            var ivKey = _aesCryptoProviderService.GenerateIV();

            var recordDto = new RecordToUpdateDto
            {
                Id = request.Id,
                //EncryptedContent = _aesCryptoProviderService.EncryptValue(request.Content, user.CryptoKey, ivKey),
                Name  = request.Name,
                IvKey = ivKey
            };

            var record = await _recordService.UpdateAsync(recordDto, cancellationToken);

            return(_mapper.Map <RecordVM>(record));
        }
Exemplo n.º 3
0
        public async Task <RecordVM> Handle(CreateRecordCommand request, CancellationToken cancellationToken)
        {
            //string currentUserName = HttpContext.User.Identity.Name;
            //User user = await _userManager.FindByNameAsync(currentUserName);
            var user  = new User();
            var ivKey = _aesCryptoProviderService.GenerateIV();
            //var encryptedContent = _aesCryptoProviderService.EncryptValue(request.Content, user.CryptoKey, ivKey);
            var recordDto = new RecordToCreateDto
            {
                IvKey  = ivKey,
                Name   = request.Name,
                UserId = user.UserId,
            };

            var record = await _recordService.CreateAsync(recordDto, cancellationToken);

            return(_mapper.Map <RecordVM>(record));
        }