Ejemplo n.º 1
0
        public JsonResult Open(string Ids)
        {
            CheckPermission();
            if (string.IsNullOrEmpty(Ids))
            {
                throw new CustomException("lds");
            }

            var idsStringArray = Ids.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
            var idsLongArray   = new long[idsStringArray.Length];

            for (var i = 0; i < idsStringArray.Length; i++)
            {
                idsLongArray[i] = long.Parse(idsStringArray[i]);
            }

            using (var result = new ResponseResult <object>())
            {
                var list     = _expertQuestionService.GetAll(m => idsLongArray.Contains(m.Id));
                var entities = list as T_QUESTION[] ?? list.ToArray();

                if (list != null && entities.Any())
                {
                    foreach (var question in entities)
                    {
                        question.IsOpen = true;
                    }

                    _expertQuestionService.Update(entities);
                }

                result.Message = "公开问题成功!";
                return(new JsonResultEx(result));
            }
        }
Ejemplo n.º 2
0
        public JsonResult Reply(ExpertQuestionReplyInput input)
        {
            using (var result = new ResponseResult <object>())
            {
                var model    = Mapper.Map <T_QUESTION_REPLY>(input);
                var question = _expertQuestionService.GetByKey(input.QuestionId);

                //判断该条的问题是否存在
                if (question == null)
                {
                    throw new CustomException("问题不存在!");
                }

                //判断该问题是否已经公开
                if (question.IsOpen)
                {
                    throw new CustomException("该问题已公开,不能执行该操作!");
                }

                result.IsSuccess = _expertQuestionReplyService.Insert(model) > 0;
                if (!result.IsSuccess)
                {
                    return(new JsonResultEx(result));
                }

                result.Message = "回答成功!";
                //更新该问题的回复数
                question.ReplyCount += 1;
                _expertQuestionService.Update(question);

                //添加先锋币
                var roleType = (RoleType)question.RoleId;
                if (roleType == RoleType.Farmer)
                {
                    var userInfo = _userService.GetByKey(input.ReplyUserId);
                    if (userInfo != null)
                    {
                        userInfo.DPoint = (userInfo.DPoint ?? 0) + 5;
                        _userService.Update(userInfo);
                    }
                }

                //给问题的提问者推送通知
                _notificationService.Insert(new T_NOTIFICATION
                {
                    MsgContent           = "有人回答了你的问题,快去看看吧!",
                    IsPublic             = false,
                    TargetUserId         = question.UserId,
                    NotificationType     = 2,
                    NotificationSource   = "",
                    NotificationSourceId = question.Id,
                    IsOpen = question.IsOpen,
                });

                return(new JsonResultEx(result));
            }
        }