public ActionResult Register(userCheck model) { if (model.UserDishes != null) { using (var dbTran = db.Database.BeginTransaction()) { try { int IdCheck = Convert.ToInt32(db.PR_NewCheck(model.CheckLocal.IdLocal).ToArray()[0]); var lista = model.UserDishes.Split(',').ToList(); foreach (var dishTmp in lista) { if (dishTmp != "") { db.PR_CreateDetailCheck(Convert.ToInt32(dishTmp), IdCheck); } } var identity = (System.Web.HttpContext.Current.User as MyIdentity.MyPrincipal).Identity as MyIdentity; db.PR_CreatePaymentCheck(identity.User.IdCard, IdCheck); db.SaveChanges(); dbTran.Commit(); return(RedirectToAction("Index", "Checks")); } catch (Exception ex) { dbTran.Rollback(); } } } return(RedirectToAction("Create", "Checks", model)); }