public ActionResult RequestTranslation2(int langElementId) { String currentUserId = User.Identity.GetUserId(); ApplicationUser currentUser = db.Users.Where(u => u.Id == currentUserId).FirstOrDefault(); LangElement element = db.LangElements.Where(l => l.LangId == currentUser.TargetLangId && l.ID == langElementId).FirstOrDefault(); GlosbeDictionaryService service = new GlosbeDictionaryService(); GlosbeResponse response = service.getTranslation(currentUser, element); if (response != null) { foreach (var t in response.tuc) { if (t.phrase != null) { if (t.phrase.text != null) { LangElementTranslation newElement = new LangElementTranslation() { LangId = currentUser.LangId, LangElementId = element.ID, Translation = t.phrase.text }; db.LangElementTranslations.Add(newElement); } } } db.SaveChanges(); } return(RedirectToAction("Index", new { langElementId = element.ID })); }
public ActionResult DeleteConfirmed(int id) { LangElementTranslation langelementtranslation = db.LangElementTranslations.Find(id); db.LangElementTranslations.Remove(langelementtranslation); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult RequestTranslation(int langElementId) { String currentUserId = User.Identity.GetUserId(); ApplicationUser currentUser = db.Users.Where(u => u.Id == currentUserId).FirstOrDefault(); LangElement element = db.LangElements.Where(l => l.LangId == currentUser.TargetLangId && l.ID == langElementId).FirstOrDefault(); PonsDictionaryService service = new PonsDictionaryService(); List <PonsResponse> responses = service.getTranslation(currentUser, element); if (responses != null) { RawTranslationResponse rawResponse = new RawTranslationResponse() { LangElementId = element.ID, LangId = currentUser.LangId, Provider = "pons" }; rawResponse.Response = JsonConvert.SerializeObject(responses); db.RawTranslationReponses.Add(rawResponse); foreach (var item in responses) { foreach (var hit in item.Hits) { if (hit.Type == "entry") { foreach (var rom in hit.Roms) { foreach (var arab in rom.Arabs) { foreach (var trans in arab.Translations) { LangElementTranslation newElement = new LangElementTranslation() { LangId = currentUser.LangId, LangElementId = element.ID, Translation = trans.Source + "; " + trans.Target }; db.LangElementTranslations.Add(newElement); } } } } else if (hit.Type == "translation") { LangElementTranslation newElement = new LangElementTranslation() { LangId = currentUser.LangId, LangElementId = element.ID, Translation = hit.Source + "; " + hit.Target }; db.LangElementTranslations.Add(newElement); } } } db.SaveChanges(); } return(RedirectToAction("Index", new { langElementId = element.ID })); }
public ActionResult Edit([Bind(Include = "Id,LangElementId,LangId,Translation")] LangElementTranslation langelementtranslation) { if (ModelState.IsValid) { db.Entry(langelementtranslation).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.LangId = new SelectList(db.Langs, "ID", "Code", langelementtranslation.LangId); ViewBag.LangElementId = new SelectList(db.LangElements, "ID", "Value", langelementtranslation.LangElementId); return(View(langelementtranslation)); }
// GET: /LangElementTranslation/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } LangElementTranslation langelementtranslation = db.LangElementTranslations.Find(id); if (langelementtranslation == null) { return(HttpNotFound()); } return(View(langelementtranslation)); }
// GET: /LangElementTranslation/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } LangElementTranslation langelementtranslation = db.LangElementTranslations.Find(id); if (langelementtranslation == null) { return(HttpNotFound()); } ViewBag.LangId = new SelectList(db.Langs, "ID", "Code", langelementtranslation.LangId); ViewBag.LangElementId = new SelectList(db.LangElements, "ID", "Value", langelementtranslation.LangElementId); return(View(langelementtranslation)); }
public ActionResult Create([Bind(Include = "Id,LangElementId,LangId,Translation")] LangElementTranslation langelementtranslation) { if (ModelState.IsValid) { db.LangElementTranslations.Add(langelementtranslation); db.SaveChanges(); if (Request.UrlReferrer.PathAndQuery != null) { return(Redirect(Request.UrlReferrer.PathAndQuery)); } return(RedirectToAction("Index")); } ViewBag.LangId = new SelectList(db.Langs, "ID", "Code", langelementtranslation.LangId); ViewBag.LangElementId = new SelectList(db.LangElements, "ID", "Value", langelementtranslation.LangElementId); return(View(langelementtranslation)); }