public IActionResult Update(String id, Website websiteIn)
        {
            var website = _websiteService.Get(id);

            if (website == null)
            {
                return(NotFound());
            }

            _websiteService.Update(id, websiteIn);

            return(NoContent());
        }
Ejemplo n.º 2
0
        public void UpdatePropertyReferences(StructureInfo structureInfo, PackageInfo packageInfo)
        {
            var website = _websiteService.Get(structureInfo.Id(packageInfo.Website.SystemId)).MakeWritableClone();

            AddProperties <WebsiteArea>(structureInfo, structureInfo.Website.Website.Fields, website.Fields, false);
            _websiteService.Update(website);

            var channel = _channelService.Get(packageInfo.Channel.SystemId).MakeWritableClone();

            channel.CountryLinks = structureInfo.Website.Channel.CountryLinks.Select(x => new ChannelToCountryLink(structureInfo.Id(x.CountrySystemId))
            {
                DeliveryMethodSystemIds = x.DeliveryMethodSystemIds.Select(z => ModuleECommerce.Instance.DeliveryMethods.Get(packageInfo.DeliveryMethods.Find(zz => zz.ID == z)?.Name ?? string.Empty, ModuleECommerce.Instance.AdminToken)?.ID ?? Guid.Empty).Where(z => z != Guid.Empty).ToList(),
                PaymentMethodSystemIds  = x.PaymentMethodSystemIds.Select(z =>
                {
                    var payment = packageInfo.PaymentMethods.Find(zz => zz.ID == z);
                    if (payment == null)
                    {
                        return(Guid.Empty);
                    }
                    return(ModuleECommerce.Instance.PaymentMethods.Get(payment.Name, payment.PaymentProviderName, ModuleECommerce.Instance.AdminToken)?.ID ?? Guid.Empty);
                }).Where(z => z != Guid.Empty).ToList(),
            }).ToList();
            AddProperties <GlobalizationArea>(structureInfo, structureInfo.Website.Channel.Fields, channel.Fields, false, new List <string> {
                SystemFieldDefinitionConstants.Name
            });
            _channelService.Update(channel);

            var inventory = _inventoryService.Get(packageInfo.Inventory.SystemId).MakeWritableClone();

            inventory.CountryLinks = structureInfo.ProductCatalog.Inventory.CountryLinks.Select(x => new InventoryToCountryLink(structureInfo.Id(x.CountrySystemId))).ToList();
            _inventoryService.Update(inventory);

            var priceList = _priceListService.Get(packageInfo.PriceList.SystemId).MakeWritableClone();

            priceList.CountryLinks = structureInfo.ProductCatalog.PriceList.CountryLinks.Select(x => new PriceListToCountryLink(structureInfo.Id(x.CountrySystemId))).ToList();
            _priceListService.Update(priceList);
        }
Ejemplo n.º 3
0
        public override void CreateWebsiteTexts(IWebsiteTextSource textSource)
        {
            try
            {
                using (_solution.SystemToken.Use("WebsiteTextSetup.CreateWebsiteStrings"))
                {
                    var allWebsites = _websiteService.GetAll();

                    foreach (var ws in allWebsites)
                    {
                        var website = ws.MakeWritableClone();


                        foreach (var text in textSource.GetTexts())
                        {
                            try
                            {
                                if (text == null)
                                {
                                    throw new Exception("Text is null");
                                }
                                if (text.Id == null)
                                {
                                    throw new Exception("Text.Id cannot be null");
                                }

                                // If the text should be generated on specific websites only and current site is not among those then skip
                                if (text.WebsiteIds.Any() && !text.WebsiteIds.Any(w => website.SystemId.Equals(w)))
                                {
                                    continue;
                                }

                                var serverTextKey = GetTextKey(textSource.Prefix, text.Id, false);
                                var clientTextKey = GetTextKey(textSource.Prefix, text.Id, true);

                                // If they dont exist here its a first time insert, so then insert all cultures
                                var serverTextKeyInitialInsert = !website.Texts.Keys.Contains(serverTextKey);
                                var clientTextKeyInitialInsert = !website.Texts.Keys.Contains(clientTextKey);

                                foreach (var textValue in text.Name)
                                {
                                    // If the string should be avaliable on the server, in other words generated as defined only
                                    if (text.ServerAvailable)
                                    {
                                        AddOrUpdateValue(textSource, website, textValue, serverTextKey, serverTextKeyInitialInsert);
                                    }

                                    // If the string shold be avaliable on client, create another string with js.-prefix
                                    // this makes the string avaliable in clientscript from window.__litium.translation
                                    // See https://docs.litium.com/documentation/litium-accelerators/develop/architecture/accelerator-mvc
                                    if (text.ClientAvailable)
                                    {
                                        AddOrUpdateValue(textSource, website, textValue, clientTextKey, clientTextKeyInitialInsert);
                                    }
                                }
                            }
                            catch (Exception exception)
                            {
                                _logger.LogError($"Error creating website text '{text?.Id}'", exception);
                            }
                        }

                        _websiteService.Update(website);
                    }
                }
            }
            catch (Exception exception)
            {
                _logger.LogError("Error creating website texts", exception);
            }
        }