Beispiel #1
0
        /// <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);
        }
Beispiel #2
0
        public NoteTypeViewModel GetNoteType(int id)
        {
            var noteTypeVm = new NoteTypeViewModel();

            return(noteTypeVm.Convert(NotelyContext.Current.Services.NoteTypeService.GetById(id)));
        }
Beispiel #3
0
        public IEnumerable <NoteTypeViewModel> GetNoteTypes()
        {
            var _noteType = new NoteTypeViewModel();

            return(NotelyContext.Current.Services.NoteTypeService.GetAll().Select(c => _noteType.Convert(c)));
        }