/// <summary> /// 这边父项目与子项目相互的插入 /// </summary> /// <param name="id"></param> /// <param name="type"></param> /// <returns></returns> public BaseResponse insertCheckRec(CheckRecCollection baseRequest) { BaseResponse returnCheckRecdtl = new BaseResponse(); returnCheckRecdtl.ResultCode = 0; Mapper.CreateMap <CheckRec, LTC_CHECKREC>(); var model = unitOfWork.GetRepository <LTC_CHECKREC>().dbSet.Where(x => x.RECORDID == baseRequest.CheckRec.RECORDID).FirstOrDefault(); if (model == null) { model = Mapper.Map <LTC_CHECKREC>(baseRequest.CheckRec); unitOfWork.GetRepository <LTC_CHECKREC>().Insert(model); returnCheckRecdtl.ResultCode = 1001; //添加成功 // 这边是保存的方法 unitOfWork.Save(); } else { Mapper.Map(baseRequest.CheckRec, model); unitOfWork.GetRepository <LTC_CHECKREC>().Update(model); } //这边先保存。这边保存的id if (baseRequest.CheckRecdtl != null && baseRequest.CheckRecdtl.Count > 0) { foreach (CheckRecdtl ckrt in baseRequest.CheckRecdtl) { Mapper.CreateMap <CheckRecdtl, LTC_CHECKRECDTL>(); var Ckmodel = unitOfWork.GetRepository <LTC_CHECKRECDTL>().dbSet.Where(x => x.ID == ckrt.ID).FirstOrDefault(); //这边进行辅助 if (Ckmodel == null) { Ckmodel = Mapper.Map <LTC_CHECKRECDTL>(ckrt); Ckmodel.RECORDID = model.RECORDID; unitOfWork.GetRepository <LTC_CHECKRECDTL>().Insert(Ckmodel); } else { Mapper.Map(ckrt, Ckmodel); unitOfWork.GetRepository <LTC_CHECKRECDTL>().Update(Ckmodel); } } } unitOfWork.Save(); return(returnCheckRecdtl); }
public IHttpActionResult Post(CheckRecCollection baseRequest) { var response = _INursingRecord.insertCheckRec(baseRequest); return(Ok(response)); }