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 NoteComment GetNoteCommentById(int id) { NoteCommentEntity entity = this.dbContext.NoteComments.FirstOrDefault(nc => nc.Id == id); return(entity == null ? null : entity.ToModel()); }