예제 #1
0
        /// <summary>
        /// Edit user
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ActionResult Edit(string id)
        {
            var user = userService.GetById(id);

            if (user == null)
            {
                this.NotifyError("User not found.");
                return(RedirectToAction("List"));
            }

            var roles = db.Roles.Select(x => new ApplicationRoleModel
            {
                Id   = x.Id,
                Name = x.Name
            }).ToList();

            var posts = postService.GetActives(id).Select(x => new PostModel
            {
                Id           = x.Id,
                Title        = x.Title,
                CreateDate   = x.CreateDateUtc,
                Url          = urlService.GetUrl(x.Id, nameof(Post)),
                CommentCount = postService.GetCommentCount(x.Id, null),
                ViewCount    = x.ViewCount,
                IsActive     = x.IsActive,
                UserName     = x.UserName,
                PicturePath  = x.Picture.FilePath
            }).ToList();

            var model = new ApplicationUserModel
            {
                Id                = user.Id,
                UserName          = user.UserName,
                Email             = user.Email,
                EmailConfirmed    = user.EmailConfirmed,
                IsActive          = user.IsActive,
                AvatarId          = user.PictureId,
                Description       = user.Description,
                Location          = user.Location,
                Name              = user.Name,
                Surname           = user.Surname,
                AvatarUrl         = mediaStorageService.GetPictureUrl(user.PictureId),
                Roles             = roles,
                SelectedRoleNames = userService.GetRoles(user.Id).ToArray(),
                IsAdmin           = roles.Any(s => s.Name == SystemRoles.Admin),
                IsOwnAccount      = User.Identity.GetUserId() == user.Id,
                Posts             = posts
            };

            return(View(model));
        }
예제 #2
0
        //
        // GET: /Manage/Index
        public async Task <ActionResult> Index(ManageMessageId?message)
        {
            ViewBag.StatusMessage =
                message == ManageMessageId.ChangePasswordSuccess ? "Your password has been changed."
                : message == ManageMessageId.SetPasswordSuccess ? "Your password has been set."
                : message == ManageMessageId.SetTwoFactorSuccess ? "Your two-factor authentication provider has been set."
                : message == ManageMessageId.Error ? "An error has occurred."
                : message == ManageMessageId.AddPhoneSuccess ? "Your phone number was added."
                : message == ManageMessageId.RemovePhoneSuccess ? "Your phone number was removed."
                : "";

            var userId      = User.Identity.GetUserId();
            var currentUser = AplicationUserService.FindById(userId);

            var model = new ManageIndexViewModel
            {
                HasPassword       = HasPassword(),
                PhoneNumber       = await AplicationUserService.GetPhoneNumberAsync(userId),
                TwoFactor         = await AplicationUserService.GetTwoFactorEnabledAsync(userId),
                Logins            = await AplicationUserService.GetLoginsAsync(userId),
                BrowserRemembered = await AuthenticationManager.TwoFactorBrowserRememberedAsync(userId),
                AvatarId          = currentUser.PictureId,
                AvatarUrl         = mediaStorageService.GetPictureUrl(currentUser.PictureId),
                UserName          = currentUser.UserName,
                Email             = currentUser.Email,
                Description       = currentUser.Description,
                Roles             = string.Join(", ", AplicationUserService.GetRoles(userId).ToArray())
            };

            return(RedirectToAction("UserEdit", new { Id = userId }));
        }