示例#1
0
 public void Map(BlogPostModel from, BlogPost to)
 {
     MiniMapper.Map(from, to);
     to.MediaFileId        = from.PictureId.ZeroToNull();
     to.PreviewMediaFileId = from.PreviewPictureId.ZeroToNull();
 }
示例#2
0
 public void Map(ProductAttributeOptionModel from, ProductAttributeOption to)
 {
     MiniMapper.Map(from, to);
     to.MediaFileId = from.PictureId;
 }
 public void Map(Topic from, TopicModel to)
 {
     MiniMapper.Map(from, to);
     to.SeName            = from.GetSeName(0, true, false);
     to.WidgetWrapContent = from.WidgetWrapContent ?? true;
 }
        /// <summary>
        /// Prepare address model
        /// </summary>
        /// <param name="model">Model</param>
        /// <param name="address">Address</param>
        /// <param name="excludeProperties">A value indicating whether to exclude properties</param>
        /// <param name="addressSettings">Address settings</param>
        /// <param name="localizationService">Localization service (used to prepare a select list)</param>
        /// <param name="stateProvinceService">State service (used to prepare a select list). null to don't prepare the list.</param>
        /// <param name="loadCountries">A function to load countries  (used to prepare a select list). null to don't prepare the list.</param>
        public static void PrepareModel(this AddressModel model,
                                        Address address,
                                        bool excludeProperties,
                                        AddressSettings addressSettings,
                                        ILocalizationService localizationService   = null,
                                        IStateProvinceService stateProvinceService = null,
                                        Func <IList <Country> > loadCountries      = null)
        {
            Guard.NotNull(model, nameof(model));
            Guard.NotNull(addressSettings, nameof(addressSettings));

            // Form fields
            MiniMapper.Map(addressSettings, model);

            if (!excludeProperties && address != null)
            {
                MiniMapper.Map(address, model);

                model.EmailMatch  = address.Email;
                model.CountryName = address.Country?.GetLocalized(x => x.Name);
                if (address.StateProvinceId.HasValue && address.StateProvince != null)
                {
                    model.StateProvinceName = address.StateProvince.GetLocalized(x => x.Name);
                }
                model.FormattedAddress = Core.Infrastructure.EngineContext.Current.Resolve <IAddressService>().FormatAddress(address, true);
            }

            // Countries and states
            if (addressSettings.CountryEnabled && loadCountries != null)
            {
                if (localizationService == null)
                {
                    throw new ArgumentNullException("localizationService");
                }

                model.AvailableCountries.Add(new SelectListItem {
                    Text = localizationService.GetResource("Address.SelectCountry"), Value = "0"
                });
                foreach (var c in loadCountries())
                {
                    model.AvailableCountries.Add(new SelectListItem
                    {
                        Text     = c.GetLocalized(x => x.Name),
                        Value    = c.Id.ToString(),
                        Selected = c.Id == model.CountryId
                    });
                }

                if (addressSettings.StateProvinceEnabled)
                {
                    // States
                    if (stateProvinceService == null)
                    {
                        throw new ArgumentNullException("stateProvinceService");
                    }

                    var states = stateProvinceService
                                 .GetStateProvincesByCountryId(model.CountryId ?? 0)
                                 .ToList();
                    if (states.Count > 0)
                    {
                        foreach (var s in states)
                        {
                            model.AvailableStates.Add(new SelectListItem
                            {
                                Text     = s.GetLocalized(x => x.Name),
                                Value    = s.Id.ToString(),
                                Selected = (s.Id == model.StateProvinceId)
                            });
                        }
                    }
                    else
                    {
                        model.AvailableStates.Add(new SelectListItem
                        {
                            Text  = localizationService.GetResource("Address.OtherNonUS"),
                            Value = "0"
                        });
                    }
                }
            }

            if (localizationService != null)
            {
                string salutations = addressSettings.GetLocalizedSetting(x => x.Salutations);
                foreach (var sal in salutations.SplitSafe(","))
                {
                    model.AvailableSalutations.Add(new SelectListItem {
                        Value = sal, Text = sal
                    });
                }
            }
        }
示例#5
0
 public void Map(NewsItemModel from, NewsItem to)
 {
     MiniMapper.Map(from, to);
     to.MediaFileId        = from.PictureId.ZeroToNull();
     to.PreviewMediaFileId = from.PreviewPictureId.ZeroToNull();
 }
示例#6
0
 public void Map(Country from, CountryModel to)
 {
     MiniMapper.Map(from, to);
     to.NumberOfStates = from.StateProvinces?.Count ?? 0;
 }
 public void Map(ProductVariantAttributeCombinationModel from, ProductVariantAttributeCombination to)
 {
     MiniMapper.Map(from, to);
     to.SetAssignedMediaIds(from.AssignedPictureIds);
 }
 public void Map(ForumGroup from, ForumGroupModel to)
 {
     MiniMapper.Map(from, to);
     to.SeName = from.GetSeName(0, true, false);
 }
示例#9
0
        protected void PrepareBlogPostModel(BlogPostModel model, BlogPost blogPost, bool prepareComments)
        {
            Guard.NotNull(blogPost, nameof(blogPost));
            Guard.NotNull(model, nameof(model));

            MiniMapper.Map(blogPost, model);

            model.SeName    = blogPost.GetSeName(blogPost.LanguageId, ensureTwoPublishedLanguages: false);
            model.CreatedOn = _dateTimeHelper.ConvertToUserTime(blogPost.CreatedOnUtc, DateTimeKind.Utc);
            model.AddNewComment.DisplayCaptcha           = _captchaSettings.CanDisplayCaptcha && _captchaSettings.ShowOnBlogCommentPage;
            model.Comments.AllowComments                 = blogPost.AllowComments;
            model.Comments.NumberOfComments              = blogPost.ApprovedCommentCount;
            model.Comments.AllowCustomersToUploadAvatars = _customerSettings.AllowCustomersToUploadAvatars;
            model.DisplayAdminLink = _services.Permissions.Authorize(Permissions.System.AccessBackend, _services.WorkContext.CurrentCustomer);

            model.HasBgImage = blogPost.PreviewDisplayType == PreviewDisplayType.DefaultSectionBg || blogPost.PreviewDisplayType == PreviewDisplayType.PreviewSectionBg;

            model.PictureModel = PrepareBlogPostPictureModel(blogPost, blogPost.MediaFileId);

            if (blogPost.PreviewDisplayType == PreviewDisplayType.Default || blogPost.PreviewDisplayType == PreviewDisplayType.DefaultSectionBg)
            {
                model.PreviewPictureModel = PrepareBlogPostPictureModel(blogPost, blogPost.MediaFileId);
            }
            else if (blogPost.PreviewDisplayType == PreviewDisplayType.Preview || blogPost.PreviewDisplayType == PreviewDisplayType.PreviewSectionBg)
            {
                model.PreviewPictureModel = PrepareBlogPostPictureModel(blogPost, blogPost.PreviewMediaFileId);
            }

            if (blogPost.PreviewDisplayType == PreviewDisplayType.Preview ||
                blogPost.PreviewDisplayType == PreviewDisplayType.Default ||
                blogPost.PreviewDisplayType == PreviewDisplayType.Bare)
            {
                model.SectionBg = string.Empty;
            }

            // tags
            model.Tags = blogPost.ParseTags().Select(x => new BlogPostTagModel
            {
                Name   = x,
                SeName = SeoHelper.GetSeName(x,
                                             _seoSettings.ConvertNonWesternChars,
                                             _seoSettings.AllowUnicodeCharsInUrls,
                                             true,
                                             _seoSettings.SeoNameCharConversion)
            }).ToList();

            if (prepareComments)
            {
                var blogComments = blogPost.BlogComments.Where(pr => pr.IsApproved).OrderBy(pr => pr.CreatedOnUtc);
                foreach (var bc in blogComments)
                {
                    var isGuest = bc.Customer.IsGuest();

                    var commentModel = new CommentModel(model.Comments)
                    {
                        Id                   = bc.Id,
                        CustomerId           = bc.CustomerId,
                        CustomerName         = bc.Customer.FormatUserName(_customerSettings, T, false),
                        CommentText          = bc.CommentText,
                        CreatedOn            = _dateTimeHelper.ConvertToUserTime(bc.CreatedOnUtc, DateTimeKind.Utc),
                        CreatedOnPretty      = bc.CreatedOnUtc.RelativeFormat(true, "f"),
                        AllowViewingProfiles = _customerSettings.AllowViewingProfiles && !isGuest
                    };

                    commentModel.Avatar = bc.Customer.ToAvatarModel(_genericAttributeService, _customerSettings, _mediaSettings, commentModel.CustomerName);

                    model.Comments.Comments.Add(commentModel);
                }
            }

            Services.DisplayControl.Announce(blogPost);
        }
        protected bool SaveConfigurationModel(
            ApiConfigurationModel model,
            FormCollection form,
            Action <TSetting> map = null)
        {
            var storeDependingSettingHelper = new StoreDependingSettingHelper(ViewData);
            var storeScope = this.GetActiveStoreScopeConfiguration(Services.StoreService, Services.WorkContext);
            var settings   = Services.Settings.LoadSetting <TSetting>(storeScope);

            var oldClientId  = settings.ClientId;
            var oldSecret    = settings.Secret;
            var oldProfileId = settings.ExperienceProfileId;

            var validator = new PayPalApiConfigValidator(T, x =>
            {
                return(storeScope == 0 || storeDependingSettingHelper.IsOverrideChecked(settings, x, form));
            });

            validator.Validate(model, ModelState);

            // Additional validation.
            if (ModelState.IsValid)
            {
                // PayPal review: check if credentials are valid.
                var credentialChanged = model.ClientId.HasValue() && model.Secret.HasValue() &&
                                        (!model.ClientId.IsCaseInsensitiveEqual(settings.ClientId) || !model.Secret.IsCaseInsensitiveEqual(settings.Secret));

                if (credentialChanged)
                {
                    var session = new PayPalSessionData {
                        ProviderSystemName = ProviderSystemName
                    };
                    var tmpSettings = new PayPalApiSettingsBase
                    {
                        UseSandbox = model.UseSandbox,
                        ClientId   = model.ClientId,
                        Secret     = model.Secret
                    };

                    var result = PayPalService.EnsureAccessToken(session, tmpSettings);
                    if (!result.Success)
                    {
                        ModelState.AddModelError("", T("Plugins.SmartStore.PayPal.InvalidCredentials"));
                        ModelState.AddModelError("", result.ErrorMessage);
                    }
                }
            }

            if (!ModelState.IsValid)
            {
                return(false);
            }

            ModelState.Clear();
            model.TransactMode = TransactMode.AuthorizeAndCapture;

            MiniMapper.Map(model, settings);
            settings.ApiAccountName      = model.ApiAccountName.TrimSafe();
            settings.ApiAccountPassword  = model.ApiAccountPassword.TrimSafe();
            settings.ClientId            = model.ClientId.TrimSafe();
            settings.ExperienceProfileId = model.ExperienceProfileId.TrimSafe();
            settings.Secret    = model.Secret.TrimSafe();
            settings.Signature = model.Signature.TrimSafe();
            settings.WebhookId = model.WebhookId.TrimSafe();

            // Additional mapping.
            map?.Invoke(settings);

            // Credentials changed: reset profile and webhook id to avoid errors.
            if (!oldClientId.IsCaseInsensitiveEqual(settings.ClientId) || !oldSecret.IsCaseInsensitiveEqual(settings.Secret))
            {
                if (oldProfileId.IsCaseInsensitiveEqual(settings.ExperienceProfileId))
                {
                    settings.ExperienceProfileId = null;
                }

                settings.WebhookId = null;
            }

            using (Services.Settings.BeginScope())
            {
                storeDependingSettingHelper.UpdateSettings(settings, form, storeScope, Services.Settings);
            }

            using (Services.Settings.BeginScope())
            {
                // Multistore context not possible, see IPN handling.
                Services.Settings.SaveSetting(settings, x => x.UseSandbox, 0, false);
            }

            NotifySuccess(T("Admin.Common.DataSuccessfullySaved"));
            return(true);
        }
示例#11
0
 public void Map(SpecificationAttributeOptionModel from, SpecificationAttributeOption to)
 {
     MiniMapper.Map(from, to);
     to.MediaFileId = from.PictureId;
 }
示例#12
0
 public void Map(CategoryModel from, Category to)
 {
     MiniMapper.Map(from, to);
     to.MediaFileId = from.PictureId.ZeroToNull();
 }
示例#13
0
 public void Map(Category from, CategoryModel to)
 {
     MiniMapper.Map(from, to);
     to.SeName    = from.GetSeName(0, true, false);
     to.PictureId = from.MediaFileId;
 }
示例#14
0
 public void Map(BlogPost from, BlogPostModel to)
 {
     MiniMapper.Map(from, to);
     to.SeName = from.GetSeName(from.LanguageId, true, false);
 }
示例#15
0
 public void Map(Category from, CategoryModel to)
 {
     MiniMapper.Map(from, to);
     to.SeName = from.GetSeName(0, true, false);
 }
示例#16
0
        public ActionResult Configure(ProfilerSettings settings)
        {
            var model = MiniMapper.Map <ProfilerSettings, ConfigurationModel>(settings);

            return(View(model));
        }