Ejemplo n.º 1
0
        public ActionResult Index()
        {
            var userId = User.Identity.GetUserId();
            var user   = userService.FindById(userId);

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

            return(RedirectToAction("Edit", new { Id = userId }));
        }
Ejemplo n.º 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 }));
        }
Ejemplo n.º 3
0
        public JsonResult Comment(AddCommentModel model)
        {
            var alert = HtmlHelper.Vertex().Alert();

            try
            {
                bool isValid = !string.IsNullOrEmpty(model.Content);
                if (!Request.IsAuthenticated)
                {
                    isValid = !(string.IsNullOrEmpty(model.FullName) ||
                                string.IsNullOrEmpty(model.Email) ||
                                string.IsNullOrEmpty(model.Content));
                }

                if (isValid)
                {
                    var post = postService.GetById(model.PostId);

                    var comment       = new Comment();
                    var userAvatarUrl = mediaStorageService.GetPictureUrl(null);

                    if (Request.IsAuthenticated)
                    {
                        var userId      = User.Identity.GetUserId();
                        var currentUser = userService.FindById(userId);

                        comment.UserId   = userId;
                        comment.FullName = currentUser.UserName;
                        comment.Email    = currentUser.Email;
                        userAvatarUrl    = mediaStorageService.GetPictureUrl(currentUser.PictureId);
                    }
                    else
                    {
                        comment.UserId   = null;
                        comment.FullName = model.FullName;
                        comment.Email    = model.Email;
                    }

                    if (model.ParentId.HasValue && model.ParentId.Value > 0)
                    {
                        comment.ParentId = model.ParentId;
                    }

                    comment.PostId         = model.PostId;
                    comment.Commentary     = model.Content;
                    comment.Approved       = post.ApproveComment;
                    comment.CommentDateUtc = DateTime.UtcNow;

                    comment.Commentary = WebHelper.ConvertPlainTextToHtml(comment.Commentary);

                    var result = postService.SaveComment(comment);
                    if (result)
                    {
                        #region Comment Template

                        string subCommentTemplate =
                            @"<div class='comment-subitem media mt-4'>" +
                            "<a href='#'>" +
                            "<img class='avatar comment-user-avatar mr-3 pi-img-round' src='/Content/img/nophoto.jpg' alt='@FullName' title='@FullName' />" +
                            "</a>" +
                            "<div class='media-body'>" +
                            "<h4 class='h6 mb-1'>@FullName <span class='small ml-2 text-muted comment-date'>@CreateDate</span></h4>" +
                            "<p class='mb-1 comment-content'>" +
                            "@Content" +
                            "</p>" +
                            "</div>" +
                            "</div>";
                        subCommentTemplate = subCommentTemplate.Replace("@FullName", comment.FullName)
                                             .Replace("@CreateDate", comment.CommentDateUtc.ToRelativeFormat())
                                             .Replace("@Content", comment.Commentary)
                                             .Replace("/Content/img/nophoto.jpg", userAvatarUrl);

                        string contentTemplate =
                            @"<li class='comment-item media mt-5'>" +
                            "<a href='#'>" +
                            "<img class='avatar comment-user-avatar mr-3 pi-img-round' src='/Content/img/nophoto.jpg' alt='@FullName' title='@FullName' />" +
                            "</a>" +
                            "<div class='media-body clearfix'>" +
                            "<h4 class='h6 mb-1 comment-full-name'>@FullName <span class='small ml-2 text-muted comment-date'>@CreateDate</span></h4>" +
                            "<p class='mb-1 comment-content'>" +
                            "@Content" +
                            "</p>" +
                            "<a href='javascript:void(0)' data-comment-id='@Id' class='comment-reply text-primary anim-link-2 anim-link-2-primary small'>Reply</a>" +
                            "</div>" +
                            "</li>";
                        contentTemplate = contentTemplate.Replace("@FullName", comment.FullName)
                                          .Replace("@CreateDate", comment.CommentDateUtc.ToRelativeFormat())
                                          .Replace("@Content", comment.Commentary)
                                          .Replace("@Id", comment.Id.ToString())
                                          .Replace("/Content/img/nophoto.jpg", userAvatarUrl);

                        #endregion Comment Template

                        string appromeMessage = alert.Text("Thanks, your comment sent to approve.").Color(BootstrapColor.Success).ToHtmlString();

                        if (comment.ParentId.HasValue)
                        {
                            return(Json(new
                            {
                                success = true,
                                postId = comment.PostId,
                                parentId = comment.ParentId,
                                result = comment.Approved ? subCommentTemplate : appromeMessage
                            }, JsonRequestBehavior.AllowGet));
                        }
                        else
                        {
                            return(Json(new
                            {
                                success = true,
                                postId = comment.PostId,
                                result = comment.Approved ? contentTemplate : appromeMessage
                            }, JsonRequestBehavior.AllowGet));
                        }
                    }
                }

                return(Json(new
                {
                    success = false,
                    postId = model.PostId,
                    parentId = (model.ParentId.HasValue && model.ParentId.Value > 0) ? model.ParentId.Value : 0,
                    result = alert.Text("Enter required fields.").Color(BootstrapColor.Warning).AppendCssClass("mt-2").ToHtmlString()
                }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                return(Json(new
                {
                    success = false,
                    postId = model.PostId,
                    parentId = (model.ParentId.HasValue && model.ParentId.Value > 0) ? model.ParentId.Value : 0,
                    result = alert.Text("Something is wrong, please try again.\n Detail: " + ex.Message).Color(BootstrapColor.Danger).ToHtmlString()
                }, JsonRequestBehavior.AllowGet));
            }
        }