Example #1
0
        public async Task <ActionResult> GcPreferences(GcPreferenceViewModel model, CancellationToken cancellationToken)
        {
            var edOrgId = _sessionInfo.CurrentAgencyId.GetValueOrDefault();
            var pref    = new OrgGcPreference
            {
                EducationOrganizationId = edOrgId,
                AllowExternalDomains    = model.AllowExternalDomains,
                GcUserEmail             = model.GcUserEmail
            };
            var creds = new ClientCredentials
            {
                EducationOrganizationId = edOrgId,
                ClientId     = model.ClientId,
                ClientSecret = model.ClientSecret
            };

            try
            {
                _setupBusiness.UpsertGcPreference(pref);
                _setupBusiness.UpsertClientCredentials(creds);

                return(RedirectToAction("ConfirmAsync", "User", new{ leaId = edOrgId, userEmail = model.GcUserEmail }));
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(View(model));
            }
        }
        public void UpsertGcPreference(OrgGcPreference orgGc)
        {
            var existing = _context.OrgGcPreferences.FirstOrDefault(u => u.EducationOrganizationId == orgGc.EducationOrganizationId);

            if (existing != null)
            {
                existing.GcUserEmail          = orgGc.GcUserEmail;
                existing.AllowExternalDomains = orgGc.AllowExternalDomains;
            }
            else
            {
                _context.OrgGcPreferences.Add(orgGc);
            }

            _context.SaveChanges();
        }