Ejemplo n.º 1
0
        /// <summary>
        /// Converts a <see cref="NoteState"/> object to a <see cref="NoteStateViewModel"/> object
        /// </summary>
        /// <param name="noteStateVm"></param>
        /// <param name="noteState"></param>
        /// <returns></returns>
        public static NoteStateViewModel Convert(this NoteStateViewModel noteStateVm, NoteState noteState)
        {
            if (noteState == null)
            {
                return(null);
            }

            return(new NoteStateViewModel()
            {
                Id = noteState.Id,
                Title = noteState.Title
            });
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
0
        public IEnumerable <NoteStateViewModel> GetNoteStates()
        {
            var _noteState = new NoteStateViewModel();

            return(NotelyContext.Current.Services.NoteStateService.GetAll().Select(c => _noteState.Convert(c)));
        }