public ActionResult Edit(EnvironmentParameters aEnvParam) { var szError = string.Empty; if (!this.ModelState.IsValid) { return(this.RedirectToAction("Development")); } try { string szWarning = null; PaymentController.DecodeInfo02(aEnvParam.Password, ref szWarning); if (!string.IsNullOrEmpty(szWarning)) { var encryptedPasswd = PaymentController.EncriptInfo02(aEnvParam.Password, ref szError); aEnvParam.Password = encryptedPasswd; } this.db.Entry(aEnvParam).State = EntityState.Modified; this.db.SaveChanges(); if (aEnvParam.Active) { var otherEnvParam = this.db.EnvironmentParameters.SingleOrDefault(x => x.ParameterId != aEnvParam.ParameterId); if (otherEnvParam != null) { otherEnvParam.Active = false; this.db.Entry(otherEnvParam).State = EntityState.Modified; this.db.SaveChanges(); } } } catch (Exception e) { this.ModelState.AddModelError(string.Empty, e.Message); return(this.View(aEnvParam)); } if (string.IsNullOrEmpty(szError)) { return(RedirectToAction("Development")); } this.ModelState.AddModelError(string.Empty, szError); return(this.View(aEnvParam)); }