public NoteComment AddNoteComment(NoteComment noteComment) { NoteCommentEntity entity = noteComment.ToEntity(); noteComment.CreateTime = DateTime.Now; noteComment.DeletedTime = DateTime.Now; noteComment.IsDeleted = false; this.dbContext.NoteComments.Add(entity); this.dbContext.SaveChanges(); return(entity.ToModel()); }
public List <NoteComment> GetNoteCommentsByNoteId(int id) { try { if (id <= 0) { return(null); } DbParameter[] parameters = new DbParameter[] { new SqlParameter() { ParameterName = SpParamsOfNoteComment.Sp_Select_NoteCommentByNoteId_NoteId, Value = id } }; using (DataSet dataSet = DbHelper.Instance.RunProcedureGetDataSet(SpNamesOfNoteComment.Sp_Select_NoteCommentByNoteId, parameters)) { NoteCommentEntity entity = null; List <NoteComment> noteComments = new List <NoteComment>(); if (dataSet != null && dataSet.Tables != null && dataSet.Tables.Count != 0 && dataSet.Tables[0].Rows != null && dataSet.Tables[0].Rows.Count != 0) { DataRowCollection dataRows = dataSet.Tables[0].Rows; DataColumnCollection dataColumns = dataSet.Tables[0].Columns; foreach (DataRow dataRow in dataRows) { entity = new NoteCommentEntity() { Id = (int)dataRow[dataColumns[0]], NoteId = (int)dataRow[dataColumns[1]], CreatorId = (int)dataRow[dataColumns[2]], CommentId = (int)dataRow[dataColumns[3]], CreateTime = (DateTime)dataRow[dataColumns[4]], IsDeleted = (bool)dataRow[dataColumns[5]], DeletedTime = (DateTime)dataRow[dataColumns[6]] }; noteComments.Add(entity.ToModel()); } } return(noteComments); } } catch (Exception ex) { throw ex; } }
public static NoteComment ToModel(this NoteCommentEntity entity) { return(new NoteComment() { Id = entity.Id, NoteId = entity.NoteId, CreatorId = entity.CreatorId, CommentId = entity.CommentId, CreateTime = entity.CreateTime, IsDeleted = entity.IsDeleted, DeletedTime = entity.DeletedTime }); }
public NoteComment GetNoteCommentById(int id) { NoteCommentEntity entity = this.dbContext.NoteComments.FirstOrDefault(nc => nc.Id == id); return(entity == null ? null : entity.ToModel()); }
public NoteComment AddNoteComment(NoteComment noteComment) { try { if (noteComment == null) { return(null); } DbParameter[] parameters = new DbParameter[] { new SqlParameter() { ParameterName = SpParamsOfNoteComment.Sp_Insert_NoteComment_NoteId, Value = noteComment.NoteId }, new SqlParameter() { ParameterName = SpParamsOfNoteComment.Sp_Insert_NoteComment_CreatorId, Value = noteComment.CreatorId }, new SqlParameter() { ParameterName = SpParamsOfNoteComment.Sp_Insert_NoteComment_CommentId, Value = noteComment.CommentId } }; using (DataSet dataSet = DbHelper.Instance.RunProcedureGetDataSet(SpNamesOfNoteComment.Sp_Insert_NoteComment, parameters)) { NoteCommentEntity entity = null; if (dataSet != null && dataSet.Tables != null && dataSet.Tables.Count != 0 && dataSet.Tables[0].Rows != null && dataSet.Tables[0].Rows.Count != 0) { DataRow dataRow = dataSet.Tables[0].Rows[0]; DataColumnCollection dataColumns = dataSet.Tables[0].Columns; entity = new NoteCommentEntity() { Id = (int)dataRow[dataColumns[0]], NoteId = (int)dataRow[dataColumns[1]], CreatorId = (int)dataRow[dataColumns[2]], CommentId = (int)dataRow[dataColumns[3]], CreateTime = (DateTime)dataRow[dataColumns[4]], IsDeleted = (bool)dataRow[dataColumns[5]], DeletedTime = (DateTime)dataRow[dataColumns[6]] }; } if (entity == null) { return(null); } return(entity.ToModel()); } } catch (Exception ex) { throw ex; } }