コード例 #1
0
        public IActionResult TestEmail(string title)
        {
            _logger.LogInformation("Test message: " + title);

            var mailgunApiKey = _configuration.GetSection("MAILGUNAPI").Value;

            _logger.LogInformation("MAILGUNAPI: " + mailgunApiKey);

            var response = MailgunAPI.SendTestMessage(title);

            return(Ok("MailGun API response: " + response));
        }
コード例 #2
0
        public string Share(string userId, string applicationId, string email)
        {
            //Check if the user with the email already exist
            if (_context.Users.Any(u => u.Username == email))
            {
                _context.ApplicationUserMaps.Add(new ApplicationUserMap {
                    ApplicationId = applicationId, UserId = userId
                });

                _context.SaveChanges();
            }
            else //If not then create one
            {
                User user = new User();
                user.Username = email;

                string password = RandomString(8);

                _logger.LogInformation("New user: "******" with password " + password + " was created");

                byte[] passwordHash, passwordSalt;
                CreatePasswordHash(password, out passwordHash, out passwordSalt);

                user.PasswordHash = passwordHash;
                user.PasswordSalt = passwordSalt;

                _context.Users.Add(user);

                _context.ApplicationUserMaps.Add(new ApplicationUserMap {
                    ApplicationId = applicationId, UserId = user.Id
                });

                _context.SaveChanges();
            }

            // Send an email to the User informing about the Share
            var application = _context.Applications.Where(a => a.Id == applicationId).FirstOrDefault();
            var response    = MailgunAPI.SendApplicationShareEmailMessage(application, email);

            return("OK");
        }
コード例 #3
0
        public Application Create(Application application, string templateId, string userId)
        {
            // Save new Application
            _context.Applications.Add(application);

            // Link Application to the User
            _context.ApplicationUserMaps.Add(new ApplicationUserMap {
                ApplicationId = application.Id, UserId = userId
            });

            // Copy questions from the TemplateQuestions to the ApplicationQuestions table
            var templateQuestions = _context.TemplateQuestions.Where(q => q.TemplateId == templateId);

            foreach (var templateQuestion in templateQuestions)
            {
                _context.ApplicationQuestions.Add(
                    new ApplicationQuestion
                {
                    Id            = Guid.NewGuid().ToString(),
                    ApplicationId = application.Id,
                    Text          = templateQuestion.Text,
                    Duration      = templateQuestion.Duration,
                    Order         = templateQuestion.Order,
                    Timestamp     = DateTime.Now
                });
            }

            _context.SaveChanges();

            // Send an email to the Candidate
            var response = MailgunAPI.SendApplicationEmailMessage(application);

            _logger.LogInformation(response);

            return(application);
        }