public async Task<ActionResult> AuxAdd(ProcessTranslation t) { var cl = db.Entities .FirstOrDefault(c => c.Translations.Any(ct => ct.LanguageCode == t.LanguageCode && ct.Value == t.Value && ct.ProcessId != t.ProcessId) ); if (cl == null) { cl = new Process(); cl.Translations.Add(t); db.Add(cl); await db.SaveChangesAsync(); } return Json((await db.Entities .OrderBy(ct => ct.Id) .ToListAsync()) .Select(ct => new TranslatedViewModel<Process, ProcessTranslation>(ct)) .Select(ct => new { value = ct.Entity.Id.ToString(), text = ct.Translation.Value, selected = ct.Entity.Id == cl.Id }) .ToList()); }
public async Task<ActionResult> Create(ProcessTranslation pt) { if (DoesProcessExist(pt)) { ModelState.AddModelError("Value", ProcessStrings.Validation_AlreadyExists); } if (ModelState.IsValid) { var process = new Process(); process.Translations.Add(pt); db.Add(process); await db.SaveChangesAsync(); return RedirectToAction("Index"); } return View(pt); }
public async Task<ActionResult> Edit(Process process) { for (var i = 0; i < process.Translations.Count; i++) { var pt = process.Translations[i]; if (DoesProcessExist(pt)) { ModelState.AddModelError("Translations[" + i + "].Value", ProcessStrings.Validation_AlreadyExists); } } if (ModelState.IsValid) { foreach (var translation in process.Translations) { db.UpdateTranslation(translation); } await db.SaveChangesAsync(); return RedirectToAction("Index"); } return View(process); }