Exemplo n.º 1
0
 public IEnumerable <CultureBase> GetAllCulturesBase()
 {
     return
         (_cultureRepository
          .GetAll()
          .ProjectTo <CultureBase>()
          .ToList());
 }
        protected IEnumerable <ViewModels.Shared.Localization> CreateEmptyLocalizations()
        {
            ICultureRepository cultureRepository = this.HttpContext.RequestServices.GetService <ICultureRepository>();

            return(cultureRepository.GetAll().Select(c => new ViewModels.Shared.Localization()
            {
                CultureCode = c.Code
            }));
        }
        protected IEnumerable <ViewModels.Shared.Localization> CreateLocalizationsFor(LocalizationSet localizationSet)
        {
            ICultureRepository cultureRepository = this.HttpContext.RequestServices.GetService <ICultureRepository>();

            return(cultureRepository.GetAll()
                   .Select(c => new ViewModels.Shared.Localization()
            {
                CultureCode = c.Code, Value = localizationSet.Localizations.FirstOrDefault(l => l.CultureCode == c.Code)?.Value
            }));
        }
        private void CreateLocalizations(PropertyInfo propertyInfo, LocalizationSet localizationSet)
        {
            ICultureRepository      cultureRepository      = this.HttpContext.RequestServices.GetService <ICultureRepository>();
            ILocalizationRepository localizationRepository = this.HttpContext.RequestServices.GetService <ILocalizationRepository>();
            Storage storage = this.HttpContext.RequestServices.GetService <Storage>();

            foreach (Culture culture in cultureRepository.GetAll())
            {
                Localization localization = new Localization();

                localization.LocalizationSetId = localizationSet.Id;
                localization.CultureCode       = culture.Code;
                localization.Value             = this.Request.Form[propertyInfo.Name + culture.Code];
                localizationRepository.Create(localization);
            }

            storage.SaveChanges();
        }
        private void HandleViewModelMultilingualProperties(ActionExecutingContext actionExecutingContext)
        {
            ViewModelBase viewModel = this.GetViewModelFromActionExecutingContext(actionExecutingContext);

            if (viewModel == null)
            {
                return;
            }

            ICultureRepository cultureRepository = this.HttpContext.RequestServices.GetService <ICultureRepository>();

            try
            {
                foreach (PropertyInfo propertyInfo in this.GetLocalizablePropertiesFromViewModel(viewModel))
                {
                    this.ModelState.Remove(propertyInfo.Name);

                    bool hasRequiredAttribute = propertyInfo.CustomAttributes.Any(ca => ca.AttributeType == typeof(RequiredAttribute));

                    foreach (Culture culture in cultureRepository.GetAll())
                    {
                        string identity = propertyInfo.Name + culture.Code;
                        string value    = this.Request.Form[identity];

                        this.ModelState.SetModelValue(identity, value, value);

                        if (hasRequiredAttribute && string.IsNullOrEmpty(value))
                        {
                            this.ModelState[identity].ValidationState = ModelValidationState.Invalid;
                            this.ModelState[identity].Errors.Add(string.Empty);
                        }

                        else
                        {
                            this.ModelState[identity].ValidationState = ModelValidationState.Valid;
                        }
                    }
                }
            }

            catch { }
        }