Exemple #1
0
        public ActionResult Detail(int id)
        {
            var request = new GetCultureDetailRequest
                              {
                                  Id = id,
                                  CultureId = CultureInfo.GetCultureInfo("vi-VN").LCID
                              };

            var response = _globalizationSettings.GetCultureDetail(request);

            return View(response);
        }
        public GetCultureDetailResponse GetCultureDetail(GetCultureDetailRequest request)
        {
            var response = new GetCultureDetailResponse();
            // Include statement need to deep enough to cover all information return
            var cul = Uow.Cultures.Get(c => c.Id == request.Id, null, o => o.Language.Localizations, o => o.Country.Localizations, o => o._localizations.Select(c => c.Culture._localizations)).SingleOrDefault();
            if (cul != null)
                response.CultureData = new CultureData
                                       {
                                           Id = cul.Id,
                                           Code = cul.Code,
                                           Name = cul._localizations.Join(new[]
                                                    {
                                                        new {Index = 0, CultureId = request.CultureId},
                                                        new { Index = 1, CultureId = CultureInfo.InvariantCulture.LCID }
                                                    }, cl => cl.CultureId,
                                                 o => o.CultureId, (cl, o) => new { Index = o.Index, Name = cl.Name })
                                                 .OrderBy(o => o.Index)
                                                 .Select(o => o.Name)
                                                 .FirstOrDefault(),
                                           Language = cul.Language != null ? cul.Language.ToLanaguageData(request.CultureId) :
                                                    new LanguageData { Iso2 = "IV", Iso3 = "IVL", Name = "Invariant Lanaguage" },
                                           Country = cul.Country != null ? cul.Country.ToCountryData(request.CultureId) :
                                                    new CountryData() { Iso2 = "IV", Iso3 = "IVL", Name = "Invariant Country" },
                                           Localized = cul._localizations.Select(c => new CultureLocalizedData
                                                {
                                                    Id = c.Id,
                                                    CultureId = c.CultureId,
                                                    CultureName = c.Culture._localizations.Join(new[]
                                                        {
                                                            new { Index = 0, CultureId = request.CultureId},
                                                            new { Index = 1, CultureId = CultureInfo.InvariantCulture.LCID }
                                                        }, cl => cl.CultureId,
                                                        o => o.CultureId, (cl, o) => new { Index = o.Index, Name = cl.Name })
                                                        .OrderBy(o => o.Index)
                                                        .Select(o => o.Name)
                                                        .FirstOrDefault(),
                                                    Name = c.Name
                                                })
                                       };

            return response;
        }