Exemplo n.º 1
0
        public async Task <IActionResult> SubmitFeedback(UserFeedbackVM input)
        {
            var strList = new List <string> {
                input.Description
            };

            if (StrIsNull(strList) || input.Type == UserFeedbackType.未选择)
            {
                return(Json(new { result = false, contentNull = true, message = "必填项为空,请检查类型和描述是否已经选择和填写!" }));
            }
            var user         = GetUser();
            var userFeedback = new UserFeedback
            {
                Link              = EncodeFilterHelper.EncodeHtmlForLink(input.Link),
                Description       = EncodeFilterHelper.EncodeHtml(input.Description),
                ContactWay        = EncodeFilterHelper.EncodeHtml(input.ContactWay),
                Type              = input.Type,
                FeedbackIPAddress = GetClientIpAddress(),
                FeedUser          = user == null ? null : user
            };
            var r = await _userFeedback.AddOrEditAndSaveAsyn(userFeedback);

            if (r)
            {
                return(Json(new { result = true }));
            }
            return(Json(new { result = false, message = "提交失败!" }));
        }
Exemplo n.º 2
0
        /// <summary>
        /// 获取所有的用户反馈
        /// </summary>
        /// <param name="id">用户的Id 标明可以使用用户Id查询对应的用户提交的记录</param>
        /// <returns></returns>
        public async Task <List <UserFeedbackVM> > GetUserFeedbacks(Guid?id)
        {
            var userFeedbacksVM = new List <UserFeedbackVM>();
            var userFeedbacks   = new List <UserFeedback>();

            if (id.HasValue && id.Value != Guid.Empty)
            {
                var query = await _userFeedback.GetAllIncludingAsyn(x => x.FeedUser);

                var result = query.Where(x => x.FeedUser.Id == id.Value.ToString());
                if (result.Count() > 0)
                {
                    userFeedbacks = result.OrderByDescending(x => x.CreateTime).ToList();
                }
            }
            else
            {
                var query = await _userFeedback.GetAllIncludingAsyn(x => x.FeedUser);

                if (query.Count() > 0)
                {
                    userFeedbacks = query.OrderByDescending(x => x.CreateTime).ToList();
                }
            }
            if (userFeedbacks.Count() > 0)
            {
                foreach (var userFeedback in userFeedbacks)
                {
                    var userFeedbackVM = new UserFeedbackVM(userFeedback);
                    userFeedbackVM.OrderNumber = (userFeedbacksVM.Count() + 1).ToString();
                    userFeedbacksVM.Add(userFeedbackVM);
                }
            }
            return(userFeedbacksVM);
        }