public ActionResult DeleteConfirmed(int?contentId, int?localeId) { ContentTranslation contentTranslation = db.ContentTranslations.FirstOrDefault(c => c.ContentID == contentId && c.LocaleID == localeId); db.ContentTranslations.Remove(contentTranslation); db.SaveChanges(); return(RedirectToAction("Index")); }
protected ContentTranslationVersion CreateVersion(ContentTranslation contentTranslation, Publication publication = null, DateTime?creationDate = null) { creationDate = creationDate ?? DependencyResolver.Current.GetService <IDateTimeManager>().Now(); return(new ContentTranslationVersion(Id, creationDate.Value, publication, ContentType, contentTranslation.Culture, contentTranslation.Properties.Select(p => new ContentTranslationVersionProperty(p.ContentTypeProperty.GetOriginalContentTypeProperty(), p.SerializedValue)))); }
public ActionResult Edit([Bind(Include = "ContentID,LocaleID,ContentTitle,ContentCaptionText,ContentDesc,CreateDate")] ContentTranslation contentTranslation) { if (ModelState.IsValid) { db.Entry(contentTranslation).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.ContentID = new SelectList(db.Contents, "ContentID", "ContentName", contentTranslation.ContentID); ViewBag.LocaleID = new SelectList(db.Locales, "LocaleID", "LocaleDesc", contentTranslation.LocaleID); return(View(contentTranslation)); }
public ActionResult Create([Bind(Include = "ContentID,LocaleID,ContentTitle,ContentCaptionText,ContentDesc")] ContentTranslation contentTranslation) { contentTranslation.CreateDate = DateTime.Now; if (ModelState.IsValid) { db.ContentTranslations.Add(contentTranslation); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.ContentID = new SelectList(db.Contents, "ContentID", "ContentName", contentTranslation.ContentID); ViewBag.LocaleID = new SelectList(db.Locales, "LocaleID", "LocaleDesc", contentTranslation.LocaleID); return(View(contentTranslation)); }
// GET: ContentTranslations/Details/5 public ActionResult Details(int?contentId, int?localeId) { if (contentId == null || localeId == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ContentTranslation contentTranslation = db.ContentTranslations.FirstOrDefault(c => c.ContentID == contentId && c.LocaleID == localeId); if (contentTranslation == null) { return(HttpNotFound()); } return(View(contentTranslation)); }
public void CreateContentTranslation(AddContentTranslationData addContentTranslationData) { if (_repository.ContentTranslations.Any( t => t.Name == addContentTranslationData.ContentName && t.Source == addContentTranslationData.ContentSource && t.Language == addContentTranslationData.Language)) { throw new RegoException("Translation already exist"); } var validationResult = new AddContentTranslationValidator(_repository).Validate(addContentTranslationData); if (!validationResult.IsValid) { throw new RegoValidationException(validationResult); } var language = _repository.Cultures.SingleOrDefault( cc => cc.Code == addContentTranslationData.Language); if (language == null) { throw new RegoException("Language not found"); } var contentTranslation = new ContentTranslation { Id = Guid.NewGuid(), Name = addContentTranslationData.ContentName, Source = addContentTranslationData.ContentSource, Language = language.Code, Translation = addContentTranslationData.Translation, Status = TranslationStatus.Disabled, Created = DateTimeOffset.Now, CreatedBy = _actorInfoProvider.Actor.UserName }; using (var scope = CustomTransactionScope.GetTransactionScope()) { _repository.ContentTranslations.Add(contentTranslation); _eventBus.Publish(new ContentTranslationCreated(contentTranslation)); _repository.SaveChanges(); scope.Complete(); } }
// GET: ContentTranslations/Edit/5 public ActionResult Edit(int?contentId, int?localeId) { if (contentId == null || localeId == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ContentTranslation contentTranslation = db.ContentTranslations.FirstOrDefault(c => c.ContentID == contentId && c.LocaleID == localeId); if (contentTranslation == null) { return(HttpNotFound()); } ViewBag.ContentID = new SelectList(db.Contents, "ContentID", "ContentName", contentTranslation.ContentID); ViewBag.LocaleID = new SelectList(db.Locales, "LocaleID", "LocaleDesc", contentTranslation.LocaleID); return(View(contentTranslation)); }
private ContentTranslation Translate(CultureInfo culture, IEnumerable <ContentProperty> cultureVariantProperties) { if (Equals(culture, CultureInfo.InvariantCulture)) { throw new ArgumentException("Cannot create translation for invariant culture."); } if (HasTranslation(culture)) { throw new InvalidOperationException("The " + culture.EnglishName + " translation of this content already exists."); } var newTranslation = new ContentTranslation(this, culture, cultureVariantProperties); _translations.Add(culture, newTranslation); return(newTranslation); }
/// <summary> /// Sets the translation for the specified language. /// </summary> /// <param name="parentId">The parent id</param> /// <param name="languageId">The language id</param> /// <param name="model">The model</param> public void SetTranslation(Guid parentId, Guid languageId, object model) { if (model is Models.GenericContent content) { var translation = Translations.FirstOrDefault(t => t.LanguageId == languageId); if (translation == null) { translation = new ContentTranslation { ContentId = content.Id, LanguageId = languageId }; Translations.Add(translation); } translation.Title = content.Title; translation.Excerpt = content.Excerpt; translation.LastModified = DateTime.Now; } }
public bool TryGetTranslation(CultureInfo culture, out ContentTranslation contentTranslation) { return(_translations.TryGetValue(culture, out contentTranslation)); }