public ActionResult AllUsers()
        {
            var applicationUserModel = this.userServices.GetAllUsers();

            List <UserViewModel> usersViewModel = UserViewModel.Convert(applicationUserModel).ToList();

            return(this.View(usersViewModel));
        }
Exemple #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);
        }
Exemple #3
0
        public async ValueTask <IActionResult> Put([FromBody] UserViewModel model)
        {
            if (ModelState.IsValid)
            {
                bool isUser = await _repo.Item().AnyAsync(u => model.Id == u.Id);

                if (isUser)
                {
                    ApplicationUser userMappedFromModel = model.Convert <UserViewModel, ApplicationUser>(_mapper);
                    (bool succeeded, ApplicationUser updatedUser, string error) = await _repo.Update(userMappedFromModel, userMappedFromModel.Id);

                    if (succeeded)
                    {
                        return(Ok(updatedUser.Convert <ApplicationUser, UserViewModel>(_mapper)));
                    }
                    return(BadRequest(new { Message = error }));
                }
            }
            return(BadRequest(new { Errors = ModelState.Values.SelectMany(e => e.Errors).ToList() }));
        }
Exemple #4
0
        /// <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);
        }