public ActionResult doIndex() { SiteConfigModel[] siteConfigModel = new SiteConfigModel[4]; siteConfigModel[0] = new SiteConfigModel("sitename", Request.Form["sitename"], "sitename"); siteConfigModel[1] = new SiteConfigModel("smtpaddress", Request.Form["smtpaddress"], "smtpaddress"); siteConfigModel[2] = new SiteConfigModel("smtpusername", Request.Form["smtpusername"], "smtpusername"); siteConfigModel[3] = new SiteConfigModel("smtppassword", Request.Form["smtppassword"], "smtppassword"); //站点名称不能为空,其它皆可为空 if (siteConfigModel[0].PropertyValue == "") { TempData["errorMsg"] = "站点名称不能为空!"; return RedirectToAction("Index", "Index"); } BLLSiteConfig bllSiteConfig = new BLLSiteConfig(); Boolean result = true; for (int i = 0; i < 4; i++ ) { if (!bllSiteConfig.saveSiteConfig(siteConfigModel[i])) { result = false; } } if (result == true) { TempData["successMsg"] = "保存成功!"; return RedirectToAction("Index", "Index"); } else { TempData["errorMsg"] = "保存失败,请重试。"; return RedirectToAction("Index", "Index"); } }
public Boolean saveSiteConfig(SiteConfigModel siteConfigModel) { SiteConfigModel siteConfigModelFromDb = siteConfigDAL.getConfigByPropertyName(siteConfigModel.PropertyName); if (siteConfigModelFromDb.PropertyValue == "") { return siteConfigDAL.addConfig(siteConfigModel); } else if ( siteConfigModelFromDb.PropertyValue != siteConfigModel.PropertyValue) { return siteConfigDAL.updateConfig(siteConfigModel); } else { return true; } }