public IPaging <RestrictedAccessTimeDto> Get(string searchTerm, string sortItem, string sortOrder
                                                     , PagingQueryString pagingQueryString)
        {
            IPaging <RestrictedAccessTimeDto> model = new RestrictedAccessTimeDtoPagingList();

            var query = //!string.IsNullOrEmpty(searchTerm)
                        //? _restrictedAccessTimeRepository.Get(q => q.Title.Contains(searchTerm.ToLower()))
                        //:
                        _restrictedAccessTimeRepository.Get();
            //total number of items
            int queryCount = query.Count();

            switch (sortItem)
            {
            case "date":
                query = sortOrder == "asc" ? query.OrderBy(o => o.Date)
                        : query.OrderByDescending(o => o.Date);
                break;

            case "from_time":
                query = sortOrder == "asc" ? query.OrderBy(o => o.FromTime)
                        : query.OrderByDescending(o => o.FromTime);
                break;

            case "to_time":
                query = sortOrder == "asc" ? query.OrderBy(o => o.ToTime)
                        : query.OrderByDescending(o => o.ToTime);
                break;

            default:
                query = query.OrderByDescending(o => o.Id);
                break;
            }

            List <RestrictedAccessTime> queryResult;

            if (pagingQueryString != null) //with paging
            {
                var pageSetup = new PagingSetup(pagingQueryString.Page, pagingQueryString.PageSize);
                queryResult = query.Skip(pageSetup.Offset).Take(pageSetup.Next).ToList();
                //paging controls
                var controls = pageSetup.GetPagingControls(queryCount, PagingStrategy.ReturnNull);
                if (controls != null)
                {
                    model.PagesCount = controls.PagesCount;
                    model.NextPage   = controls.NextPage;
                    model.PrevPage   = controls.PrevPage;
                }
            }
            else //without paging
            {
                queryResult = query.ToList();
            }
            model.PagingList = Mapper.Map <List <RestrictedAccessTimeDto> >(queryResult);

            return(model);
        }
        public async Task <IPaging <MessageDtoForPaging> > Get(MessageType messageType
                                                               , string receiverUsername, string searchTerm, string sortItem, string sortOrder
                                                               , PagingQueryString pagingQueryString)
        {
            IPaging <MessageDtoForPaging> model = new MessageDtoPagingList();

            var receiver = await _authRepository.FindUserByUsernameAsync(receiverUsername);

            if (receiver != null)
            {
                var query = !string.IsNullOrEmpty(searchTerm)
                ? _messageRepository.Get(q => q.MessageType == messageType && q.ReceiverId == receiver.Id &&
                                         q.Title.Contains(searchTerm.ToLower()), includeProperties: "Sender,Receiver")
                : _messageRepository.Get(q => q.MessageType == messageType && q.ReceiverId == receiver.Id
                                         , includeProperties: "Sender,Receiver");
                //total number of items
                int queryCount = query.Count();
                switch (sortItem)
                {
                case "title":
                    query = sortOrder == "asc" ? query.OrderBy(o => o.Title)
                            : query.OrderByDescending(o => o.Title);
                    break;

                case "date":
                    query = sortOrder == "asc" ? query.OrderBy(o => o.Date)
                            : query.OrderByDescending(o => o.Date);
                    break;

                default:
                    query = query.OrderByDescending(o => o.Id);
                    break;
                }

                List <Message> queryResult;
                if (pagingQueryString != null) //with paging
                {
                    var pageSetup = new PagingSetup(pagingQueryString.Page, pagingQueryString.PageSize);
                    queryResult = query.Skip(pageSetup.Offset).Take(pageSetup.Next).ToList();
                    //paging controls
                    var controls = pageSetup.GetPagingControls(queryCount, PagingStrategy.ReturnNull);
                    if (controls != null)
                    {
                        model.PagesCount = controls.PagesCount;
                        model.NextPage   = controls.NextPage;
                        model.PrevPage   = controls.PrevPage;
                    }
                }
                else //without paging
                {
                    queryResult = query.ToList();
                }
                model.PagingList = Mapper.Map <List <MessageDtoForPaging> >(queryResult);
            }

            return(model);
        }
Example #3
0
        public IPaging <UserLogDto> Get(string userId, string searchTerm, string sortItem
                                        , string sortOrder, PagingQueryString pagingQueryString)
        {
            IPaging <UserLogDto> model = new UserLogDtoPagingList();

            var query = !string.IsNullOrEmpty(searchTerm)
                ? _userLoggerRepository.Get(q => q.UserId == userId &&
                                            q.User.UserName.ToLower().Contains(searchTerm.ToLower())
                                            , includeProperties: "User")
                : _userLoggerRepository.Get(q => q.UserId == userId, includeProperties: "User");
            //total number of items
            int queryCount = query.Count();

            switch (sortItem)
            {
            case "username":
                query = sortOrder == "asc" ? query.OrderBy(o => o.User.UserName)
                        : query.OrderByDescending(o => o.User.UserName);
                break;

            case "date":
                query = sortOrder == "asc" ? query.OrderBy(o => o.Date)
                        : query.OrderByDescending(o => o.Date);
                break;

            default:
                query = query.OrderByDescending(o => o.Date);
                break;
            }

            List <UserLog> queryResult;

            if (pagingQueryString != null) //with paging
            {
                var pageSetup = new PagingSetup(pagingQueryString.Page, pagingQueryString.PageSize);
                queryResult = query.Skip(pageSetup.Offset).Take(pageSetup.Next).ToList();
                //paging controls
                var controls = pageSetup.GetPagingControls(queryCount, PagingStrategy.ReturnNull);
                if (controls != null)
                {
                    model.PagesCount = controls.PagesCount;
                    model.NextPage   = controls.NextPage;
                    model.PrevPage   = controls.PrevPage;
                }
            }
            else //without paging
            {
                queryResult = query.ToList();
            }
            model.PagingList = Mapper.Map <List <UserLogDto> >(queryResult);

            return(model);
        }
        public IPaging <ApprovalProcDtoForPaging> Get(string searchTerm, string sortItem
                                                      , string sortOrder, PagingQueryString pagingQueryString)
        {
            IPaging <ApprovalProcDtoForPaging> model = new ApprovalProcDtoPagingList();

            var query = !string.IsNullOrEmpty(searchTerm)
                ? _approvalProcRepository.Get(q => q.Title.Contains(searchTerm.ToLower())
                                              , includeProperties: "ParentProc")
                : _approvalProcRepository.Get(includeProperties: "ParentProc");

            //total number of items
            int queryCount = query.Count();

            switch (sortItem)
            {
            case "title":
                query = sortOrder == "asc" ? query.OrderBy(o => o.Title)
                        : query.OrderByDescending(o => o.Title);
                break;

            case "parent_title":
                query = sortOrder == "asc" ? query.OrderBy(o => o.ParentProc.Title)
                        : query.OrderByDescending(o => o.ParentProc.Title);
                break;

            default:
                query = query.OrderByDescending(o => o.Id);
                break;
            }

            List <ApprovalProc> queryResult;

            if (pagingQueryString != null) //with paging
            {
                var pageSetup = new PagingSetup(pagingQueryString.Page, pagingQueryString.PageSize);
                queryResult = query.Skip(pageSetup.Offset).Take(pageSetup.Next).ToList();
                //paging controls
                var controls = pageSetup.GetPagingControls(queryCount, PagingStrategy.ReturnNull);
                if (controls != null)
                {
                    model.PagesCount = controls.PagesCount;
                    model.NextPage   = controls.NextPage;
                    model.PrevPage   = controls.PrevPage;
                }
            }
            else //without paging
            {
                queryResult = query.ToList();
            }
            model.PagingList = Mapper.Map <List <ApprovalProcDtoForPaging> >(queryResult);

            return(model);
        }
        public IPaging <PersonnelDismissalEntranceDto> Get(string username, string fromDate, string toDate
                                                           , string searchTerm, string sortItem, string sortOrder, PagingQueryString pagingQueryString)
        {
            IPaging <PersonnelDismissalEntranceDto> model = new PersonnelDismissalEntranceDtoPagingList();

            IQueryable <PersonnelDismissalEntrance> query = null;

            var personnel = _personnelRepository.Get(q => q.Code == username).SingleOrDefault();

            if (personnel != null)
            {
                query = !string.IsNullOrEmpty(searchTerm)
                ? _personnelDismissalEntranceRepository
                        .Get(q => q.PersonnelId == personnel.Id &&
                             (q.Personnel.Name.Contains(searchTerm.ToLower()) ||
                              q.Personnel.LastName.Contains(searchTerm.ToLower()))
                             , includeProperties: "Personnel")
                : _personnelDismissalEntranceRepository.Get(q => q.PersonnelId == personnel.Id
                                                            , includeProperties: "Personnel");
            }
            else
            {
                query = !string.IsNullOrEmpty(searchTerm)
                ? _personnelDismissalEntranceRepository
                        .Get(q => q.Personnel.Name.Contains(searchTerm.ToLower()) ||
                             q.Personnel.LastName.Contains(searchTerm.ToLower())
                             , includeProperties: "Personnel")
                : _personnelDismissalEntranceRepository.Get(includeProperties: "Personnel");
            }

            if (!string.IsNullOrEmpty(fromDate))
            {
                var fromDateConverted = DateTime.Parse(fromDate);
                query = query.Where(q => q.StartDate >= fromDateConverted);
            }
            if (!string.IsNullOrEmpty(toDate))
            {
                var toDateConverted = DateTime.Parse(toDate);
                query = query.Where(q => q.StartDate <= toDateConverted);
            }

            //total number of items
            int queryCount = query.Count();

            switch (sortItem)
            {
            case "personnel_full_name":
                query = sortOrder == "asc" ? query.OrderBy(o => o.Personnel.Name + " " + o.Personnel.LastName)
                        : query.OrderByDescending(o => o.Personnel.Name + " " + o.Personnel.LastName);
                break;

            case "personnel_code":
                query = sortOrder == "asc" ? query.OrderBy(o => o.Personnel.Code)
                        : query.OrderByDescending(o => o.Personnel.LastName);
                break;

            case "enter":
                query = sortOrder == "asc" ? query.OrderBy(o => o.StartDate).ThenBy(o => o.Start)
                        : query.OrderByDescending(o => o.StartDate).ThenByDescending(o => o.Start);
                break;

            default:
                query = query.OrderByDescending(o => o.StartDate).ThenByDescending(o => o.Start);
                break;
            }

            List <PersonnelDismissalEntrance> queryResult;

            if (pagingQueryString != null) //with paging
            {
                var pageSetup = new PagingSetup(pagingQueryString.Page, pagingQueryString.PageSize);
                queryResult = query.Skip(pageSetup.Offset).Take(pageSetup.Next).ToList();
                //paging controls
                var controls = pageSetup.GetPagingControls(queryCount, PagingStrategy.ReturnNull);
                if (controls != null)
                {
                    model.PagesCount = controls.PagesCount;
                    model.NextPage   = controls.NextPage;
                    model.PrevPage   = controls.PrevPage;
                }
            }
            else //without paging
            {
                queryResult = query.ToList();
            }
            model.PagingList = Mapper.Map <List <PersonnelDismissalEntranceDto> >(queryResult);

            return(model);
        }
Example #6
0
        public IPaging <PersonnelShiftReplacementDtoForPaging> Get(string username
                                                                   , string searchTerm, string sortItem, string sortOrder, PagingQueryString pagingQueryString)
        {
            IPaging <PersonnelShiftReplacementDtoForPaging> model = new PersonnelShiftReplacementDtoPagingList();

            IQueryable <PersonnelShiftReplacement> query = null;

            var personnel = _personnelRepository.Get(q => q.Code == username).SingleOrDefault();

            if (personnel != null)
            {
                query = !string.IsNullOrEmpty(searchTerm)
                ? _personnelShiftReplacementRepository.Get(q => q.PersonnelId == personnel.Id &&
                                                           (q.Personnel.Name.Contains(searchTerm.ToLower()) ||
                                                            q.Personnel.LastName.Contains(searchTerm.ToLower()) ||
                                                            q.ReplacedPersonnel.Name.Contains(searchTerm.ToLower()) ||
                                                            q.ReplacedPersonnel.LastName.Contains(searchTerm.ToLower()) ||
                                                            q.WorkingHour.Title.Contains(searchTerm.ToLower()) ||
                                                            q.ReplacedWorkingHour.Title.Contains(searchTerm.ToLower()))
                                                           , includeProperties: "Personnel,ReplacedPersonnel,WorkingHour,ReplacedWorkingHour")
                : _personnelShiftReplacementRepository
                        .Get(q => q.PersonnelId == personnel.Id
                             , includeProperties: "Personnel,ReplacedPersonnel,WorkingHour,ReplacedWorkingHour");
            }
            else
            {
                query = !string.IsNullOrEmpty(searchTerm)
                ? _personnelShiftReplacementRepository.Get(q => q.Personnel.Name.Contains(searchTerm.ToLower()) ||
                                                           q.Personnel.LastName.Contains(searchTerm.ToLower()) ||
                                                           q.ReplacedPersonnel.Name.Contains(searchTerm.ToLower()) ||
                                                           q.ReplacedPersonnel.LastName.Contains(searchTerm.ToLower()) ||
                                                           q.WorkingHour.Title.Contains(searchTerm.ToLower()) ||
                                                           q.ReplacedWorkingHour.Title.Contains(searchTerm.ToLower())
                                                           , includeProperties: "Personnel,ReplacedPersonnel,WorkingHour,ReplacedWorkingHour")
                : _personnelShiftReplacementRepository
                        .Get(includeProperties: "Personnel,ReplacedPersonnel,WorkingHour,ReplacedWorkingHour");
            }

            //total number of items
            int queryCount = query.Count();

            switch (sortItem)
            {
            case "personnel_name":
                query = sortOrder == "asc" ? query.OrderBy(o => o.Personnel.Name)
                        : query.OrderByDescending(o => o.Personnel.Name);
                break;

            case "personnel_last_name":
                query = sortOrder == "asc" ? query.OrderBy(o => o.Personnel.LastName)
                        : query.OrderByDescending(o => o.Personnel.LastName);
                break;

            case "working_hour_title":
                query = sortOrder == "asc" ? query.OrderBy(o => o.WorkingHour.Title)
                        : query.OrderByDescending(o => o.WorkingHour.Title);
                break;

            default:
                query = query.OrderByDescending(o => o.Id);
                break;
            }

            List <PersonnelShiftReplacement> queryResult;

            if (pagingQueryString != null) //with paging
            {
                var pageSetup = new PagingSetup(pagingQueryString.Page, pagingQueryString.PageSize);
                queryResult = query.Skip(pageSetup.Offset).Take(pageSetup.Next).ToList();
                //paging controls
                var controls = pageSetup.GetPagingControls(queryCount, PagingStrategy.ReturnNull);
                if (controls != null)
                {
                    model.PagesCount = controls.PagesCount;
                    model.NextPage   = controls.NextPage;
                    model.PrevPage   = controls.PrevPage;
                }
            }
            else //without paging
            {
                queryResult = query.ToList();
            }
            model.PagingList = Mapper.Map <List <PersonnelShiftReplacementDtoForPaging> >
                                   (queryResult);


            return(model);
        }
Example #7
0
        public IPaging <WorkingHourDtoForPaging> Get(int?shiftId, string searchTerm
                                                     , string sortItem, string sortOrder, PagingQueryString pagingQueryString)
        {
            IPaging <WorkingHourDtoForPaging> model = new WorkingHourDtoPagingList();

            IQueryable <WorkingHour> query = null;

            if (shiftId.HasValue)
            {
                query = !string.IsNullOrEmpty(searchTerm)
                ? _workingHourRepository.Get(q => q.ShiftId == shiftId.Value &&
                                             q.Title.Contains(searchTerm.ToLower())
                                             , includeProperties: "Shift")
                : _workingHourRepository.Get(q => q.ShiftId == shiftId.Value
                                             , includeProperties: "Shift");
            }
            else
            {
                query = !string.IsNullOrEmpty(searchTerm)
                ? _workingHourRepository.Get(q => q.Title.Contains(searchTerm.ToLower())
                                             , includeProperties: "Shift")
                : _workingHourRepository.Get(includeProperties: "Shift");
            }


            //total number of items
            int queryCount = query.Count();

            switch (sortItem)
            {
            case "title":
                query = sortOrder == "asc" ? query.OrderBy(o => o.Title)
                        : query.OrderByDescending(o => o.Title);
                break;

            case "shift_title":
                query = sortOrder == "asc" ? query.OrderBy(o => o.Shift.Title)
                        : query.OrderByDescending(o => o.Shift.Title);
                break;

            default:
                query = query.OrderByDescending(o => o.Id);
                break;
            }

            List <WorkingHour> queryResult;

            if (pagingQueryString != null) //with paging
            {
                var pageSetup = new PagingSetup(pagingQueryString.Page, pagingQueryString.PageSize);
                queryResult = query.Skip(pageSetup.Offset).Take(pageSetup.Next).ToList();
                //paging controls
                var controls = pageSetup.GetPagingControls(queryCount, PagingStrategy.ReturnNull);
                if (controls != null)
                {
                    model.PagesCount = controls.PagesCount;
                    model.NextPage   = controls.NextPage;
                    model.PrevPage   = controls.PrevPage;
                }
            }
            else //without paging
            {
                queryResult = query.ToList();
            }
            model.PagingList = Mapper.Map <List <WorkingHourDtoForPaging> >(queryResult);

            return(model);
        }