Exemplo n.º 1
0
        public GenericCollectionViewModel <ListDocumentsLightViewModel> GetByFilter(DocumentFilterViewModel model)
        {
            var lang = this._languageService.CurrentLanguage;
            ConditionFilter <Document, long> condition = new ConditionFilter <Document, long>()
            {
                Order = Order.Descending
            };

            if (model.Sort?.Count > 0)
            {
                if (model.Sort[0].Dir != "desc")
                {
                    condition.Order = Order.Ascending;
                }
            }

            //if (model.DateFrom.HasValue) model.DateFrom = model.DateFrom.SetTimeToNow();
            //if (model.DateTo.HasValue) model.DateTo = model.DateTo.SetTimeToMax();

            // The IQueryable data to query.
            IQueryable <Document> queryableData = this._documentRepository.Get(condition);

            //queryableData = queryableData.Where(x => x.Language == lang && x.ParentKeyVendor != null);

            if (string.IsNullOrEmpty(model.DocomentNumber) == false)
            {
                queryableData = queryableData.Where(x => x.DocumentNumber.ToString().Contains(model.DocomentNumber));
            }

            if (string.IsNullOrEmpty(model.CountReceipts) == false)
            {
                queryableData = queryableData.Where(x => x.CountReceipts.ToString().Contains(model.CountReceipts));
            }

            if (string.IsNullOrEmpty(model.FirstNumber) == false)
            {
                queryableData = queryableData.Where(x => x.FirstNumber.ToString().Contains(model.FirstNumber));
            }

            var entityCollection = queryableData.ToList();
            var dtoCollection    = entityCollection.Select(entity => entity.ToListModel()).ToList();


            var total = dtoCollection.Count();

            dtoCollection = dtoCollection.Skip(model.PageIndex * model.PageSize).Take(model.PageSize).ToList();
            var result = new GenericCollectionViewModel <ListDocumentsLightViewModel>
            {
                Collection = dtoCollection,
                TotalCount = total,
                PageIndex  = model.PageIndex,
                PageSize   = model.PageSize
            };

            return(result);
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Index(int templateId, DocumentFilterViewModel model = null)
        {
            if (templateId <= 0)
            {
                return(NotFound());
            }


            if (model == null)
            {
                model = new DocumentFilterViewModel();
            }

            model.TemplateId = templateId;

            var query = from d in Uow.Documents.GetAll()
                        join e in Uow.Employees.GetAll() on d.CreatorId equals e.Id//todo user and employee mapping table and auto initialize
                        select new DocumentsViewModel
            {
                Id           = d.Id,
                DepartmentId = d.DepartmentId,
                JobTitleId   = d.JobTitleId,


                CreateDate = d.CreateDate,
                CreatorId  = d.CreatorId,
                IsDeleted  = d.IsDeleted,

                IsApproved = d.IsApproved
            };


            query = query.Filter(q => q.Id, WhereOperator.Equals, model.Id);

            if (!User.IsInAnyRole(Constants.Roles.Admin, Constants.Roles.IT, Constants.Roles.Administration))
            {
                query = query.Filter(q => q.CreatorId, WhereOperator.Equals, UserId);
            }


            model.PagedList = await query.ToPagedListAsync(model.Page, model.PageSize);

            var jobTitles   = _cache.GetJobTitle(null, 1);
            var departments = _cache.GetDepartment(1);
            var branches    = _cache.GetBranch(1);

            foreach (var row in model.PagedList)
            {
                if (row.JobTitleId != null)
                {
                    row.JobTitle = jobTitles.TryGetValue(row.JobTitleId.Value);
                }
                if (row.DepartmentId != null)
                {
                    row.Department = departments.TryGetValue(row.DepartmentId.Value);
                }

                //if (row.BranchId != null)
                //    row.Branch = branches.TryGetValue(row.BranchId.Value);
            }

            if (Request.IsAjaxRequest())
            {
                return(PartialView("_Grid", model));
            }

            ReturnUrl = Url.Action(nameof(Index), "Documents", new { templateId });
            Title     = await Uow.DocumentTemplates.Where(t => t.Id == templateId && !t.IsDeleted).Select(t => t.Name).SingleOrDefaultAsync();

            return(View(model));
        }