public virtual async Task <MIS_Article_CommentModel> GetByIdAsync(object id) { if (IsExists(id)) { MIS_Article_Comment entity = await m_Rep.GetByIdAsync(id); MIS_Article_CommentModel model = new MIS_Article_CommentModel(); model.Id = entity.Id; model.ArticleId = entity.ArticleId; model.UserId = entity.UserId; model.TrueName = entity.TrueName; model.IP = entity.IP; model.BodyContent = entity.BodyContent; model.CreateTime = entity.CreateTime; model.IsReply = entity.IsReply; model.ReplyContent = entity.ReplyContent; model.ReplyTime = entity.ReplyTime; return(model); } else { return(null); } }
public virtual async Task <Tuple <ValidationErrors, bool> > CreateAsync(MIS_Article_CommentModel model) { ValidationErrors errors = new ValidationErrors(); try { MIS_Article_Comment entity = await m_Rep.GetByIdAsync(model.Id); if (entity != null) { errors.Add(Resource.PrimaryRepeat); return(new Tuple <ValidationErrors, bool>(errors, false)); } entity = new MIS_Article_Comment(); entity.Id = model.Id; entity.ArticleId = model.ArticleId; entity.UserId = model.UserId; entity.TrueName = model.TrueName; entity.IP = model.IP; entity.BodyContent = model.BodyContent; entity.CreateTime = model.CreateTime; entity.IsReply = model.IsReply; entity.ReplyContent = model.ReplyContent; entity.ReplyTime = model.ReplyTime; if (await m_Rep.CreateAsync(entity)) { return(new Tuple <ValidationErrors, bool>(errors, true)); } else { errors.Add(Resource.InsertFail); return(new Tuple <ValidationErrors, bool>(errors, false)); } } catch (Exception ex) { errors.Add(ex.Message); ExceptionHander.WriteException(ex); return(new Tuple <ValidationErrors, bool>(errors, false)); } }
public virtual bool Create(ref ValidationErrors errors, MIS_Article_CommentModel model) { try { MIS_Article_Comment entity = m_Rep.GetById(model.Id); if (entity != null) { errors.Add(Resource.PrimaryRepeat); return(false); } entity = new MIS_Article_Comment(); entity.Id = model.Id; entity.ArticleId = model.ArticleId; entity.UserId = model.UserId; entity.TrueName = model.TrueName; entity.IP = model.IP; entity.BodyContent = model.BodyContent; entity.CreateTime = model.CreateTime; entity.IsReply = model.IsReply; entity.ReplyContent = model.ReplyContent; entity.ReplyTime = model.ReplyTime; if (m_Rep.Create(entity)) { return(true); } else { errors.Add(Resource.InsertFail); return(false); } } catch (Exception ex) { errors.Add(ex.Message); ExceptionHander.WriteException(ex); return(false); } }
public virtual bool Edit(ref ValidationErrors errors, MIS_Article_CommentModel model) { try { MIS_Article_Comment entity = m_Rep.GetById(model.Id); if (entity == null) { errors.Add(Resource.Disable); return(false); } entity.Id = model.Id; entity.ArticleId = model.ArticleId; entity.UserId = model.UserId; entity.TrueName = model.TrueName; entity.IP = model.IP; entity.BodyContent = model.BodyContent; entity.CreateTime = model.CreateTime; entity.IsReply = model.IsReply; entity.ReplyContent = model.ReplyContent; entity.ReplyTime = model.ReplyTime; if (m_Rep.Edit(entity)) { return(true); } else { errors.Add(Resource.NoDataChange); return(false); } } catch (Exception ex) { errors.Add(ex.Message); ExceptionHander.WriteException(ex); return(false); } }
public virtual MIS_Article_CommentModel GetById(string id) { if (IsExists(id)) { MIS_Article_Comment entity = m_Rep.GetById(id); MIS_Article_CommentModel model = new MIS_Article_CommentModel(); model.Id = entity.Id; model.ArticleId = entity.ArticleId; model.UserId = entity.UserId; model.TrueName = entity.TrueName; model.IP = entity.IP; model.BodyContent = entity.BodyContent; model.CreateTime = entity.CreateTime; model.IsReply = entity.IsReply; model.ReplyContent = entity.ReplyContent; model.ReplyTime = entity.ReplyTime; return(model); } else { return(null); } }
/// <summary> /// 校验Excel数据,这个方法一般用于重写校验逻辑 /// </summary> public virtual bool CheckImportData(string fileName, List <MIS_Article_CommentModel> list, ref ValidationErrors errors) { var targetFile = new FileInfo(fileName); if (!targetFile.Exists) { errors.Add("导入的数据文件不存在"); return(false); } var excelFile = new ExcelQueryFactory(fileName); //对应列头 excelFile.AddMapping <MIS_Article_CommentModel>(x => x.ArticleId, "所属文章"); excelFile.AddMapping <MIS_Article_CommentModel>(x => x.UserId, "发布者"); excelFile.AddMapping <MIS_Article_CommentModel>(x => x.TrueName, "姓名"); excelFile.AddMapping <MIS_Article_CommentModel>(x => x.IP, "IP"); excelFile.AddMapping <MIS_Article_CommentModel>(x => x.BodyContent, "内容"); excelFile.AddMapping <MIS_Article_CommentModel>(x => x.CreateTime, "创建时间"); excelFile.AddMapping <MIS_Article_CommentModel>(x => x.IsReply, "是否回复"); excelFile.AddMapping <MIS_Article_CommentModel>(x => x.ReplyContent, "回复内容"); excelFile.AddMapping <MIS_Article_CommentModel>(x => x.ReplyTime, "回复时间"); //SheetName var excelContent = excelFile.Worksheet <MIS_Article_CommentModel>(0); int rowIndex = 1; //检查数据正确性 foreach (var row in excelContent) { var errorMessage = new StringBuilder(); var entity = new MIS_Article_CommentModel(); entity.Id = row.Id; entity.ArticleId = row.ArticleId; entity.UserId = row.UserId; entity.TrueName = row.TrueName; entity.IP = row.IP; entity.BodyContent = row.BodyContent; entity.CreateTime = row.CreateTime; entity.IsReply = row.IsReply; entity.ReplyContent = row.ReplyContent; entity.ReplyTime = row.ReplyTime; //============================================================================= if (errorMessage.Length > 0) { errors.Add(string.Format( "第 {0} 列发现错误:{1}{2}", rowIndex, errorMessage, "<br/>")); } list.Add(entity); rowIndex += 1; } if (errors.Count > 0) { return(false); } return(true); }