/// <summary> /// Generates temporary model values in clone modal /// </summary> public ActionResult Clone(int id) { GHSPHSource PHSrc = new GHSPHSource(); string[] Suffix = new string[] {"A","B","C","D","E","F","G","H","I","J"}; using (var db = new EF.CMCSQL03Entities()) { var phsrc = (from t in db.tblGHSPHSource where t.PHsourceID == id select t).FirstOrDefault(); int i = 0; PHSrc.PHNumber = phsrc.PHNumber + "-" + Suffix[i]; var isExists = db.tblGHSPHSource.Any(r => r.PHNumber.Equals(PHSrc.PHNumber)); while (isExists) { ++i; PHSrc.PHNumber = phsrc.PHNumber + "-" + Suffix[i]; isExists = db.tblGHSPHSource.Any(r => r.PHNumber.Equals(PHSrc.PHNumber)); } PHSrc.PHSourceID = phsrc.PHsourceID; PHSrc.Language = phsrc.Language; PHSrc.PHStatement = phsrc.PHStatement; } return PartialView("CloneEdit", PHSrc); }
public ActionResult SaveClone(GHSPHSource obj) { using (var db = new EF.CMCSQL03Entities()) { var newrecord = new EF.tblGHSPHSource { PHNumber = obj.PHNumber, Language = obj.Language, PHStatement = obj.PHStatement, CreateDate = DateTime.Now, CreateUser = HttpContext.User.Identity.Name }; db.tblGHSPHSource.Add(newrecord); db.SaveChanges(); // Get new id to pass to AddPhDetail action var pd = (from t in db.tblGHSPHSource where t.PHNumber == obj.PHNumber select t).FirstOrDefault(); obj.PHSourceID = pd.PHsourceID; } return RedirectToAction("AddPHDetail", new { id = obj.PHSourceID }); }