/// <summary> /// 新增医院 /// </summary> /// <param name="model">医院信息</param> /// <returns>是否成功</returns> public async Task<OutputBase> Add(AdminHospitalDto model) { if (await _repository.GetHospitalByName(model.HospitalName) != null) return OutputBase.Fail("同名医院已存在"); var entity = new Hospital { CityId = model.CityId, HospitalName = model.HospitalName }; _repository.Add(entity); return _unitWork.Commit() ? OutputBase.Success("新增成功") : OutputBase.Fail("新增失败"); }
/// <summary> /// 更新医院 /// </summary> /// <param name="model">医院信息</param> /// <returns>是否成功</returns> public async Task<OutputBase> Update(AdminHospitalDto model) { var hospital = await _repository.GetHospitalById(model.Id); if (hospital == null) return OutputBase.Fail("该医院不存在"); if (model.HospitalName != hospital.HospitalName && await _repository.GetHospitalByName(model.HospitalName) != null) return OutputBase.Fail("同名医院已存在"); var entity = new Hospital { Id = model.Id, CityId = model.CityId, HospitalName = model.HospitalName }; await _repository.Update(entity); return _unitWork.Commit() ? OutputBase.Success("更新成功") : OutputBase.Fail("更新失败"); }
public async Task <IActionResult> Edit(AdminHospitalDto model) { if (!ModelState.IsValid) { await ShowProvinceList(false); await ShowCityList(false, model.ProvinceId); return(PartialView("_EditPartial", model)); } //主键初始Id大于0表示是编辑,反之则是新增 if (model.Id > 0) { var result = await _service.Update(model); return(Json(result)); } else { var result = await _service.Add(model); return(Json(result)); } }