public async Task <ActionResult> Edit(long id = 0) { var model = new PartnerModel(); if (id == 0) { return(PartialView(model)); } var partner = await PartnerRepository.GetEnableByIdAsync(id); if (partner == null) { var json = new JsonModel { message = "记录不存在了", statusCode = 300 }; return(Json(json, JsonRequestBehavior.AllowGet)); } Mapper.Map(partner, model); return(PartialView(model)); }
public async Task <ActionResult> Edit(PartnerModel model) { var result = new JsonModel(); if (!ModelState.IsValid) { result.GetError(ModelState); return(Json(result)); } Partner partner = null; var operationType = OperationType.Update; if (model.Id > 0) { operationType = OperationType.Update; partner = await PartnerRepository.GetEnableByIdAsync(model.Id); if (partner == null) { result.statusCode = 300; result.message = "该条数据不存在,请刷新重试!"; return(Json(result)); } } else { partner = new Partner(); } Mapper.Map(model, partner); partner.CommonStatus = CommonStatus.Enabled; await PartnerRepository.SaveAsync(partner); await LogRepository.Insert(TableSource.Partner, operationType, "", partner.Id); result.Data = partner; result.message = "保存成功!"; return(Json(result)); }