Пример #1
0
        public IActionResult History(string filter, string dateStart, string dateEnd, int pageNumber = 1)
        {
            Func <Activity, bool> filterFunction = c => String.IsNullOrEmpty(filter) || c.Client.Name.Contains(filter);
            CultureInfo           provider       = CultureInfo.InvariantCulture;
            DateTime date1 = new DateTime();
            DateTime date2 = new DateTime();

            if (dateStart != null && dateStart != "")
            {
                date1 = DateTime.ParseExact(dateStart, "dd/MM/yyyy", provider);
            }
            if (dateEnd != null && dateEnd != "")
            {
                date2 = DateTime.ParseExact(dateEnd, "dd/MM/yyyy", provider);
            }
            Func <Activity, bool> filterFunctionDate = a => a.RealizationDate >= date1 && a.RealizationDate <= date2;
            var user = HttpContext.User;
            var id   = user.Claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier).Value;
            ActivityHistoryViewModel viewModel = new ActivityHistoryViewModel();

            viewModel.CurrentFilter = filter;
            if (!String.IsNullOrEmpty(dateStart) && !String.IsNullOrEmpty(dateEnd))
            {
                viewModel.Activities = _activityRepo.Activities
                                       .Where(a => a.CreatorId == Convert.ToInt32(id))
                                       .Where(filterFunction)
                                       .Where(filterFunctionDate)
                                       .OrderByDescending(a => a.RealizationDate)
                                       .Skip((pageNumber - 1) * PageSize)
                                       .Take(PageSize);
                viewModel.CurrentStartDate = date1.ToString("dd/MM/yyyy");
                viewModel.CurrentEndDate   = date2.ToString("dd/MM/yyyy");
            }
            else
            {
                viewModel.Activities = _activityRepo.Activities
                                       .Where(a => a.CreatorId == Convert.ToInt32(id))
                                       .Where(filterFunction)
                                       .OrderByDescending(a => a.RealizationDate)
                                       .Skip((pageNumber - 1) * PageSize)
                                       .Take(PageSize);
            }
            viewModel.PagingInfo = new PagingInfo
            {
                CurrentPage  = pageNumber,
                ItemsPerPage = PageSize,
                TotalItems   = _activityRepo.Activities.Where(a => a.CreatorId == Convert.ToInt32(id)).Count(filterFunction)
            };
            viewModel.Expenses = _expenseRepo.Expenses;
            return(View(viewModel));
        }
Пример #2
0
        private ICollection <ActivityHistoryViewModel> Parse(ICollection <ActivityHistory> activityHistories)
        {
            ICollection <ActivityHistoryViewModel> activityHistoryVMs = new List <ActivityHistoryViewModel>();

            ActivityHistoryViewModel activityHistoryVM = null;

            foreach (ActivityHistory activityHistory in activityHistories)
            {
                activityHistoryVM                     = new ActivityHistoryViewModel();
                activityHistoryVM.actionDate          = activityHistory.CreatedDate;
                activityHistoryVM.activity            = activityHistory.Activity;
                activityHistoryVM.approver            = activityHistory.Approver;
                activityHistoryVM.appriverDisplayName = activityHistory.ApproverDisplayName;
                activityHistoryVM.decision            = activityHistory.Decision;
                activityHistoryVM.comment             = activityHistory.Comments;
                activityHistoryVMs.Add(activityHistoryVM);
            }

            return(activityHistoryVMs.OrderBy(x => x.actionDate).ToList());
        }