public IActionResult CountryDetail(int?id) { var model = new CountryDetailModel(); model.Country = new Country(); if (id.HasValue && id.Value > 0) { model.Country = DefaultStorage.CountryGet(id.Value); } return(View(model)); }
public async Task <IActionResult> CountryDetail(int?i, Country model) { var now = DateTime.Now; var result = new Result(); if (!i.HasValue) { if (model.Id.IsNullOrEmpty()) { result.Error("请输入三位数字代码"); return(Json(result)); } } if (model.Code.IsNullOrEmpty()) { result.Error("请输入三位字母代码"); return(Json(result)); } if (model.Name.IsNullOrEmpty()) { result.Error("请输入中文名称"); return(Json(result)); } if (model.EnName.IsNullOrEmpty()) { result.Error("请输入英文名称"); return(Json(result)); } if (i.HasValue && i.Value > 0) { var old = DefaultStorage.CountryGet(i.Value); if (old == null) { result.Message = "数据不存在"; return(Json(result)); } var status = await TryUpdateModelAsync(old); if (status) { result.Status = DefaultStorage.CountryUpdate(old); if (!result.Status) { result.Message = "更新失败"; } } else { result.Message = "参数有误"; } return(Json(result)); } model.Id = i.ToString(); model.Extra = string.Empty; model.CreatedOn = now; model.ModifiedBy = string.Empty; model.ModifiedOn = now; result.Status = DefaultStorage.CountryCreate(model); if (result.Status) { result.Success(); } return(Json(result)); }