Exemplo n.º 1
0
        public int CreateComment(Comment comment)
        {
            using (var scope = new TransactionScope())
            {
                Mapper.Initialize(cfg => {
                    cfg.CreateMap <Comment, t_comment>();
                });

                t_comment com = Mapper.Map <t_comment>(comment);

                _unitOfWork.CommentRepository.Add(com);
                _unitOfWork.Save();
                scope.Complete();
                return(com.id);
            }
        }
Exemplo n.º 2
0
        public Comment GetCommentById(int id)
        {
            Mapper.Initialize(cfg => {
                cfg.CreateMap <t_comment, Comment>()
                .ForMember(dest => dest.postion, opt => opt.MapFrom(z => z.t_user.t_position.position))
                .ForMember(dest => dest.userfname, opt => opt.MapFrom(z => z.t_user.first_name))
                .ForMember(dest => dest.userlname, opt => opt.MapFrom(z => z.t_user.last_name));
            });

            if (id > 0)
            {
                t_comment tcom = _unitOfWork.CommentRepository.Get(id);
                Comment   dto  = Mapper.Map <Comment>(tcom);
                return(dto);
            }
            return(null);
        }
 public ActionResult PostComment(PostDetailsModel postComment)
 {
     if (ModelState.IsValid)
     {
         t_comment objComments = new t_comment();
         objComments.username  = postComment.addcomment.email;
         objComments.email     = postComment.addcomment.email;
         objComments.postid    = postComment.posts.id;
         objComments.comment   = postComment.addcomment.comment;
         objComments.date_time = System.DateTime.Now.ToString("yyyy-MM-dd");
         obj.t_comment.Add(objComments);
         obj.SaveChanges();
         return(RedirectToAction("Index"));
     }
     else
     {
         return(RedirectToAction("Index"));
     }
 }