/// <summary> /// 게시판의 상세 보기 페이지(Details, BoardView) /// </summary> public IActionResult Details(int id) { // 넘겨온 Id 값에 해당하는 레코드 하나 읽어서 Note 클래스에 바인딩 var note = _repository.GetNoteById(id); //[!] 인코딩 방식에 따른 데이터 출력: // 직접 문자열 비교해도 되지만, 학습목적으로 열거형으로 비교 ContentEncodingType encoding = (ContentEncodingType)Enum.Parse(typeof(ContentEncodingType), note.Encoding); string encodedContent = ""; switch (encoding) { // Text : 소스 그대로 표현 case ContentEncodingType.Text: encodedContent = Dul.HtmlUtility.EncodeWithTabAndSpace(note.Content); break; // Html : HTML 형식으로 출력 case ContentEncodingType.Html: encodedContent = note.Content; // 변환없음 break; // Mixed : 엔터처리만 case ContentEncodingType.Mixed: encodedContent = note.Content.Replace("\r\n", "<br />"); break; // Html : 기본 default: encodedContent = note.Content; // 변환없음 break; } ViewBag.Content = encodedContent; //[!] // 첨부된 파일 확인 if (note.FileName.Length > 1) { //[a] 파일 다운로드 링크: String.Format()으로 표현해 봄 ViewBag.FileName = String.Format("<a href='/DotNetNote/BoardDown?Id={0}'>" + "{1}{2} / 전송수: {3}</a>", note.Id, "<img src=\"/images/ext/ext_zip.gif\" border=\"0\">", note.FileName, note.DownCount); //[b] 이미지 미리보기: C# 6.0 String 보간법으로 표현해 봄 if (Dul.BoardLibrary.IsPhoto(note.FileName)) { ViewBag.ImageDown = $"<img src=\'/DotNetNote/ImageDown/{note.Id}\'><br />"; } } else { ViewBag.FileName = "(업로드된 파일이 없습니다.)"; } // 현재 글에 해당하는 댓글 리스트와 현재 글 번호를 담아서 전달 NoteCommentViewModel vm = new NoteCommentViewModel(); vm.NoteCommentList = _commentRepository.GetNoteComments(note.Id); vm.BoardId = note.Id; ViewBag.CommentListAndId = vm; return(View(note)); }
public void AddNoteComment(object noteCommentVm) { var noteComment = new NoteComment(); NoteCommentViewModel noteCommentDto = JsonConvert.DeserializeObject <NoteCommentViewModel>(noteCommentVm.ToString()); NotelyContext.Current.Services.NoteCommentService.Save(noteComment.Convert(noteCommentDto)); }
public IEnumerable <NoteCommentViewModel> GetAllNoteComments(string logType) { var commentVm = new NoteCommentViewModel(); if (string.IsNullOrEmpty(logType)) { return(NotelyContext.Current.Services.NoteCommentService.GetAll().Select(c => commentVm.Convert(c))); } else { return(NotelyContext.Current.Services.NoteCommentService.GetAll(logType).Select(c => commentVm.Convert(c))); } }
/// <summary> /// Converts a <see cref="NoteCommentViewModel"/> object to a <see cref="NoteComment"/> object /// </summary> /// <param name="comment"></param> /// <param name="commentVm"></param> /// <returns></returns> public static NoteComment Convert(this NoteComment comment, NoteCommentViewModel commentVm) { var result = new NoteComment() { Id = commentVm.Id, Datestamp = DateTime.Now, LogComment = commentVm.LogComment, LogType = commentVm.LogType, NoteId = commentVm.NoteId, UserId = commentVm.User.Id }; return(result); }
/// <summary> /// Converts a <see cref="NoteComment"/> object to a <see cref="NoteCommentViewModel"/> object /// </summary> /// <param name="commentVm"></param> /// <param name="comment"></param> /// <returns></returns> public static NoteCommentViewModel Convert(this NoteCommentViewModel commentVm, NoteComment comment) { var userVm = new UserViewModel(); var _note = NotelyContext.Current.Services.NoteService.GetById(comment.NoteId); var result = new NoteCommentViewModel() { Id = comment.Id, Datestamp = umbraco.library.FormatDateTime(comment.Datestamp.ToString(), "dd MMM yyyy HH:mm:ss"), LogComment = comment.LogComment, LogType = comment.LogType, NoteId = comment.NoteId, NoteName = _note.Title, User = userVm.Convert( UmbracoContext.Current.Application.Services.UserService.GetUserById(comment.UserId) ) }; return(result); }
public IEnumerable <NoteCommentViewModel> GetNoteComments(int noteId) { var commentVm = new NoteCommentViewModel(); return(NotelyContext.Current.Services.NoteCommentService.GetByNoteId(noteId).Select(c => commentVm.Convert(c))); }