public ActionResult ChangeCodeInfo(ChangeCodeModel model) { var target = db.iRemocons.Where(p => p.IPAddress.Equals(model.IPAddress)).Single(); var targetcode = target.RegistrationCodes.Where(p=>p.RegistrationCode1 == model.Code).Single(); if (ModelState.IsValid) { if (!model.Check) { Common common = new Common(); string res; try { res = common.ConnectRemocon(model.IPAddress, "*au\r\n"); } catch { ModelState.AddModelError("", "iRemocon(" + model.IPAddress + ") に接続できませんでした"); return View(model); } if (!res.Equals("ok")) { ModelState.AddModelError("", "iRemocon(" + model.IPAddress + ") に接続できませんでした"); return View(model); } try { res = common.ConnectRemocon(model.IPAddress, "*ic;" + model.Code + "\r\n"); } catch { ModelState.AddModelError("", "iRemocon(" + model.IPAddress + ") に接続できませんでした"); return View(model); } if (!res.Equals("ic;ok")) { ModelState.AddModelError("", "iRemocon(" + model.IPAddress + ") からのエラー: " + res); return View(model); } } targetcode.Detail = model.Detail; db.SaveChanges(); return RedirectToAction("ShowCodes", "Home", new { id = target.ID }); } // ここで問題が発生した場合はフォームを再表示します return View(model); }
public ActionResult ChangeCodeInfo(string id, int code, string detail) { ChangeCodeModel CCModel = new ChangeCodeModel(); CCModel.IPAddress = id.Replace('_', '.'); CCModel.Code = code; CCModel.Detail = detail; CCModel.Check = true; return View(CCModel); }