Beispiel #1
0
        public ActionResult Edit()
        {
            UserDTO userDTO = _iapiResponse.Get <UserDTO>("users?value=" + User.Identity.GetUserName());

            AccountVM.EditUserViewModel userVM = new AccountVM.EditUserViewModel();
            userVM.DisplayName = userDTO.DisplayName;
            userVM.ImageUser   = ImageFunction.ConvertImage(userDTO.ImageUser);
            if (userDTO == null)
            {
                return(HttpNotFound());
            }
            return(View(userVM));
        }
Beispiel #2
0
        private List <CommentDTO> MappingComment(List <Comment> listComment)
        {
            List <CommentDTO> listCommentDto = new List <CommentDTO>();

            foreach (Comment comment in listComment)
            {
                CommentDTO commentDto = Mapper.Map <Comment, CommentDTO>(comment);
                commentDto.DisplayName = comment.User.DisplayName;
                commentDto.ImageUser   = ImageFunction.ConvertImage(comment.User.ImageUser);
                commentDto.Email       = comment.User.Email;
                listCommentDto.Add(commentDto);
            }
            return(listCommentDto);
        }
Beispiel #3
0
        public WebMappingProfile()
        {
            CreateMap <AccountVM.RegisterViewModel, UserDTO>().ReverseMap();
            CreateMap <UserDTO, AccountVM.RegisterViewModel>().ReverseMap();
            CreateMap <AccountVM.LoginViewModel, UserDTO>().ReverseMap();
            CreateMap <UserDTO, AccountVM.LoginViewModel>().ReverseMap();
            CreateMap <PostVM.PostCreateVM, PostDTO>()
            .ForMember(d => d.ID, opt => opt.MapFrom(s => s.PostId))
            .ReverseMap();
            CreateMap <PostDTO, PostVM.PostCreateVM>()
            .ForMember(d => d.PostId, opt => opt.MapFrom(s => s.ID))
            .ForMember(d => d.RowVersion, opt => opt.MapFrom(s => s.RowVersion))
            .ReverseMap();
            CreateMap <CommentVM, CommentDTO>().ReverseMap();

            CreateMap <CommentDTO, CommentVM>()
            .ForMember(d => d.ImageUser, opt => opt.MapFrom(s => s.ImageUser))
            .ReverseMap();

            CreateMap <PostDTO, PostVM.PostDetailVM>()
            .ForMember(d => d.PostId, opt => opt.MapFrom(s => s.ID))
            .ForMember(d => d.Image, opt => opt.MapFrom(s => ImageFunction.ConvertImage(s.Image)))
            .ForMember(d => d.ListComment, opt => opt.MapFrom(s => s.ListCommentDTO))
            .ForMember(d => d.ListTag, opt => opt.MapFrom(s => s.ListTagDTO))
            .ReverseMap();

            CreateMap <PostDTO, PostVM.PostIndexVM>()
            .ForMember(d => d.PostId, opt => opt.MapFrom(s => s.ID))
            .ForMember(d => d.Image, opt => opt.MapFrom(s => ImageFunction.ConvertImage(s.Image)))
            .ForMember(d => d.ImageUser, opt => opt.MapFrom(s => ImageFunction.ConvertImage(s.ImageUser)))
            .ForMember(d => d.ListTag, opt => opt.MapFrom(s => s.ListTagDTO))
            .ForMember(d => d.UserId, opt => opt.MapFrom(s => s.UserId))
            .ForMember(d => d.Email, opt => opt.MapFrom(s => s.Email))
            .ReverseMap();
            CreateMap <TagVM, TagDTO>().ReverseMap();
            CreateMap <TagDTO, TagVM>()
            .ForMember(d => d.TagId, opt => opt.MapFrom(s => s.TagId))
            .ForMember(d => d.Name, opt => opt.MapFrom(s => s.NameTag))
            .ReverseMap();
            //CreateMap<PostVM.PostCreateVM, PostDTO>().ReverseMap();
            //CreateMap<PostDTO, PostVM.PostCreateVM>().ReverseMap();
        }
Beispiel #4
0
        public ActionResult Create([Bind(Include = "PostId,CommentContent")] CommentVM comment)
        {
            string url = TempData["Url"] as string;

            if (ModelState.IsValid)
            {
                CommentDTO commentDTO = _imapper.Map <CommentVM, CommentDTO>(comment);
                commentDTO.Email = User.Identity.GetUserName();
                int?    result = ConvertString.ConvertToInt(_iapiResponse.Post <CommentDTO>("comments", commentDTO));
                UserDTO user   = _iapiResponse.Get <UserDTO>("users?value=" + User.Identity.GetUserName());
                comment.DisplayName = user.DisplayName;
                comment.CreateDate  = DateTime.Now;
                comment.ImageUser   = ImageFunction.ConvertImage(user.ImageUser);
                if (result == null)
                {
                    ModelState.AddModelError("", "Can not sent your comment");
                }
                return(PartialView("_CommentsPartial", comment));
            }
            return(RedirectToAction("Details", "Posts", new { id = comment.PostId, slug = url }));
        }