public async Task <IActionResult> Send()
        {
            var userEmails = await this.contactsService.GetAllUserEmailsAsync <UserEmailViewModel>();

            var model = new SendContactInputModel
            {
                UserEmails = userEmails,
            };

            return(this.View(model));
        }
        public async Task <IActionResult> Send(SendContactInputModel sendContactInputModel)
        {
            if (!this.ModelState.IsValid)
            {
                var userEmails = await this.contactsService.GetAllUserEmailsAsync <UserEmailViewModel>();

                sendContactInputModel.UserEmails = userEmails;

                return(this.View(sendContactInputModel));
            }

            await this.contactsService.SendContactToUser(sendContactInputModel);

            return(this.RedirectToAction("SuccessfullySend", new { userEmail = sendContactInputModel.Email }));
        }
        public async Task CheckIfSendContactToUserWorksCorrectly()
        {
            var model = new SendContactInputModel
            {
                FullName = "Administrator fullname",
                Email    = "*****@*****.**",
                Subject  = "Answer about cinema news",
                Content  = "Sample content about cinema news",
            };

            await this.contactsService.SendContactToUser(model);

            var count = await this.adminContactsRepository.All().CountAsync();

            Assert.Equal(1, count);
        }
        public async Task SendContactToUser(SendContactInputModel sendContactInputModel)
        {
            var adminContactFormEntry = new AdminContactFromEntry
            {
                FullName = sendContactInputModel.FullName,
                Email    = sendContactInputModel.Email,
                Subject  = sendContactInputModel.Subject,
                Content  = sendContactInputModel.Content,
            };

            await this.adminContactsRepository.AddAsync(adminContactFormEntry);

            await this.adminContactsRepository.SaveChangesAsync();

            await this.emailSender.SendEmailAsync(
                GlobalConstants.SystemEmail,
                sendContactInputModel.FullName,
                sendContactInputModel.Email,
                sendContactInputModel.Subject,
                sendContactInputModel.Content);
        }