public async Task<ActionResult> AddTranslation(DocumentTranslation translation) { if (ModelState.IsValid) { db.AddTranslation(translation); await db.SaveChangesAsync(); return RedirectToAction("Index"); } return View(translation); }
public async Task<ActionResult> AddTranslation(int? id) { if (id == null) { return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } var doc = await db.GetByIdAsync(id); if (doc == null) { return HttpNotFound(); } var translations = doc.Translations .Select(dt => dt.LanguageCode) .ToList(); if (translations.Count() == LanguageDefinitions.Languages.Count) { return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } var model = new DocumentTranslation { DocumentId = doc.Id }; ViewBag.Languages = LanguageDefinitions.GenerateAvailableLanguageDDL(doc.Translations.Select(t => t.LanguageCode).ToList()); return View(model); }