Example #1
0
 private void InitRoleFilterViewModel(ref RoleFilterViewModel filterViewModel, bool isList)
 {
     if (isList)
     {
         InitBaseFilterViewModel(filterViewModel);
     }
 }
Example #2
0
        public ActionResult List(RoleFilterViewModel filterViewModel)
        {
            InitRoleFilterViewModel(ref filterViewModel, true);
            var                filter    = Mapper.Map <RoleFilter>(filterViewModel);
            RoleItems          list      = _roleRepository.GetRoleItems(UserContext.User.Id, UserContext.User.OrganizationId, filter);
            RoleItemsViewModel viewModel = Mapper.Map <RoleItemsViewModel>(list);

            viewModel.Filter = filterViewModel;
            InitListViewModel(viewModel, list);

            return(View(Mvc.View.Role.List, viewModel));
        }
Example #3
0
        public async Task <JsonResult> OnPostSearch(RoleFilterViewModel model)
        {
            try
            {
                model = await RolesService.Search(model);

                return(new JsonResult(new { Result = CommonConstants.JTableConstants.OK, Records = model.Items, TotalRecordCount = model.TotalCount }));
            }
            catch (Exception ex)
            {
                return(new JsonResult(new { Result = CommonConstants.JTableConstants.ERROR, ex.Message }));
            }
        }
Example #4
0
        public async Task <IActionResult> List(RoleFilterViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var result = await _roleService.GetListAsync(model.sortOrder, model.searchString, model.pageIndex, model.pageSize);

            if (!result.Succeeded)
            {
                return(BadRequest(result.Errors));
            }

            var countItems = await _roleService.CountAsync(model.searchString);

            return(Ok(result));
        }
Example #5
0
        public GenericCollectionViewModel <ListRolesLightViewModel> GetByFilter(RoleFilterViewModel model)
        {
            var lang = this._languageService.CurrentLanguage;
            ConditionFilter <Role, long> condition = new ConditionFilter <Role, 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.SetTimeToNow();

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

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

            if (string.IsNullOrEmpty(model.Code) == false)
            {
                queryableData = queryableData.Where(x => x.ParentKeyRole.Code == model.Code);
            }

            if (string.IsNullOrEmpty(model.Name) == false)
            {
                queryableData = queryableData.Where(x => x.Name != null && x.Name.Contains(model.Name));
            }

            if (model.IsActive.HasValue)
            {
                queryableData = queryableData.Where(x => x.ParentKeyRole.IsActive == model.IsActive.Value);
            }

            if (model.DateFrom.HasValue)
            {
                queryableData = queryableData.Where(x => x.ParentKeyRole.Date >= model.DateFrom.Value);
            }

            if (model.DateTo.HasValue)
            {
                queryableData = queryableData.Where(x => x.ParentKeyRole.Date <= model.DateTo.Value);
            }


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

            //foreach (var item in entityCollection)
            //{
            //	var ViewModel = dtoCollection.Find(x => x.Id == item.ParentKeyRoleId.Value);
            //	//ViewModel.Amount = item.Amount.ToString() + " " + item.Currency.ChildTranslatedCurrencys.FirstOrDefault(z => z.Language == lang).Name;
            //	//if (item.ParentKeyBankMovement.Bank != null)
            //	//{
            //	//	ViewModel.BankName = item.ParentKeyBankMovement.Bank.ChildTranslatedBanks.First(x => x.Language == lang).Name;
            //	//}
            //	//if (item.ParentKeyBankMovement.JournalType != null)
            //	//{
            //	//	ViewModel.JournalTypeName = item.ParentKeyBankMovement.JournalType.ChildTranslatedJournalTypes.First(x => x.Language == lang).Name; ;
            //	//}
            //}

            var total = dtoCollection.Count();

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

            return(result);
        }