public virtual async Task <SiteMailClientSetting> Handle(EditSiteMailSettingCommand command,
                                                                 CancellationToken cancellationToken)
        {
            EditableFieldViewModel <IMailAddress[]> carbonCopies      = null;
            EditableFieldViewModel <IMailAddress[]> blindCarbonCopies = null;

            if (command.CarbonCopies != null)
            {
                carbonCopies             = new EditableFieldViewModel <IMailAddress[]>();
                carbonCopies.Value       = command.CarbonCopies.Value?.Select(x => (IMailAddress)x).ToArray();
                carbonCopies.HasModified = command.CarbonCopies.HasModified;
            }

            if (command.BlindCarbonCopies != null)
            {
                blindCarbonCopies             = new EditableFieldViewModel <IMailAddress[]>();
                blindCarbonCopies.Value       = command.BlindCarbonCopies.Value?.Select(x => (IMailAddress)x).ToArray();
                blindCarbonCopies.HasModified = command.BlindCarbonCopies.HasModified;
            }

            var updatedSiteMailClientSetting = await _siteMailClientsService
                                               .EditSiteMailClientSettingAsync(command.Id, _tenant.Id, command.DisplayName, command.MailHost,
                                                                               command.Timeout, carbonCopies, blindCarbonCopies, cancellationToken);

            return((SiteMailClientSetting)updatedSiteMailClientSetting);
        }
Ejemplo n.º 2
0
        public virtual async Task <ICorsPolicy> UpdateSiteCorsPolicyAsync(Guid id, EditableFieldViewModel <string[]> allowedHeaders, EditableFieldViewModel <string[]> allowedOrigins, EditableFieldViewModel <string[]> allowedMethods,
                                                                          EditableFieldViewModel <string[]> allowedExposedHeaders, EditableFieldViewModel <bool> allowCredential,
                                                                          EditableFieldViewModel <MasterItemAvailabilities> availability,
                                                                          CancellationToken cancellationToken = default)
        {
            // Find the site cors policy by id.
            var siteCorsPolicies = _dbContext.CorsPolicies.AsQueryable();
            var hasFieldChanged  = false;

            var siteCorsPolicy = await siteCorsPolicies
                                 .FirstOrDefaultAsync(x => x.Id == id, cancellationToken);

            if (siteCorsPolicy == null)
            {
                throw new Exception("Cors policy is not found.");
            }

            if (allowedHeaders != null && allowedHeaders.HasModified)
            {
                siteCorsPolicy.AllowedHeaders = allowedHeaders.Value;
                hasFieldChanged = true;
            }

            if (allowedOrigins != null && allowedOrigins.HasModified)
            {
                siteCorsPolicy.AllowedOrigins = allowedOrigins.Value;
                hasFieldChanged = true;
            }

            if (allowedMethods != null && allowedMethods.HasModified)
            {
                siteCorsPolicy.AllowedMethods = allowedMethods.Value;
                hasFieldChanged = true;
            }

            if (allowedExposedHeaders != null && allowedExposedHeaders.HasModified)
            {
                siteCorsPolicy.AllowedExposedHeaders = allowedExposedHeaders.Value;
                hasFieldChanged = true;
            }

            if (allowCredential != null && allowCredential.HasModified)
            {
                siteCorsPolicy.AllowCredential = allowCredential.Value;
                hasFieldChanged = true;
            }

            if (availability != null && availability.HasModified)
            {
                siteCorsPolicy.Availability = availability.Value;
                hasFieldChanged             = true;
            }

            if (hasFieldChanged)
            {
                await _dbContext.SaveChangesAsync(cancellationToken);

                return(siteCorsPolicy);
            }

            return(siteCorsPolicy);
        }