Ejemplo n.º 1
0
        /// <summary>
        /// Récupére l'entité désignée par l'id en paramétre.
        /// </summary>
        /// <param name="id">Id de l'entité</param>
        /// <returns>Message de retour avec l'entité</returns>
        public async Task <DTO.Comment> GetById(long id)
        {
            ENT.Comment comment = await CommentDomain.Get(id);

            DTO.Comment dtoComment = null;
            if (comment != null)
            {
                dtoComment = Mapper.Map <ENT.Comment, DTO.Comment>(comment);
            }

            return(dtoComment);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Ajoute un commentaire en base
        /// </summary>
        /// <param name="comment">Commentaire</param>
        /// <returns>Message de retour</returns>
        public async Task <HttpResponseMessageResult> Post(DTO.Comment comment)
        {
            ENT.Comment element = Mapper.Map <DTO.Comment, ENT.Comment>(comment);

            comment = Mapper.Map <ENT.Comment, DTO.Comment>(await CommentDomain.Add(element));

            HttpResponseMessageResult res = new HttpResponseMessageResult()
            {
                IsSuccess = true
            };

            res.Json = JsonConvert.SerializeObject(comment);

            return(res);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Récupére toutes les entités DTO existantes.
        /// </summary>
        /// <returns>Message de retour avec la liste en json</returns>
        public async Task <IEnumerable <DTO.Comment> > GetAll()
        {
            IEnumerable <ENT.Comment> comments = await CommentDomain.Get();

            IEnumerable <DTO.Comment> dtoComments = null;

            if (comments != null)
            {
                dtoComments = Mapper.Map <IEnumerable <ENT.Comment>, IEnumerable <DTO.Comment> >(comments);
            }
            else
            {
                dtoComments = new List <DTO.Comment>();
            }

            return(dtoComments);
        }
Ejemplo n.º 4
0
        public JsonResult <object> AddComment(AddCommentRequest request)
        {
            if (request == null)
            {
                return(JsonError("请求参数不能为空"));
            }
            if (string.IsNullOrEmpty(request.CommentContent))
            {
                throw new Exception("评论内容不能为空");
            }
            if (!_articleService.ExistData(request.ArticleID))
            {
                throw new Exception("文章不存在");
            }

            var baseInfo = GetBaseInfo();

            if (!_weCharUserInfoService.Exist(baseInfo.UnionID))
            {
                throw new Exception("微信账号不存在");
            }

            var msgObj = WXHelper.MsgCheck(request.CommentContent);

            if (msgObj.errcode == Senparc.Weixin.ReturnCode.请求成功)
            {
                CommentDomain domain = request.ToDomainModel();
                domain.UnionID    = baseInfo.UnionID;
                domain.ID         = Guid.NewGuid();
                domain.CreateTime = DateTime.Now;
                _commentService.NewCreate(domain);


                return(JsonNet("发表成功"));
            }
            if (msgObj.errcode == (Senparc.Weixin.ReturnCode) 40001)
            {
                WXHelper.RemoveAccessToken();
                //access_token失效 请重新获取
                return(JsonNet("发表错误,请重新发送"));
            }

            return(JsonError(msgObj.errcode.ToString()));
        }
Ejemplo n.º 5
0
 public static Comment ToDbModel(this CommentDomain model)
 {
     return(Mapper.Map <Comment>(model));
 }
Ejemplo n.º 6
0
 /// <summary>
 /// 增 - 直接添加
 /// </summary>
 /// <param name="domain"></param>
 public void NewCreate(CommentDomain domain)
 {
     DataProvider.Create(domain.ToDbModel());
 }