public ActionResult Create(CurrencyModel model, bool continueEditing)
        {
            if (!_services.Permissions.Authorize(StandardPermissionProvider.ManageCurrencies))
            {
                return(AccessDeniedView());
            }

            if (ModelState.IsValid)
            {
                var currency = model.ToEntity();

                _currencyService.InsertCurrency(currency);

                //locales
                UpdateLocales(currency, model);

                //Stores
                _storeMappingService.SaveStoreMappings <Currency>(currency, model.SelectedStoreIds);

                NotifySuccess(_services.Localization.GetResource("Admin.Configuration.Currencies.Added"));
                return(continueEditing ? RedirectToAction("Edit", new { id = currency.Id }) : RedirectToAction("List"));
            }

            //If we got this far, something failed, redisplay form

            //Stores
            PrepareCurrencyModel(model, null, true);

            return(View(model));
        }
コード例 #2
0
ファイル: BlogController.cs プロジェクト: achenda/marketplace
        public ActionResult Create(BlogPostModel model, bool continueEditing)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageBlog))
            {
                return(AccessDeniedView());
            }

            if (ModelState.IsValid)
            {
                var blogPost = model.ToEntity();
                blogPost.CreatedOnUtc = model.CreatedOnUtc;
                blogPost.StartDateUtc = model.StartDate;
                blogPost.EndDateUtc   = model.EndDate;
                blogPost.CreatedOnUtc = DateTime.UtcNow;
                _blogService.InsertBlogPost(blogPost);

                //search engine name
                var seName = blogPost.ValidateSeName(model.SeName, model.Title, true);
                _urlRecordService.SaveSlug(blogPost, seName, blogPost.LanguageId);

                //Stores
                _storeMappingService.SaveStoreMappings <BlogPost>(blogPost, model.SelectedStoreIds);

                NotifySuccess(_localizationService.GetResource("Admin.ContentManagement.Blog.BlogPosts.Added"));
                return(continueEditing ? RedirectToAction("Edit", new { id = blogPost.Id }) : RedirectToAction("List"));
            }

            //If we got this far, something failed, redisplay form
            ViewBag.AllLanguages = _languageService.GetAllLanguages(true);
            //Stores
            PrepareStoresMappingModel(model, null, true);
            return(View(model));
        }
コード例 #3
0
        public ActionResult Create(CheckoutAttributeModel model, bool continueEditing)
        {
            if (!_services.Permissions.Authorize(StandardPermissionProvider.ManageCatalog))
            {
                return(AccessDeniedView());
            }

            if (ModelState.IsValid)
            {
                var checkoutAttribute = model.ToEntity();
                _checkoutAttributeService.InsertCheckoutAttribute(checkoutAttribute);

                UpdateAttributeLocales(checkoutAttribute, model);

                _storeMappingService.SaveStoreMappings(checkoutAttribute, model.SelectedStoreIds);

                //activity log
                _customerActivityService.InsertActivity("AddNewCheckoutAttribute", _services.Localization.GetResource("ActivityLog.AddNewCheckoutAttribute"), checkoutAttribute.Name);

                NotifySuccess(_services.Localization.GetResource("Admin.Catalog.Attributes.CheckoutAttributes.Added"));
                return(continueEditing ? RedirectToAction("Edit", new { id = checkoutAttribute.Id }) : RedirectToAction("List"));
            }

            //If we got this far, something failed, redisplay form
            PrepareCheckoutAttributeModel(model, null, true);
            return(View(model));
        }
コード例 #4
0
        public ActionResult CreateForumGroup(ForumGroupModel model, bool continueEditing)
        {
            if (!_services.Permissions.Authorize(StandardPermissionProvider.ManageForums))
            {
                return(AccessDeniedView());
            }

            if (ModelState.IsValid)
            {
                var forumGroup = model.ToEntity();

                _forumService.InsertForumGroup(forumGroup);

                model.SeName = forumGroup.ValidateSeName(model.SeName, forumGroup.Name, true);
                _urlRecordService.SaveSlug(forumGroup, model.SeName, 0);

                UpdateLocales(model, forumGroup);

                _storeMappingService.SaveStoreMappings <ForumGroup>(forumGroup, model.SelectedStoreIds);

                NotifySuccess(_services.Localization.GetResource("Admin.ContentManagement.Forums.ForumGroup.Added"));

                return(continueEditing ? RedirectToAction("EditForumGroup", new { forumGroup.Id }) : RedirectToAction("List"));
            }

            //If we got this far, something failed, redisplay form

            PrepareForumGroupModel(model, null, true);

            return(View(model));
        }
コード例 #5
0
        public ActionResult Create(LanguageModel model, bool continueEditing)
        {
            if (!_services.Permissions.Authorize(StandardPermissionProvider.ManageLanguages))
            {
                return(AccessDeniedView());
            }

            if (ModelState.IsValid)
            {
                var language = model.ToEntity();
                _languageService.InsertLanguage(language);

                _storeMappingService.SaveStoreMappings <Language>(language, model.SelectedStoreIds);

                var plugins         = _pluginFinder.GetPluginDescriptors(true);
                var filterLanguages = new List <Language>()
                {
                    language
                };

                foreach (var plugin in plugins)
                {
                    _services.Localization.ImportPluginResourcesFromXml(plugin, null, false, filterLanguages);
                }

                NotifySuccess(T("Admin.Configuration.Languages.Added"));
                return(continueEditing ? RedirectToAction("Edit", new { id = language.Id }) : RedirectToAction("List"));
            }

            PrepareLanguageModel(model, null, true);

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
コード例 #6
0
        public ActionResult Create(CountryModel model, bool continueEditing)
        {
            if (!_services.Permissions.Authorize(StandardPermissionProvider.ManageCountries))
            {
                return(AccessDeniedView());
            }

            if (ModelState.IsValid)
            {
                var country = model.ToEntity();
                _countryService.InsertCountry(country);

                UpdateLocales(country, model);

                _storeMappingService.SaveStoreMappings <Country>(country, model.SelectedStoreIds);

                NotifySuccess(T("Admin.Configuration.Countries.Added"));

                return(continueEditing ? RedirectToAction("Edit", new { id = country.Id }) : RedirectToAction("List"));
            }

            PrepareCountryModel(model, null, true);

            return(View(model));
        }
コード例 #7
0
        public ActionResult Create(PollModel model, bool continueEditing)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManagePolls))
            {
                return(AccessDeniedView());
            }

            if (ModelState.IsValid)
            {
                var poll = model.ToEntity();
                poll.StartDateUtc = model.StartDate;
                poll.EndDateUtc   = model.EndDate;

                _pollService.InsertPoll(poll);

                _storeMappingService.SaveStoreMappings <Poll>(poll, model.SelectedStoreIds);

                NotifySuccess(_localizationService.GetResource("Admin.ContentManagement.Polls.Added"));
                return(continueEditing ? RedirectToAction("Edit", new { id = poll.Id }) : RedirectToAction("List"));
            }

            //If we got this far, something failed, redisplay form
            ViewBag.AllLanguages = _languageService.GetAllLanguages(true);

            PreparePollModel(model, null, true);

            return(View(model));
        }
コード例 #8
0
        public ActionResult Create(ManufacturerModel model, bool continueEditing)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageCatalog))
            {
                return(AccessDeniedView());
            }

            if (ModelState.IsValid)
            {
                var manufacturer = model.ToEntity();

                MediaHelper.UpdatePictureTransientStateFor(manufacturer, m => m.PictureId);

                _manufacturerService.InsertManufacturer(manufacturer);

                // search engine name
                model.SeName = manufacturer.ValidateSeName(model.SeName, manufacturer.Name, true);
                _urlRecordService.SaveSlug(manufacturer, model.SeName, 0);

                // locales
                UpdateLocales(manufacturer, model);

                // discounts
                var allDiscounts = _discountService.GetAllDiscounts(DiscountType.AssignedToManufacturers, null, true);
                foreach (var discount in allDiscounts)
                {
                    if (model.SelectedDiscountIds != null && model.SelectedDiscountIds.Contains(discount.Id))
                    {
                        manufacturer.AppliedDiscounts.Add(discount);
                    }
                }

                var hasDiscountsApplied = manufacturer.AppliedDiscounts.Count > 0;
                if (hasDiscountsApplied)
                {
                    manufacturer.HasDiscountsApplied = manufacturer.AppliedDiscounts.Count > 0;
                    _manufacturerService.UpdateManufacturer(manufacturer);
                }

                // update picture seo file name
                UpdatePictureSeoNames(manufacturer);

                // Stores
                _storeMappingService.SaveStoreMappings <Manufacturer>(manufacturer, model.SelectedStoreIds);

                // activity log
                _customerActivityService.InsertActivity("AddNewManufacturer", _localizationService.GetResource("ActivityLog.AddNewManufacturer"), manufacturer.Name);

                NotifySuccess(_localizationService.GetResource("Admin.Catalog.Manufacturers.Added"));
                return(continueEditing ? RedirectToAction("Edit", new { id = manufacturer.Id }) : RedirectToAction("List"));
            }

            //If we got this far, something failed, redisplay form
            //templates
            PrepareTemplatesModel(model);
            PrepareManufacturerModel(model, null, true);

            return(View(model));
        }
コード例 #9
0
        public ActionResult Create(ManufacturerModel model, bool continueEditing)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageCatalog))
            {
                return(AccessDeniedView());
            }

            if (ModelState.IsValid)
            {
                var manufacturer = model.ToEntity();
                manufacturer.CreatedOnUtc = DateTime.UtcNow;
                manufacturer.UpdatedOnUtc = DateTime.UtcNow;

                _manufacturerService.InsertManufacturer(manufacturer);

                //search engine name
                model.SeName = manufacturer.ValidateSeName(model.SeName, manufacturer.Name, true);
                _urlRecordService.SaveSlug(manufacturer, model.SeName, 0);

                //locales
                UpdateLocales(manufacturer, model);

                //update picture seo file name
                UpdatePictureSeoNames(manufacturer);

                //Stores
                _storeMappingService.SaveStoreMappings <Manufacturer>(manufacturer, model.SelectedStoreIds);

                //activity log
                _customerActivityService.InsertActivity("AddNewManufacturer", _localizationService.GetResource("ActivityLog.AddNewManufacturer"), manufacturer.Name);

                NotifySuccess(_localizationService.GetResource("Admin.Catalog.Manufacturers.Added"));
                return(continueEditing ? RedirectToAction("Edit", new { id = manufacturer.Id }) : RedirectToAction("List"));
            }

            //If we got this far, something failed, redisplay form
            //templates
            PrepareTemplatesModel(model);
            PrepareManufacturerModel(model, null, true);

            return(View(model));
        }
コード例 #10
0
        public ActionResult Edit(TopicModel model, bool continueEditing, FormCollection form)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageTopics))
            {
                return(AccessDeniedView());
            }

            var topic = _topicService.GetTopicById(model.Id);

            if (topic == null)
            {
                return(RedirectToAction("List"));
            }

            if (!model.IsPasswordProtected)
            {
                model.Password = null;
            }

            if (ModelState.IsValid)
            {
                topic = model.ToEntity(topic);

                if (model.WidgetZone != null)
                {
                    topic.WidgetZone = string.Join(",", model.WidgetZone);
                }

                _topicService.UpdateTopic(topic);

                model.SeName = topic.ValidateSeName(model.SeName, topic.Title.NullEmpty() ?? topic.SystemName, true);
                _urlRecordService.SaveSlug(topic, model.SeName, 0);

                //Stores
                _storeMappingService.SaveStoreMappings <Topic>(topic, model.SelectedStoreIds);

                //locales
                UpdateLocales(topic, model);

                _eventPublisher.Publish(new ModelBoundEvent(model, topic, form));

                NotifySuccess(_localizationService.GetResource("Admin.ContentManagement.Topics.Updated"));
                return(continueEditing ? RedirectToAction("Edit", topic.Id) : RedirectToAction("List"));
            }

            // If we got this far, something failed, redisplay form
            model.Url = Url.RouteUrl("Topic", new { SeName = topic.GetSeName() }, "http");
            PrepareStoresMappingModel(model, topic, true);

            return(View(model));
        }
コード例 #11
0
        public ActionResult CreateMethod(ShippingMethodModel model, bool continueEditing)
        {
            if (!_services.Permissions.Authorize(StandardPermissionProvider.ManageShippingSettings))
            {
                return(AccessDeniedView());
            }

            if (ModelState.IsValid)
            {
                var sm = model.ToEntity();
                _shippingService.InsertShippingMethod(sm);

                _storeMappingService.SaveStoreMappings(sm, model.SelectedStoreIds);

                UpdateLocales(sm, model);

                NotifySuccess(_services.Localization.GetResource("Admin.Configuration.Shipping.Methods.Added"));
                return(continueEditing ? RedirectToAction("EditMethod", new { id = sm.Id }) : RedirectToAction("Methods"));
            }

            // If we got this far, something failed, redisplay form.
            return(View(model));
        }
コード例 #12
0
        private void ProcessStoreMappings(IImportExecuteContext context, ImportRow <Category>[] batch)
        {
            foreach (var row in batch)
            {
                var limitedToStore = row.GetDataValue <bool>("LimitedToStores");

                if (limitedToStore)
                {
                    var storeIds = row.GetDataValue <List <int> >("StoreIds");

                    _storeMappingService.SaveStoreMappings(row.Entity, storeIds == null ? new int[0] : storeIds.ToArray());
                }
            }
        }
コード例 #13
0
        public ActionResult Create(CampaignModel model, bool continueEditing)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageCampaigns))
            {
                return(AccessDeniedView());
            }

            if (ModelState.IsValid)
            {
                var campaign = model.ToEntity();
                campaign.CreatedOnUtc = DateTime.UtcNow;
                _campaignService.InsertCampaign(campaign);

                _storeMappingService.SaveStoreMappings <Campaign>(campaign, model.SelectedStoreIds);

                NotifySuccess(_localizationService.GetResource("Admin.Promotions.Campaigns.Added"));
                return(continueEditing ? RedirectToAction("Edit", new { id = campaign.Id }) : RedirectToAction("List"));
            }

            //If we got this far, something failed, redisplay form
            PrepareCampaignModel(model, null, true);

            return(View(model));
        }
コード例 #14
0
        public ActionResult Edit(MessageTemplateModel model, bool continueEditing)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageMessageTemplates))
            {
                return(AccessDeniedView());
            }

            var messageTemplate = _messageTemplateService.GetMessageTemplateById(model.Id);

            if (messageTemplate == null)
            {
                return(RedirectToAction("List"));
            }

            if (ModelState.IsValid)
            {
                messageTemplate = model.ToEntity(messageTemplate);

                MediaHelper.UpdateDownloadTransientStateFor(messageTemplate, x => x.Attachment1FileId);
                MediaHelper.UpdateDownloadTransientStateFor(messageTemplate, x => x.Attachment2FileId);
                MediaHelper.UpdateDownloadTransientStateFor(messageTemplate, x => x.Attachment3FileId);

                _messageTemplateService.UpdateMessageTemplate(messageTemplate);

                // Stores
                _storeMappingService.SaveStoreMappings <MessageTemplate>(messageTemplate, model.SelectedStoreIds);

                // locales
                UpdateLocales(messageTemplate, model);

                NotifySuccess(_localizationService.GetResource("Admin.ContentManagement.MessageTemplates.Updated"));
                return(continueEditing ? RedirectToAction("Edit", messageTemplate.Id) : RedirectToAction("List"));
            }


            //If we got this far, something failed, redisplay form
            FillTokensTree(model.TokensTree, _messageTokenProvider.GetListOfAllowedTokens());

            //available email accounts
            foreach (var ea in _emailAccountService.GetAllEmailAccounts())
            {
                model.AvailableEmailAccounts.Add(ea.ToModel());
            }

            //Store
            PrepareStoresMappingModel(model, messageTemplate, true);
            return(View(model));
        }
コード例 #15
0
        public ActionResult Edit(TopicModel model, bool continueEditing)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageTopics))
            {
                return(AccessDeniedView());
            }

            var topic = _topicService.GetTopicById(model.Id);

            if (topic == null)
            {
                return(RedirectToAction("List"));
            }

            model.Url = Url.RouteUrl("Topic", new { SystemName = topic.SystemName }, "http");

            if (!model.IsPasswordProtected)
            {
                model.Password = null;
            }

            if (ModelState.IsValid)
            {
                topic = model.ToEntity(topic);
                _topicService.UpdateTopic(topic);

                //Stores
                _storeMappingService.SaveStoreMappings <Topic>(topic, model.SelectedStoreIds);

                //locales
                UpdateLocales(topic, model);

                NotifySuccess(_localizationService.GetResource("Admin.ContentManagement.Topics.Updated"));
                return(continueEditing ? RedirectToAction("Edit", topic.Id) : RedirectToAction("List"));
            }

            //If we got this far, something failed, redisplay form
            //Store
            PrepareStoresMappingModel(model, topic, true);

            return(View(model));
        }
コード例 #16
0
        private int ProcessProducts(ICollection <ImportRow <Product> > batch, ImportResult result)
        {
            _rsProduct.AutoCommitEnabled = true;

            Product lastInserted = null;
            Product lastUpdated  = null;

            foreach (var row in batch)
            {
                if (row.Count == 0)
                {
                    continue;
                }

                Product product = null;

                object key;

                // try get by int ID
                if (row.TryGetValue("Id", out key) && key.ToString().ToInt() > 0)
                {
                    product = _productService.GetProductById(key.ToString().ToInt());
                }

                // try get by SKU
                if (product == null && row.TryGetValue("SKU", out key))
                {
                    product = _productService.GetProductBySku(key.ToString());
                }

                // try get by GTIN
                if (product == null && row.TryGetValue("Gtin", out key))
                {
                    product = _productService.GetProductByGtin(key.ToString());
                }

                if (product == null)
                {
                    // a Name is required with new products.
                    if (!row.ContainsKey("Name"))
                    {
                        result.AddError("The 'Name' field is required for new products. Skipping row.", row.GetRowInfo(), "Name");
                        continue;
                    }
                    product = new Product();
                }

                row.Initialize(product, row["Name"].ToString());

                if (!row.IsNew)
                {
                    if (!product.Name.Equals(row["Name"].ToString(), StringComparison.OrdinalIgnoreCase))
                    {
                        // Perf: use this later for SeName updates.
                        row.NameChanged = true;
                    }
                }

                row.SetProperty(result, product, (x) => x.Sku);
                row.SetProperty(result, product, (x) => x.Gtin);
                row.SetProperty(result, product, (x) => x.ManufacturerPartNumber);
                row.SetProperty(result, product, (x) => x.ProductTypeId, (int)ProductType.SimpleProduct);
                row.SetProperty(result, product, (x) => x.ParentGroupedProductId);
                row.SetProperty(result, product, (x) => x.VisibleIndividually, true);
                row.SetProperty(result, product, (x) => x.Name);
                row.SetProperty(result, product, (x) => x.ShortDescription);
                row.SetProperty(result, product, (x) => x.FullDescription);
                row.SetProperty(result, product, (x) => x.ProductTemplateId);
                row.SetProperty(result, product, (x) => x.ShowOnHomePage);
                row.SetProperty(result, product, (x) => x.MetaKeywords);
                row.SetProperty(result, product, (x) => x.MetaDescription);
                row.SetProperty(result, product, (x) => x.MetaTitle);
                row.SetProperty(result, product, (x) => x.AllowCustomerReviews, true);
                row.SetProperty(result, product, (x) => x.Published, true);
                row.SetProperty(result, product, (x) => x.IsGiftCard);
                row.SetProperty(result, product, (x) => x.GiftCardTypeId);
                row.SetProperty(result, product, (x) => x.RequireOtherProducts);
                row.SetProperty(result, product, (x) => x.RequiredProductIds);
                row.SetProperty(result, product, (x) => x.AutomaticallyAddRequiredProducts);
                row.SetProperty(result, product, (x) => x.IsDownload);
                row.SetProperty(result, product, (x) => x.DownloadId);
                row.SetProperty(result, product, (x) => x.UnlimitedDownloads, true);
                row.SetProperty(result, product, (x) => x.MaxNumberOfDownloads, 10);
                row.SetProperty(result, product, (x) => x.DownloadActivationTypeId, 1);
                row.SetProperty(result, product, (x) => x.HasSampleDownload);
                row.SetProperty(result, product, (x) => x.SampleDownloadId, (int?)null, ZeroToNull);
                row.SetProperty(result, product, (x) => x.HasUserAgreement);
                row.SetProperty(result, product, (x) => x.UserAgreementText);
                row.SetProperty(result, product, (x) => x.IsRecurring);
                row.SetProperty(result, product, (x) => x.RecurringCycleLength, 100);
                row.SetProperty(result, product, (x) => x.RecurringCyclePeriodId);
                row.SetProperty(result, product, (x) => x.RecurringTotalCycles, 10);
                row.SetProperty(result, product, (x) => x.IsShipEnabled, true);
                row.SetProperty(result, product, (x) => x.IsFreeShipping);
                row.SetProperty(result, product, (x) => x.AdditionalShippingCharge);
                row.SetProperty(result, product, (x) => x.IsEsd);
                row.SetProperty(result, product, (x) => x.IsTaxExempt);
                row.SetProperty(result, product, (x) => x.TaxCategoryId, 1);
                row.SetProperty(result, product, (x) => x.ManageInventoryMethodId);
                row.SetProperty(result, product, (x) => x.StockQuantity, 10000);
                row.SetProperty(result, product, (x) => x.DisplayStockAvailability);
                row.SetProperty(result, product, (x) => x.DisplayStockQuantity);
                row.SetProperty(result, product, (x) => x.MinStockQuantity);
                row.SetProperty(result, product, (x) => x.LowStockActivityId);
                row.SetProperty(result, product, (x) => x.NotifyAdminForQuantityBelow, 1);
                row.SetProperty(result, product, (x) => x.BackorderModeId);
                row.SetProperty(result, product, (x) => x.AllowBackInStockSubscriptions);
                row.SetProperty(result, product, (x) => x.OrderMinimumQuantity, 1);
                row.SetProperty(result, product, (x) => x.OrderMaximumQuantity, 10000);
                row.SetProperty(result, product, (x) => x.AllowedQuantities);
                row.SetProperty(result, product, (x) => x.DisableBuyButton);
                row.SetProperty(result, product, (x) => x.DisableWishlistButton);
                row.SetProperty(result, product, (x) => x.AvailableForPreOrder);
                row.SetProperty(result, product, (x) => x.CallForPrice);
                row.SetProperty(result, product, (x) => x.Price);
                row.SetProperty(result, product, (x) => x.OldPrice);
                row.SetProperty(result, product, (x) => x.ProductCost);
                row.SetProperty(result, product, (x) => x.SpecialPrice);
                row.SetProperty(result, product, (x) => x.SpecialPriceStartDateTimeUtc, null, OADateToUtcDate);
                row.SetProperty(result, product, (x) => x.SpecialPriceEndDateTimeUtc, null, OADateToUtcDate);
                row.SetProperty(result, product, (x) => x.CustomerEntersPrice);
                row.SetProperty(result, product, (x) => x.MinimumCustomerEnteredPrice);
                row.SetProperty(result, product, (x) => x.MaximumCustomerEnteredPrice, 1000);
                row.SetProperty(result, product, (x) => x.Weight);
                row.SetProperty(result, product, (x) => x.Length);
                row.SetProperty(result, product, (x) => x.Width);
                row.SetProperty(result, product, (x) => x.Height);
                row.SetProperty(result, product, (x) => x.DeliveryTimeId);
                row.SetProperty(result, product, (x) => x.QuantityUnitId);
                row.SetProperty(result, product, (x) => x.BasePriceEnabled);
                row.SetProperty(result, product, (x) => x.BasePriceMeasureUnit);
                row.SetProperty(result, product, (x) => x.BasePriceAmount);
                row.SetProperty(result, product, (x) => x.BasePriceBaseAmount);
                row.SetProperty(result, product, (x) => x.BundlePerItemPricing);
                row.SetProperty(result, product, (x) => x.BundlePerItemShipping);
                row.SetProperty(result, product, (x) => x.BundlePerItemShoppingCart);
                row.SetProperty(result, product, (x) => x.BundleTitleText);
                row.SetProperty(result, product, (x) => x.AvailableStartDateTimeUtc, null, OADateToUtcDate);
                row.SetProperty(result, product, (x) => x.AvailableEndDateTimeUtc, null, OADateToUtcDate);
                row.SetProperty(result, product, (x) => x.LimitedToStores);

                string storeIds = row.GetValue <string>("StoreIds");
                if (storeIds.HasValue())
                {
                    _storeMappingService.SaveStoreMappings(product,
                                                           row["StoreIds"].ToString()
                                                           .Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries).Select(x => Convert.ToInt32(x.Trim())).ToArray());
                }

                row.SetProperty(result, product, (x) => x.CreatedOnUtc, DateTime.UtcNow, OADateToUtcDate);

                product.UpdatedOnUtc = DateTime.UtcNow;

                if (row.IsTransient)
                {
                    _rsProduct.Insert(product);
                    lastInserted = product;
                }
                else
                {
                    _rsProduct.Update(product);
                    lastUpdated = product;
                }
            }

            // commit whole batch at once
            var num = _rsProduct.Context.SaveChanges();

            // Perf: notify only about LAST insertion and update
            if (lastInserted != null)
            {
                _eventPublisher.EntityInserted(lastInserted);
            }
            if (lastUpdated != null)
            {
                _eventPublisher.EntityUpdated(lastUpdated);
            }

            return(num);
        }
コード例 #17
0
        public ActionResult Edit(string systemName, bool continueEditing, PaymentMethodEditModel model, FormCollection form)
        {
            if (!_services.Permissions.Authorize(StandardPermissionProvider.ManagePaymentMethods))
            {
                return(AccessDeniedView());
            }

            var provider = _paymentService.LoadPaymentMethodBySystemName(systemName);

            if (provider == null)
            {
                return(HttpNotFound());
            }

            _pluginMediator.SetSetting(provider.Metadata, "FriendlyName", model.FriendlyName);
            _pluginMediator.SetSetting(provider.Metadata, "Description", model.Description);

            var paymentMethod = _paymentService.GetPaymentMethodBySystemName(systemName);

            if (paymentMethod == null)
            {
                paymentMethod = new PaymentMethod {
                    PaymentMethodSystemName = systemName
                }
            }
            ;

            paymentMethod.FullDescription        = model.FullDescription;
            paymentMethod.RoundOrderTotalEnabled = model.RoundOrderTotalEnabled;
            paymentMethod.LimitedToStores        = model.LimitedToStores;

            if (paymentMethod.Id == 0)
            {
                _paymentService.InsertPaymentMethod(paymentMethod);
            }
            else
            {
                _paymentService.UpdatePaymentMethod(paymentMethod);
            }

            _storeMappingService.SaveStoreMappings(paymentMethod, model.SelectedStoreIds);

            foreach (var localized in model.Locales)
            {
                _pluginMediator.SaveLocalizedValue(provider.Metadata, localized.LanguageId, "FriendlyName", localized.FriendlyName);
                _pluginMediator.SaveLocalizedValue(provider.Metadata, localized.LanguageId, "Description", localized.Description);

                _localizedEntityService.SaveLocalizedValue(paymentMethod, x => x.FullDescription, localized.FullDescription, localized.LanguageId);
            }

            _services.EventPublisher.Publish(new ModelBoundEvent(model, paymentMethod, form));

            NotifySuccess(T("Admin.Common.DataEditSuccess"));

            return(continueEditing ?
                   RedirectToAction("Edit", "Payment", new { systemName = systemName }) :
                   RedirectToAction("Providers", "Payment"));
        }

        #endregion
    }
コード例 #18
0
        public ActionResult Create(CategoryModel model, bool continueEditing, FormCollection form)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageCatalog))
            {
                return(AccessDeniedView());
            }

            if (ModelState.IsValid)
            {
                var category = model.ToEntity();
                category.CreatedOnUtc = DateTime.UtcNow;
                category.UpdatedOnUtc = DateTime.UtcNow;
                _categoryService.InsertCategory(category);

                //search engine name
                model.SeName = category.ValidateSeName(model.SeName, category.Name, true);
                _urlRecordService.SaveSlug(category, model.SeName, 0);

                //locales
                UpdateLocales(category, model);

                //disounts
                var allDiscounts = _discountService.GetAllDiscounts(DiscountType.AssignedToCategories, null, true);
                foreach (var discount in allDiscounts)
                {
                    if (model.SelectedDiscountIds != null && model.SelectedDiscountIds.Contains(discount.Id))
                    {
                        category.AppliedDiscounts.Add(discount);
                    }
                }
                _categoryService.UpdateCategory(category);

                //update "HasDiscountsApplied" property
                _categoryService.UpdateHasDiscountsApplied(category);

                //update picture seo file name
                UpdatePictureSeoNames(category);

                //ACL (customer roles)
                SaveCategoryAcl(category, model);

                //Stores
                _storeMappingService.SaveStoreMappings <Category>(category, model.SelectedStoreIds);

                _eventPublisher.Publish(new ModelBoundEvent(model, category, form));

                //activity log
                _customerActivityService.InsertActivity("AddNewCategory", _localizationService.GetResource("ActivityLog.AddNewCategory"), category.Name);

                NotifySuccess(_localizationService.GetResource("Admin.Catalog.Categories.Added"));
                return(continueEditing ? RedirectToAction("Edit", new { id = category.Id }) : RedirectToAction("List"));
            }

            //If we got this far, something failed, redisplay form
            //templates
            PrepareTemplatesModel(model);
            //parent categories
            if (model.ParentCategoryId.HasValue)
            {
                var parentCategory = _categoryService.GetCategoryById(model.ParentCategoryId.Value);
                if (parentCategory != null && !parentCategory.Deleted)
                {
                    model.ParentCategoryBreadcrumb = parentCategory.GetCategoryBreadCrumb(_categoryService);
                }
                else
                {
                    model.ParentCategoryId = 0;
                }
            }

            PrepareCategoryModel(model, null, true);
            //ACL
            PrepareAclModel(model, null, true);
            //Stores
            PrepareStoresMappingModel(model, null, true);
            return(View(model));
        }