Esempio n. 1
0
        public async Task <IActionResult> Create(MessageViewModel messageViewModel)
        {
            if (ModelState.IsValid)
            {
                var result = await validator.ValidateCreationAsync(messageViewModel);

                if (result.Succeeded)
                {
                    var message = await mapper.FromViewModelAsync(messageViewModel);

                    var encrypt = encryptor.EncryptMessage(messageViewModel.Message, messageViewModel.Key);
                    message.Value = encrypt.Value;
                    message.IV    = encrypt.IV;

                    await repository.AddMessageAsync(message);

                    return(RedirectToAction(nameof(Success), new { Id = message.Code }));
                }
                ModelState.AddModelError("", result.Description);
            }
            return(View());
        }