Пример #1
0
        public JsonResult GetStatistic()
        {
            //IEnumerable<Result> resultList;
            //resultList = db.Results
            //             .Where(p => p.UserName == User.Identity.Name);

            var resultList = db.Results.Join(db.Questions,      // второй набор
                                             p => p.QuestionId, // свойство-селектор объекта из первого набора
                                             c => c.Id,
                                             (p, c) => new      // результат
            {
                QId       = p.QuestionId,
                IsCorrect = p.IsCorrect,
                Course    = c.Course,
                UserName  = p.UserName,
            });
            ResultReview stat = new ResultReview();

            stat.length          = resultList.Count();
            stat.correctNumber   = resultList.Where(c => c.IsCorrect == true).Count();
            stat.incorrectNumber = resultList.Where(c => c.IsCorrect == false).Count();
            stat.c1 = resultList.Where(c => c.Course == "C1").Count();
            stat.c2 = resultList.Where(c => c.Course == "C2").Count();
            stat.c3 = resultList.Where(c => c.Course == "C3").Count();
            return(Json(stat));
        }
Пример #2
0
        private static void SearchReviews()
        {
            string filePath = "../../xml/test4.xml";
            var    result   = Helpers.DeserializeFromXml <ReviewQueries>(filePath);

            SearchResult sr = new SearchResult();

            result.ReviewQueryList.ForEach(query =>
            {
                ResultSet rs = new ResultSet();
                var dbSearch = SessionState.dbBookstore.Reviews.AsQueryable();
                switch (query.Type)
                {
                case "by-period":
                    var startDate = DateTime.Parse(query.StartDate);
                    var endDate   = DateTime.Parse(query.EndDate);
                    dbSearch      = dbSearch.Where(r => r.CreatDate >= startDate && r.CreatDate <= endDate);
                    break;

                default:
                    dbSearch =
                        dbSearch.Include("Author")
                        .Where(r => r.Author.Name == query.Author)
                        .OrderBy(o => o.CreatDate)
                        .ThenBy(o => o.Text);
                    break;
                }

                var res = dbSearch.Include("Book").ToList();

                res.ForEach(r =>
                {
                    ResultReview rr = new ResultReview();
                    rr.CreatDate    = r.CreatDate.ToString("dd-MMM-yyyy");
                    rr.Text         = r.Text;
                    rr.ResultBook   = new ResultBook
                    {
                        Title   = r.Book.Title,
                        Authors = string.Join(", ", r.Book.Authors.Select(a => a.Name)),
                        ISBN    = r.Book.ISBN,
                        Url     = r.Book.Url
                    };
                    rs.ResultReviews.Add(rr);
                });

                sr.ResultSets.Add(rs);

                //logs
                //SessionState.dbLogs.SearchLogs.Add(new SearchLogs()
                //{
                //    Date = DateTime.Now,
                //    QueryXml = Helpers.SerializeToXmlToString(query)
                //});
                //SessionState.dbLogs.SaveChanges();
            });

            string outputFilePath = "../../reviews-search-results.xml";

            Helpers.SerializeToXml(sr, outputFilePath);
        }