public IEnumerable <NoteViewModel> GetNotes(int contentId, int propertyDataId, string propertyTypeAlias) { var _propertyVM = new ContentPropertyViewModel() { ContentId = contentId, PropertyDataId = propertyDataId, PropertyTypeAlias = propertyTypeAlias }; var noteVm = new NoteViewModel(); if (_propertyVM.ContentId > 0 && _propertyVM.PropertyDataId > 0) { var _content = Services.ContentService.GetById(_propertyVM.ContentId); var _property = _content.Properties.FirstOrDefault( p => p.Id == _propertyVM.PropertyDataId || p.Alias.Equals(_propertyVM.PropertyTypeAlias) ); return(NotelyContext.Current.Services.NoteService.GetAll( _propertyVM.ContentId, _property != null ? _property.PropertyType.Id : -1).Select(c => noteVm.Convert(c))); } else { return(null); } }
/// <summary> /// Convert a <see cref="Note"/> to a <see cref="NoteViewModel"/> object /// </summary> /// <param name="noteVm"></param> /// <param name="note"></param> /// <returns></returns> public static NoteViewModel Convert(this NoteViewModel noteVm, Note note) { var _content = UmbracoContext.Current.Application.Services.ContentService.GetById(note.ContentId); /* * 1) We first check if we can find the property type based on the property data id. * If we can't find the type then there is a new version published of the property value. * 2) Next step is to find the type based on the alias of the property. * */ var _property = _content.Properties.FirstOrDefault( p => p.PropertyType.Id == note.PropertyTypeId ); var userVm = new UserViewModel(); var noteTypeVm = new NoteTypeViewModel(); var noteStateVm = new NoteStateViewModel(); var contentProperty = new ContentPropertyViewModel() { ContentId = note.ContentId, ContentName = _content.Name, PropertyTypeAlias = _property.Alias }; var result = new NoteViewModel() { AssignedTo = note.AssignedTo.HasValue ? userVm.Convert( UmbracoContext.Current.Application.Services.UserService.GetUserById(note.AssignedTo.Value) ) : null, CreateDate = note.CreateDate, Description = note.Description, Id = note.Id, State = noteStateVm.Convert(note.NoteState), Title = note.Title, Type = noteTypeVm.Convert(note.NoteType), ContentProperty = contentProperty, Priority = note.Priority }; return(result); }