Exemple #1
0
        public async Task <IActionResult> Put(long id, string culture, [FromBody] CategoryTranslationForm model)
        {
            if (ModelState.IsValid)
            {
                var category = await _categoryRepository.Query().FirstOrDefaultAsync(x => x.Id == id);

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

                var entityType = category.GetType().Name;

                var localizeProperties = _localizedContentPropertyRepository.Query().Where(x => x.EntityId == category.Id &&
                                                                                           x.EntityType == entityType && x.CultureId == culture);

                var localizedName = CreateOrUpdateTranslation(localizeProperties, category, nameof(category.Name), culture);
                localizedName.Value = model.Name;

                var localizedDescription = CreateOrUpdateTranslation(localizeProperties, category, nameof(category.Description), culture);
                localizedDescription.Value = model.Description;

                await _localizedContentPropertyRepository.SaveChangesAsync();

                return(Accepted());
            }

            return(BadRequest(ModelState));
        }
Exemple #2
0
        public async Task <IActionResult> Get(long id, string culture)
        {
            var category = await _categoryRepository.Query().FirstOrDefaultAsync(x => x.Id == id);

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

            var entityType = category.GetType().Name;

            var localizeProperties = _localizedContentPropertyRepository.Query().Where(x => x.EntityId == category.Id &&
                                                                                       x.EntityType == entityType && x.CultureId == culture);

            var model = new CategoryTranslationForm
            {
                DefaultCultureName = category.Name,
                Name        = localizeProperties.FirstOrDefault(x => x.ProperyName == nameof(category.Name))?.Value,
                Description = localizeProperties.FirstOrDefault(x => x.ProperyName == nameof(category.Description))?.Value,
            };

            return(Ok(model));
        }