Ejemplo n.º 1
0
        public ApiResult Create(string sourceId, [FromBody] CreateEvaluateModel postEvaluate)
        {
            Argument.ThrowIfNullOrEmpty(postEvaluate.Content, "评论内容");
            Argument.ThrowIfNullOrEmpty(sourceId, "话题Id");
            var id = sourceId.ToGuid();

            if (id.Equals(Guid.Empty))
            {
                throw new WebApiInnerException("0001", "话题Id类型格式不正确");
            }

            if (postEvaluate.Content.Length > 1000)
            {
                throw new WebApiInnerException("0002", "评论内容太长");
            }


            var member   = _memberService.FindMemberById(AuthorizedUser.Id);
            var evaluate = new Models.Evaluate()
            {
                Id          = KeyGenerator.GetGuidKey(),
                Content     = postEvaluate.Content,
                Score       = postEvaluate.Score,
                MemberId    = AuthorizedUser.Id,
                MemberName  = member.NickName,
                SourceId    = id,
                ModuleKey   = EvaluateModule.Key,
                ModuleName  = EvaluateModule.DisplayName,
                SourceType  = SourceType,
                CreateTime  = DateTime.Now,
                IsAnonymity = false,
                Status      = 1,
            };

            _evaluateService.SaveEvaluate(evaluate);
            var result = new ApiResult();

            result.SetData(new ListEvaluateModel(evaluate));
            return(result);
        }