/// <summary> /// 从数据库删除数据 (逻辑删除) /// </summary> /// <param name="meetInfo"></param> /// <param name="workUser"></param> private bool DoDataInfoDeletion(HcpDataInfo data, WorkUser workUser) { using (var tran = _rep.Database.BeginTransaction()) { try { data.IsDeleted = 1; data.UpdateTime = DateTime.Now; data.UpdateUser = workUser.User.Id; if (!string.IsNullOrEmpty(data.OldId)) { data.IsCompleted = EnumComplete.CanceledUpdate; //修改后的副本变为取消修改状态 //是否存在需要审核的其它记录 bool hasApprovingCopy = _rep.Table <HcpDataInfo>().Any(s => s.IsDeleted != 1 && s.Id != data.Id && s.OldId == data.OldId); if (!hasApprovingCopy) { //解锁原始数据 var originalDataInfo = _rep.FirstOrDefault <HcpDataInfo>(s => s.IsDeleted != 1 && s.Id == data.OldId && s.IsCompleted == EnumComplete.Locked); if (originalDataInfo != null) { originalDataInfo.IsCompleted = EnumComplete.Approved; _rep.Update(originalDataInfo); } } } _rep.Update(data); var mediaRelList = _rep.Where <HcpMediaDataRel>(s => s.DataInfoId == data.Id); foreach (var media in mediaRelList) { media.IsDeleted = 1; _rep.Update(media); } _rep.SaveChanges(); tran.Commit(); return(true); } catch (Exception ex) { tran.Rollback(); return(false); } } }
/// <summary> /// 删除资料 /// </summary> /// <param name="dataInfo"></param> /// <param name="workUser"></param> /// <returns></returns> public ReturnValueModel DeleteHcpDataInfo(HcpDataInfo dataInfo, WorkUser workUser) { ReturnValueModel rvm = new ReturnValueModel(); var data = _rep.FirstOrDefault <HcpDataInfo>(s => s.Id == dataInfo.Id); if (data == null) { rvm.Success = false; rvm.Msg = "Invalid Id"; return(rvm); } if (data.IsDeleted == 1) { rvm.Msg = "This DataInfo has been deleted."; rvm.Success = true; return(rvm); } var approvalEnabled = _systemService.AdminApprovalEnabled; //是否启用审核 if (approvalEnabled && (data.MediaType == 1 || data.MediaType == 3)) { switch (data.IsCompleted ?? EnumComplete.AddedUnapproved) { case EnumComplete.Locked: rvm.Success = false; return(rvm); case EnumComplete.Approved: data.IsCompleted = EnumComplete.WillDelete; //将要删除(等待审核) _rep.Update(data); _rep.SaveChanges(); //待审核发送邮件提醒 if (IsSendMail == "1") { MailUtil.SendMeetMail(workUser?.User.ChineseName ?? "", "资料", data.Title) .ContinueWith((previousTask) => { bool rCount = previousTask.Result; }); //MailUtil.SendMeetMail(workUser?.User.ChineseName ?? "", "资料", data.Title); } break; case EnumComplete.Reject: case EnumComplete.AddedUnapproved: case EnumComplete.UpdatedUnapproved: //删除数据 if (!DoDataInfoDeletion(data, workUser)) { rvm.Msg = "fail"; rvm.Success = false; return(rvm); } break; default: rvm.Msg = "This DataInfo can not be deleted at this time."; rvm.Success = false; return(rvm); } } else { //删除数据 if (!DoDataInfoDeletion(data, workUser)) { rvm.Msg = "fail"; rvm.Success = false; return(rvm); } } rvm.Msg = "success"; rvm.Success = true; return(rvm); }
public IHttpActionResult DeleteDataInfo(HcpDataInfo dataInfo) { var ret = _hcpDataInfoService.DeleteHcpDataInfo(dataInfo, WorkUser); return(Ok(ret)); }