public async Task <ActionResult> Create(Status status, string nameVI, string nameEN, string NameTW) { try { status.Name = nameVI + " - " + nameEN + " - " + NameTW;; db.Status.Add(status); await db.SaveChangesAsync(); StatusLang vn = new StatusLang(); vn.Name = nameVI; vn.LanguageID = "vi"; vn.StatusID = status.StatusID; db.StatusLangs.Add(vn); StatusLang en = new StatusLang(); en.Name = nameEN; en.LanguageID = "en"; en.StatusID = status.StatusID; db.StatusLangs.Add(en); StatusLang tw = new StatusLang(); tw.Name = NameTW; tw.LanguageID = "en"; tw.StatusID = status.StatusID; db.StatusLangs.Add(tw); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } catch (Exception) { return(View(status)); } }
public async Task <ActionResult> Edit(Status status, string nameVI, string nameEN, string nameTW) { try { var id = status.StatusID; var itemOri = await db.Status.FindAsync(id); var itemVi = await db.StatusLangs.FirstOrDefaultAsync(x => x.StatusID == id && x.LanguageID == "vi"); var itemEn = await db.StatusLangs.FirstOrDefaultAsync(x => x.StatusID == id && x.LanguageID == "en"); var itemTw = await db.StatusLangs.FirstOrDefaultAsync(x => x.StatusID == id && x.LanguageID == "tw"); await db.SaveChangesAsync(); if (itemVi == null) { StatusLang vn = new StatusLang(); vn.Name = nameVI; vn.LanguageID = "vi"; vn.StatusID = status.StatusID; db.StatusLangs.Add(vn); } else { itemVi.Name = nameVI; } if (itemTw == null) { StatusLang tw = new StatusLang(); tw.Name = nameTW; tw.LanguageID = "tw"; tw.StatusID = status.StatusID; db.StatusLangs.Add(tw); } else { itemTw.Name = nameTW; } if (itemEn == null) { StatusLang en = new StatusLang(); en.Name = nameEN; en.LanguageID = "en"; en.StatusID = status.StatusID; db.StatusLangs.Add(en); } else { itemEn.Name = nameEN; } itemOri.Name = nameVI + " - " + nameEN + " - " + nameTW; await db.SaveChangesAsync(); return(RedirectToAction("Index")); } catch (Exception) { return(View(status)); } }