示例#1
0
        public ActionResult Log(MedicationUploadListModelFilter filter = null, int pageNumber = 1)
        {
            int totalRecords;

            if (filter != null && filter.Status == 0)
            {
                filter.Status = null;
            }
            if (filter != null && filter.UploadedBy == -1)
            {
                filter.UploadedBy = null;
            }
            var medicationData = _medicationService.GetUploadList(pageNumber, _pageSize, filter, out totalRecords);
            var model          = medicationData == null ? new MedicationUploadListModel() : new MedicationUploadListModel {
                Collection = medicationData
            };

            model.Filter = filter;
            model.Url    = _mediaRepository.GetMedicationUploadMediaFileLocation().Url;

            var values = MedicationUploadStatus.UploadStarted.GetNameValuePairs();
            var status = new List <OrderedPair <long, string> >();

            status.Add(new OrderedPair <long, string>(0, "All"));
            foreach (var source in values.Where(x => x.FirstValue != (long)MedicationUploadStatus.UploadStarted && x.FirstValue != (long)MedicationUploadStatus.FileNotFound))
            {
                status.Add(new OrderedPair <long, string>(source.FirstValue, source.SecondValue));
            }
            ViewBag.Status = status;

            var currentAction          = ControllerContext.RouteData.Values["action"].ToString();
            Func <int, string> urlFunc =
                pn =>
                filter != null?Url.Action(currentAction,
                                          new
            {
                pageNumber = pn,
                filter.Name,
                filter.FromDate,
                filter.ToDate,
                filter.Status,
            }) : null;

            model.PagingModel = new PagingModel(pageNumber, _pageSize, totalRecords, urlFunc);
            return(View(model));
        }
示例#2
0
        public IEnumerable <MedicationUploadViewModel> GetUploadList(int pageNumber, int pageSize, MedicationUploadListModelFilter filter, out int totalRecords)
        {
            var list        = _medicationUploadRepository.GetUploadList(pageNumber, pageSize, filter, out totalRecords).ToArray();
            var uploadByIds = list.Select(c => c.UploadedBy).Distinct().ToArray();

            IEnumerable <OrderedPair <long, string> > uploadedbyAgentNameIdPair = null;

            if (uploadByIds != null && uploadByIds.Any())
            {
                uploadedbyAgentNameIdPair = _organizationRoleUserRepository.GetNameIdPairofUsers(uploadByIds).ToArray();
            }
            foreach (var rapsUploadModel in list)
            {
                if (uploadedbyAgentNameIdPair != null && uploadedbyAgentNameIdPair.Any())
                {
                    rapsUploadModel.UploadedName = uploadedbyAgentNameIdPair.Single(ap => ap.FirstValue == rapsUploadModel.UploadedBy).SecondValue;
                }
            }
            return(list);
        }
        public IEnumerable <MedicationUploadViewModel> GetUploadList(int pageNumber, int pageSize, MedicationUploadListModelFilter filter, out int totalRecords)
        {
            using (var adapter = PersistenceLayer.GetDataAccessAdapter())
            {
                var linqMetaData = new LinqMetaData(adapter);
                IEnumerable <MedicationUploadEntity> entities = (from cu in linqMetaData.MedicationUpload where cu.StatusId == (long)MedicationUploadStatus.Uploaded select cu).ToList();

                if (filter.IsEmpty())
                {
                    var query = (from cu in linqMetaData.MedicationUpload where cu.StatusId != (long)MedicationUploadStatus.UploadStarted select cu).OrderByDescending(x => x.UploadTime);

                    totalRecords = query.Count();
                    entities     = query.WithPath(prefetchPath => prefetchPath.Prefetch(e => e.File)).TakePage(pageNumber, pageSize).ToList();
                }
                else
                {
                    var query = (from cu in linqMetaData.MedicationUpload
                                 where cu.StatusId != (long)MedicationUploadStatus.UploadStarted &&
                                 (filter.FromDate == null || filter.FromDate <= cu.UploadTime.Date) &&
                                 (filter.ToDate == null || filter.ToDate >= cu.UploadTime.Date) &&
                                 (filter.Status == null || (long)filter.Status == cu.StatusId) &&
                                 (filter.Name == null || cu.File.Path.Contains(filter.Name)) &&
                                 (filter.UploadedBy == null || filter.UploadedBy == cu.UploadedBy)
                                 select cu).OrderByDescending(x => x.UploadTime);

                    totalRecords = query.Count();
                    entities     = query.WithPath(prefetchPath => prefetchPath.Prefetch(e => e.File)).TakePage(pageNumber, pageSize).ToList();
                }


                return(Mapper.Map <IEnumerable <MedicationUploadEntity>, IEnumerable <MedicationUploadViewModel> >(entities));
            }
        }