public ActionResult SaveSettings(string email)
        {
            try
            {
                if (Request.IsAuthenticated)
                {
                    var           username     = User.Identity.Name;
                    StringBuilder sbUserStatus = new StringBuilder();
                    using (PnPTestAutomationEntities dbContext = new PnPTestAutomationEntities())
                    {
                        var user = dbContext.UsersSets.SingleOrDefault(u => u.UPN.Equals(username, StringComparison.InvariantCultureIgnoreCase));

                        if (user != null)
                        {
                            user.SendTestResults = true;
                            user.Email           = email;
                            dbContext.SaveChanges();

                            SendEmail(email);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw;
            }

            return(View());
        }
        public ActionResult UpdateSettings(string email, bool isSendTestResults)
        {
            EmailConfirmation emailConfirmation = new EmailConfirmation();

            try
            {
                if (Request.IsAuthenticated)
                {
                    var           username     = User.Identity.Name;
                    StringBuilder sbUserStatus = new StringBuilder();
                    using (PnPTestAutomationEntities dbContext = new PnPTestAutomationEntities())
                    {
                        var user = dbContext.UsersSets.SingleOrDefault(u => u.UPN.Equals(username, StringComparison.InvariantCultureIgnoreCase));

                        if (user != null)
                        {
                            if (!isSendTestResults)
                            {
                                user.SendTestResults = false;
                                user.Email           = email;
                                user.IsEmailVerified = false;
                                dbContext.SaveChanges();

                                emailConfirmation.IsSettingsUpdated = true;
                            }
                            else if (isSendTestResults && user.Email != email)
                            {
                                user.SendTestResults = true;
                                user.Email           = email;
                                dbContext.SaveChanges();

                                SendEmail(email);
                                emailConfirmation.IsEmailSent = true;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw;
            }

            return(View(emailConfirmation));
        }
        public ActionResult Edit(Configuration config)
        {
            using (PnPTestAutomationEntities dc = new PnPTestAutomationEntities())
            {
                var configuration = dc.TestConfigurationSets.SingleOrDefault(c => c.Id == config.ConfigurationId);
                configuration.Branch = config.GithubBranch;
                configuration.Description = config.Description;
                configuration.TenantUrl = config.Tenantadminsitecollection;
                configuration.TestSiteUrl = config.Testsitecollection;
                configuration.VSBuildConfiguration = config.VSBuildConfiguration;
                configuration.Type = (int)Enum.Parse(typeof(EnvironmentType), config.Platform);

                var testauthenticationset = dc.TestAuthenticationSets.SingleOrDefault(a => a.Id == configuration.TestAuthentication_Id);
                if (testauthenticationset != null)
                {
                    testauthenticationset.AppSecret = config.ClientSecret;
                    testauthenticationset.AppId = config.ClientID;
                    testauthenticationset.CredentialManagerLabel = config.CredentialManagerLabel;

                    testauthenticationset.User = config.UserName;
                    testauthenticationset.Domain = config.Domain;
                    testauthenticationset.Password = config.PassWord;
                }

                dc.SaveChanges();

                if (config.ConfigCustomProperties != null && config.ConfigCustomProperties.Count > 0)
                {
                    foreach (ConfigurationpropertySet configpropertySet in config.ConfigCustomProperties)
                    {
                        var configurationpropertySetData = dc.TestConfigurationPropertySets.SingleOrDefault(c => c.Id == configpropertySet.ID);
                        if (configurationpropertySetData != null)
                        {
                            configurationpropertySetData.Name = configpropertySet.Name;
                            configurationpropertySetData.Value = configpropertySet.Value;
                            dc.SaveChanges();
                        }
                    }
                }

            }

            return RedirectToAction("Edit", new { id = config.TestRunId, IsConfigurationUpdated = true });
        }
Esempio n. 4
0
        public ActionResult Edit(Configuration config)
        {
            using (PnPTestAutomationEntities dc = new PnPTestAutomationEntities())
            {
                var configuration = dc.TestConfigurationSets.SingleOrDefault(c => c.Id == config.ConfigurationId);
                configuration.Branch               = config.GithubBranch;
                configuration.Description          = config.Description;
                configuration.TenantUrl            = config.Tenantadminsitecollection;
                configuration.TestSiteUrl          = config.Testsitecollection;
                configuration.VSBuildConfiguration = config.VSBuildConfiguration;
                configuration.Type = (int)Enum.Parse(typeof(EnvironmentType), config.Platform);

                var testauthenticationset = dc.TestAuthenticationSets.SingleOrDefault(a => a.Id == configuration.TestAuthentication_Id);
                if (testauthenticationset != null)
                {
                    testauthenticationset.AppSecret = config.ClientSecret;
                    testauthenticationset.AppId     = config.ClientID;
                    testauthenticationset.CredentialManagerLabel = config.CredentialManagerLabel;

                    testauthenticationset.User     = config.UserName;
                    testauthenticationset.Domain   = config.Domain;
                    testauthenticationset.Password = config.PassWord;
                }

                dc.SaveChanges();

                if (config.ConfigCustomProperties != null && config.ConfigCustomProperties.Count > 0)
                {
                    foreach (ConfigurationpropertySet configpropertySet in config.ConfigCustomProperties)
                    {
                        var configurationpropertySetData = dc.TestConfigurationPropertySets.SingleOrDefault(c => c.Id == configpropertySet.ID);
                        if (configurationpropertySetData != null)
                        {
                            configurationpropertySetData.Name  = configpropertySet.Name;
                            configurationpropertySetData.Value = configpropertySet.Value;
                            dc.SaveChanges();
                        }
                    }
                }
            }

            return(RedirectToAction("Edit", new { id = config.TestRunId, IsConfigurationUpdated = true }));
        }
        public ActionResult ConfirmEmail(string validateToken)
        {
            EmailConfirmation emailconf = new EmailConfirmation();

            try
            {
                if (Request.IsAuthenticated)
                {
                    var    username       = User.Identity.Name;
                    string decryptedEmail = EncryptionUtility.Decrypt(validateToken);
                    emailconf.Email = decryptedEmail;
                    using (PnPTestAutomationEntities dbContext = new PnPTestAutomationEntities())
                    {
                        var user = dbContext.UsersSets.FirstOrDefault(
                            u => u.Email.Equals(decryptedEmail, StringComparison.InvariantCultureIgnoreCase) &&
                            u.UPN.Equals(username, StringComparison.InvariantCultureIgnoreCase));
                        if (user != null)
                        {
                            user.IsEmailVerified = true;
                            user.SendTestResults = true;
                            dbContext.SaveChanges();
                            emailconf.IsEmailVerified = true;
                        }
                    }
                }
                else
                {
                    HttpContext.GetOwinContext().Authentication.Challenge(new AuthenticationProperties {
                        RedirectUri = "/Usersettings/ConfirmEmail/" + validateToken
                    },
                                                                          OpenIdConnectAuthenticationDefaults.AuthenticationType);
                }
            }
            catch (Exception ex)
            {
                throw;
            }

            return(View(emailconf));
        }
        public ActionResult ConfirmEmail(string validateToken)
        {
            EmailConfirmation emailconf = new EmailConfirmation();

            try
            {
                if (Request.IsAuthenticated)
                {
                    var username = User.Identity.Name;
                    string decryptedEmail = EncryptionUtility.Decrypt(validateToken);
                    emailconf.Email = decryptedEmail;
                    using (PnPTestAutomationEntities dbContext = new PnPTestAutomationEntities())
                    {
                        var user = dbContext.UsersSets.FirstOrDefault(
                        u => u.Email.Equals(decryptedEmail, StringComparison.InvariantCultureIgnoreCase)
                        && u.UPN.Equals(username, StringComparison.InvariantCultureIgnoreCase));
                        if (user != null)
                        {
                            user.IsEmailVerified = true;
                            user.SendTestResults = true;
                            dbContext.SaveChanges();
                            emailconf.IsEmailVerified = true;
                        }
                    }
                }
                else
                {
                    HttpContext.GetOwinContext().Authentication.Challenge(new AuthenticationProperties { RedirectUri = "/Usersettings/ConfirmEmail/" + validateToken },
                  OpenIdConnectAuthenticationDefaults.AuthenticationType);
                }
            }
            catch (Exception ex)
            {
                throw;
            }

            return View(emailconf);
        }
        public ActionResult UpdateSettings(string email, bool isSendTestResults)
        {
            EmailConfirmation emailConfirmation = new EmailConfirmation();

            try
            {
                if (Request.IsAuthenticated)
                {
                    var username = User.Identity.Name;
                    StringBuilder sbUserStatus = new StringBuilder();
                    using (PnPTestAutomationEntities dbContext = new PnPTestAutomationEntities())
                    {
                        var user = dbContext.UsersSets.SingleOrDefault(u => u.UPN.Equals(username, StringComparison.InvariantCultureIgnoreCase));

                        if (user != null)
                        {
                            if (!isSendTestResults)
                            {
                                user.SendTestResults = false;
                                user.Email = email;
                                user.IsEmailVerified = false;
                                dbContext.SaveChanges();

                                emailConfirmation.IsSettingsUpdated = true;
                            }
                            else if (isSendTestResults && user.Email != email)
                            {
                                user.SendTestResults = true;
                                user.Email = email;
                                dbContext.SaveChanges();

                                SendEmail(email);
                                emailConfirmation.IsEmailSent = true;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw;
            }

            return View(emailConfirmation);
        }
        public ActionResult SaveSettings(string email)
        {
            try
            {
                if (Request.IsAuthenticated)
                {
                    var username = User.Identity.Name;
                    StringBuilder sbUserStatus = new StringBuilder();
                    using (PnPTestAutomationEntities dbContext = new PnPTestAutomationEntities())
                    {
                        var user = dbContext.UsersSets.SingleOrDefault(u => u.UPN.Equals(username, StringComparison.InvariantCultureIgnoreCase));

                        if (user != null)
                        {
                            user.SendTestResults = true;
                            user.Email = email;
                            dbContext.SaveChanges();

                            SendEmail(email);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw;
            }

            return View();
        }