Exemple #1
0
        public ActionResult Index(DiaryLogSearchViewModel diaryLogSearch)
        {
            if (!IsSessionExist())
            {
                return(RedirectToAction("Login", "Account"));
            }

            IQueryable <DiaryLog> diaryLogs = _genericRepository.GetAll();

            int userId = Convert.ToInt32(Session["Id"].ToString());

            if (!Session["Account"].ToString().Equals("9999"))
            {
                diaryLogs = diaryLogs.Where(x => x.UserId.Equals(userId));
            }

            if (diaryLogSearch.dateStart != null)
            {
                diaryLogs = diaryLogs.Where(x => x.DiaryLogDate >= diaryLogSearch.dateStart);
            }

            if (diaryLogSearch.dateEnd != null)
            {
                diaryLogs = diaryLogs.Where(x => x.DiaryLogDate <= diaryLogSearch.dateEnd);
            }

            if (!string.IsNullOrEmpty(diaryLogSearch.content))
            {
                diaryLogs = diaryLogs.Where(x => x.DiaryLogContents.Contains(diaryLogSearch.content));
            }

            var gro = from d in diaryLogs
                      group d by d.DiaryLogDate;

            List <DiaryLogGroupByDateVM> diaryLogGroups = new List <DiaryLogGroupByDateVM>();

            foreach (var g in gro)
            {
                DiaryLogGroupByDateVM diaryLogGroup = new DiaryLogGroupByDateVM();
                List <DiaryLog>       diaLogs       = new List <DiaryLog>();

                foreach (var item in g)
                {
                    diaLogs.Add(item);
                }

                diaryLogGroup.DiaryLogDate = g.Key;
                diaryLogGroup.DiaryLogs    = diaLogs;

                diaryLogGroups.Add(diaryLogGroup);
            }


            diaryLogSearch.DiaryLogGroupByDates = diaryLogGroups.OrderByDescending(p => p.DiaryLogDate).ToPagedList(diaryLogSearch.Page > 0 ? diaryLogSearch.Page - 1 : 0, PageSize);

            return(View(diaryLogSearch));
        }
Exemple #2
0
        public ActionResult Index()
        {
            if (!IsSessionExist())
            {
                return(RedirectToAction("Login", "Account"));
            }

            DiaryLogSearchViewModel diaryLogSearch = new DiaryLogSearchViewModel();

            return(View(diaryLogSearch));
        }