public async Task <IActionResult> Put(long id, string culture, [FromBody] PageTranslationForm model) { if (ModelState.IsValid) { var page = await _pageRepository.Query().FirstOrDefaultAsync(x => x.Id == id); if (page == null) { return(NotFound()); } var entityType = page.GetType().Name; var localizeProperties = _localizedContentPropertyRepository.Query().Where(x => x.EntityId == page.Id && x.EntityType == entityType && x.CultureId == culture); var localizedName = CreateOrUpdateTranslation(localizeProperties, page, nameof(page.Name), culture); localizedName.Value = model.Name; var localizedDescription = CreateOrUpdateTranslation(localizeProperties, page, nameof(page.Body), culture); localizedDescription.Value = model.Body; await _localizedContentPropertyRepository.SaveChangesAsync(); return(Accepted()); } return(BadRequest(ModelState)); }
public async Task <IActionResult> Get(long id, string culture) { var page = await _pageRepository.Query().FirstOrDefaultAsync(x => x.Id == id); if (page == null) { return(NotFound()); } var entityType = page.GetType().Name; var localizeProperties = _localizedContentPropertyRepository.Query().Where(x => x.EntityId == page.Id && x.EntityType == entityType && x.CultureId == culture); var model = new PageTranslationForm { DefaultCultureName = page.Name, Name = localizeProperties.FirstOrDefault(x => x.ProperyName == nameof(page.Name))?.Value, Body = localizeProperties.FirstOrDefault(x => x.ProperyName == nameof(page.Body))?.Value, }; return(Ok(model)); }