示例#1
0
 /// <summary>
 /// Converts a <see cref="NoteTypeViewModel"/> object to a <see cref="NoteType"/> object
 /// </summary>
 /// <param name="noteType"></param>
 /// <param name="noteTypeVm"></param>
 /// <returns></returns>
 public static NoteType Convert(this NoteType noteType, NoteTypeViewModel noteTypeVm)
 {
     return(new NoteType()
     {
         Id = noteTypeVm.Id,
         Title = noteTypeVm.Title,
         Icon = noteTypeVm.Icon,
         CanAssign = noteTypeVm.CanAssign
     });
 }
示例#2
0
        /// <summary>
        /// Converts a <see cref="NoteType"/> object to <see cref="NoteTypeViewModel"/> object
        /// </summary>
        /// <param name="noteTypeVm"></param>
        /// <param name="noteType"></param>
        /// <returns></returns>
        public static NoteTypeViewModel Convert(this NoteTypeViewModel noteTypeVm, NoteType noteType)
        {
            if (noteType == null)
            {
                return(null);
            }

            return(new NoteTypeViewModel()
            {
                Id = noteType.Id,
                Title = noteType.Title,
                Icon = noteType.Icon,
                CanAssign = noteType.CanAssign
            });
        }
示例#3
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);
        }
示例#4
0
        public NoteTypeViewModel GetNoteType(int id)
        {
            var noteTypeVm = new NoteTypeViewModel();

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

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