Пример #1
0
        public OutputList GetUserProblems([FromBody] ProblemInput input)
        {
            var querys = from problems in _doContext.Problems.ToList()
                         join answers in _doContext.Answers.ToList()
                         on problems.Id equals answers.ProblemId into JoinedEmpAnswer
                         from answer in JoinedEmpAnswer.DefaultIfEmpty()
                         join users in _doContext.Users.ToList()
                         on answer.UserId equals users.Id into JoinedEmpUser
                         from user in JoinedEmpUser.DefaultIfEmpty()
                         select new ProblemListDto
            {
                Id      = problems.Id,
                Title   = problems.Title,
                Info    = answer == null ? "" : answer.Content,
                Another = user == null ? "匿名" : user.UserName,
                UserId  = user == null ? 0 : user.Id,
                Img     = "../../static/hen/问.jpg'"
            };

            querys = querys.Where(x => x.UserId == input.UserId);

            querys = querys.GroupBy(x => x.Id).Select(a => new ProblemListDto
            {
                Id      = a.Key,
                Title   = a.FirstOrDefault().Title,
                Another = a.FirstOrDefault().Another,
                Info    = a.FirstOrDefault().Info,
                UserId  = a.FirstOrDefault().UserId,
                Img     = a.FirstOrDefault().Img
            }).ToList();

            var totel = querys.Count();

            var result = _mapper.Map <List <ProblemListDto> >(querys);

            OutputList outputList = new OutputList
            {
                Totel = totel,
                Data  = result
            };

            return(outputList);
        }
Пример #2
0
        public OutputList GetAnswers([FromBody] AnswerInput input)
        {
            var querys = from answers in _doContext.Answers.ToList()
                         join users in _doContext.Users.ToList() on answers.UserId equals users.Id
                         into JoinedEmpUser
                         from user in JoinedEmpUser.DefaultIfEmpty()
                         join problems in _doContext.Problems.ToList()
                         .Where(x => x.Id == input.ProbliemId)
                         on answers.ProblemId equals problems.Id
                         into JoinedEmpProblem
                         from problem in JoinedEmpProblem.DefaultIfEmpty()
                         select new ProblemListDto
            {
                Id        = answers.Id,
                Title     = problem == null ? "" : problem.Title,
                Info      = answers.Content,
                Another   = user == null ? "" : user.UserName,
                UserId    = user == null ? 0 : user.Id,
                ProblemId = problem == null ? 0 : problem.Id,
            };


            var totel = querys.Count();

            querys = querys.Where(x => x.ProblemId == input.ProbliemId);

            var result = _mapper.Map <List <ProblemListDto> >(querys);

            OutputList outputList = new OutputList
            {
                Totel = totel,
                Data  = result
            };

            return(outputList);
        }