示例#1
0
        public EvaluateDetail(Models.Evaluate model, List <StorageFile> imgList)
        {
            Id         = model.Id;
            Content    = model.Content;
            Score      = model.Score;
            MemberId   = model.MemberId;
            MemberName = model.MemberName;
            CreateTime = model.CreateTime;

            Images = imgList.Select(me => me.Simplified()).ToList();
        }
示例#2
0
        public ListEvaluateModel(Models.Evaluate model)
        {
            Id         = model.Id;
            Content    = model.Content;
            Score      = model.Score;
            MemberId   = model.MemberId;
            MemberName = model.MemberName;
            CreateTime = model.CreateTime;

            var storageFileService = HostConstObject.Container.Resolve <IStorageFileService>();

            Images = storageFileService.GetFiles(model.Id, EvaluateModule.Key).Select(me => me.Simplified()).ToList();

            var memberService = HostConstObject.Container.Resolve <IMemberService>();

            var file = memberService.GetAvatarFile(model.MemberId);

            Avatar = file?.Simplified();
        }
示例#3
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);
        }
示例#4
0
        public void SaveEvaluate(Models.Evaluate evaluate)
        {
            using (var dbContext = new EvaluateDbContext())
            {
                if (dbContext.Evaluate.Count(
                        e =>
                        e.MemberId.Equals(evaluate.MemberId, StringComparison.OrdinalIgnoreCase) &&
                        e.SourceId.Equals(evaluate.SourceId)) > 0)
                {
                    throw new Exception("不可以重复评价");
                }

                dbContext.Evaluate.Add(evaluate);
                if (dbContext.SaveChanges() > 0 && evaluate.Files != null)
                {
                    foreach (var file in evaluate.Files)
                    {
                        _storageFileService.AssociateFile(evaluate.Id, EvaluateModule.Key, EvaluateModule.DisplayName,
                                                          file.Id);
                    }
                }
            }
        }