public HttpResponseMessage GetModel(int contentTypeId)
        {
            var page        = new Page();
            var contentType = Services.ContentTypeService.Get(contentTypeId);
            var properties  = contentType.CompositionPropertyTypes;

            page.Variants = new List <Variant>();
            page.AllowVaryingByCulture = contentType.Variations.Equals(ContentVariation.Culture);

            List <ILanguage> languages;

            if (page.AllowVaryingByCulture)
            {
                languages = Services.LocalizationService.GetAllLanguages().ToList();
            }
            else
            {
                languages = Services.LocalizationService.GetAllLanguages().Where(lang => lang.IsDefault).ToList();
            }

            foreach (var lang in languages)
            {
                var language = new Models.Language()
                {
                    CultureName = lang.CultureName,
                    IsDefault   = lang.IsDefault,
                    CultureInfo = lang.CultureInfo.ToString()
                };

                var variant = new Variant()
                {
                    Language      = language,
                    PropertyTypes = new List <Models.PropertyType>()
                };

                foreach (var prop in properties)
                {
                    var propAllowVaryingByCulture = prop.Variations.Equals(ContentVariation.Culture);

                    if (!lang.IsDefault && !propAllowVaryingByCulture)
                    {
                    }
                    else
                    {
                        var propType = new Models.PropertyType();
                        propType.Alias = prop.Alias;
                        propType.Name  = prop.Name;
                        propType.AllowVaryingByCulture = propAllowVaryingByCulture;
                        variant.PropertyTypes.Add(propType);
                    }
                }

                page.Variants.Add(variant);
            }

            return(Request.CreateResponse(HttpStatusCode.OK, page));
        }
 public static string GetDisplayName(this Models.Language language)
 {
     if (languageDisplayNameMap.ContainsKey(language))
     {
         return(languageDisplayNameMap[language]);
     }
     else
     {
         return(language.ToString());
     }
 }
Exemple #3
0
        public async Task <IActionResult> OnGetAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Language = await _context.Language.FirstOrDefaultAsync(m => m.LangId == id);

            if (Language == null)
            {
                return(NotFound());
            }
            return(Page());
        }
Exemple #4
0
        public SelectList GetAllLanguages()
        {
            List <Language> Languages = _db.Languages.ToList();

            Language SelectNone = new Models.Language()
            {
                LanguageID = 0, Name = "All Languages"
            };

            Languages.Add(SelectNone);

            SelectList AllLanguages = new SelectList(Languages.OrderBy(l => l.LanguageID), "LanguageID", "Name");

            return(AllLanguages);
        }
Exemple #5
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Language = await _context.Language.FindAsync(id);

            if (Language != null)
            {
                _context.Language.Remove(Language);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
Exemple #6
0
        /// <summary>
        /// Executes the specified request.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns>Updated language view model</returns>
        public LanguageViewModel Execute(LanguageViewModel request)
        {
            var isNew = request.Id.HasDefaultValue();

            Models.Language language;

            // Validate
            ValidateLanguage(request, isNew);

            if (isNew)
            {
                language      = new Models.Language();
                language.Code = request.Code;
            }
            else
            {
                language = Repository.AsQueryable <Models.Language>(w => w.Id == request.Id).FirstOne();
            }

            language.Name    = request.Name;
            language.Version = request.Version;

            Repository.Save(language);
            UnitOfWork.Commit();

            if (isNew)
            {
                Events.RootEvents.Instance.OnLanguageCreated(language);
            }
            else
            {
                Events.RootEvents.Instance.OnLanguageUpdated(language);
            }

            return(new LanguageViewModel
            {
                Id = language.Id,
                Version = language.Version,
                Name = language.Name,
                Code = CultureInfo.GetCultures(CultureTypes.AllCultures).First(c => c.Name == language.Code).GetFullName(),
            });
        }
Exemple #7
0
        public ActionResult LanguageCreateot(FormCollection collection, Models.Language catego)
        {
            if (Request.Cookies["Username"] != null)
            {
                // Lấy dữ liệu từ view
                catego.Name = collection["Name"];
                catego.Code = collection["Code"];

                catego.Images = collection["Images"];
                catego.Active = (collection["Action"] == "false") ? false : true;

                db.Entry(catego).State = EntityState.Added;
                db.SaveChanges();
                return(RedirectToAction("LanguageIndexot"));
            }
            else
            {
                return(Redirect("/Admins/admins"));
            }
        }
Exemple #8
0
        public void Create(LanguageDto input)
        {
            Models.Language language = input.MapTo <Models.Language>();

            _languageRepository.Insert(language);
        }