Ejemplo n.º 1
0
        public ActionResult Index()
        {
            var request = new GetLanguagesRequest
                              {
                                  CultureId = CultureInfo.GetCultureInfo("vi-VN").LCID,
                                  Index = 1,
                                  NumberOfResultsPerPage = 5
                              };
            var response = _globalizationSettings.GetLanguages(request);

            return View(response.Languages);
        }
Ejemplo n.º 2
0
        public GetLanguagesResponse GetLanguages(GetLanguagesRequest request)
        {
            if (!Uow.Languages.Get(c => c.Id.Equals(request.CultureId)).Any())
                throw new CultureNotFoundException("Request culture not supported");

            var result = Uow.Languages.Get(null, null, icl => icl.Localizations, icl => icl.Cultures);

            var response = new GetLanguagesResponse
            {
                Languages = result.Select(d => new LanguageData
                {
                    Id = d.Id,
                    Iso2 = d.Iso2,
                    Iso3 = d.Iso3,
                    Name = d.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()
                }).OrderBy(c => c.Name)
                .Skip((request.Index - 1) * request.NumberOfResultsPerPage)
                .Take(request.NumberOfResultsPerPage).ToList(),
                CurrentPage = request.Index,
                TotalNumberOfPage = result.Count() / request.NumberOfResultsPerPage
            };

            return response;
        }