Ejemplo n.º 1
0
        /// <summary>
        /// Get paged list of active or inactive user by Client id
        /// </summary>
        /// <param name="pagingInfo">pagingInfo object</param>
        /// <param name="ClientId">Id of the client</param>
        /// <param name="IsActive">TRUE OR False</param>
        /// <returns>Returns Active or Inactive user's paged list </returns>
        public static PageData <UserDTO> GetUserPagedListbyClientIdWithIsActive(PagingInfo pagingInfo, int ClientId, bool IsActive)
        {
            List <UserDTO>     UserDTOList = new List <UserDTO>();
            PageData <UserDTO> pageList    = new PageData <UserDTO>();

            if (pagingInfo == null)
            {
                PagingInfo PagingInfoCreated = new PagingInfo();
                PagingInfoCreated.Page         = 1;
                PagingInfoCreated.Reverse      = false;
                PagingInfoCreated.ItemsPerPage = 1;
                PagingInfoCreated.Search       = "";
                PagingInfoCreated.TotalItem    = 0;

                pagingInfo = PagingInfoCreated;
            }

            if (pagingInfo.SortBy == "")
            {
                pagingInfo.SortBy = "Name";
            }


            UserDTOList = GetUsersbyClientIdWithIsActive(ClientId, pagingInfo.Search, IsActive, pagingInfo);
            IQueryable <UserDTO> UserDTOPagedList = UserDTOList.AsQueryable();

            UnitOfWork uow   = new UnitOfWork();
            int        count = 0;

            if (pagingInfo.Search != "" && pagingInfo.Search != null)
            {
                bool IsDate = CommonService.IsDate(pagingInfo.Search);
                if (IsDate != true)
                {
                    //int LocationId = LocationService.GetByLocationName(pagingInfo.Search, ClientId);
                    string LocationIdString = LocationService.GetLocationIdarrayByName(pagingInfo.Search, ClientId);
                    count = 0;
                    count = uow.UserRepo.GetAll().Where(e => (e.Email.ToLower().Contains(pagingInfo.Search.ToLower()) || e.Name.ToLower().Contains(pagingInfo.Search.ToLower()) || (e.Mobile != null ? (e.Mobile.Contains(pagingInfo.Search)) : false) || (LocationIdString != null ? (e.LocationId.ToString().Split(',').Any(LocationId => LocationIdString.Contains(LocationId))) : false)) && e.IsActive == IsActive && e.ClientId == ClientId).OrderBy(e => e.Name).Count();
                }
                else
                {
                    //DateTime date = Convert.ToDateTime(pagingInfo.Search);
                    //count = 0;
                    //count = uow.UserRepo.GetAll().Where(e => e.CreatedDate >= date && e.CreatedDate < date.AddDays(1) || e.ScheduledDate >= date && e.ScheduledDate < date.AddDays(1)).OrderByDescending(e => e.CreatedDate).Count();
                }
            }
            else
            {
                count = uow.UserRepo.GetAll().Where(e => e.ClientId == ClientId && e.IsActive == IsActive).Count();
            }

            ////Sorting
            UserDTOPagedList = PagingService.Sorting <UserDTO>(UserDTOPagedList, pagingInfo.SortBy, pagingInfo.Reverse);

            // paging
            if (UserDTOPagedList.Count() > 0)
            {
                //var ContacDTOPerPage = PagingService.Paging<UserDTO>(UserDTOPagedList, pagingInfo.ItemsPerPage, pagingInfo.Page);
                pageList.Count = count;// UserDTOPagedList.Count();

                pageList.SuccessCount = GetActiveUserCount(ClientId);
                pageList.FailureCount = GetInactiveUserCount(ClientId);


                List <UserDTO> pagedClientUserDTOList = new List <UserDTO>();
                foreach (var item in UserDTOPagedList)
                {
                    pagedClientUserDTOList.Add(item);
                }
                pageList.Data = pagedClientUserDTOList;
            }
            else
            {
                pageList.Data = null;
            }



            return(pageList);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Get active or inactive Users by Client id
        /// </summary>
        /// <param name="ClientId">Id of the Client</param>
        /// <param name="search">search string</param>
        /// <param name="IsActive">TRUE OR FALSE</param>
        /// <param name="pagingInfo">pagingInfo object</param>
        /// <returns> Returns Active or Inactive user list </returns>
        public static List <UserDTO> GetUsersbyClientIdWithIsActive(int ClientId, string search, bool IsActive, PagingInfo pagingInfo)
        {
            List <UserDTO> UserDTOList = new List <UserDTO>();

            try
            {
                UnitOfWork uow = new UnitOfWork();

                int skip = (pagingInfo.Page - 1) * pagingInfo.ItemsPerPage;
                int take = pagingInfo.ItemsPerPage;

                IQueryable <User> User = uow.UserRepo.GetAll().Where(e => e.ClientId == ClientId && e.IsActive == IsActive).OrderBy(e => e.Name).AsQueryable();// .ToList().Skip(skip).Take(take);
                User = PagingService.Sorting <User>(User, pagingInfo.SortBy, pagingInfo.Reverse);
                User = User.Skip(skip).Take(take);


                if (User != null)
                {
                    foreach (var user in User)
                    {
                        UserDTO UserDTO = new UserDTO();
                        UserDTO = Transform.UserToDTO(user);
                        LocationDTO LocationDTO = new LocationDTO();
                        UserDTO.Location = LocationService.GetById(UserDTO.LocationId).Name;
                        UserDTOList.Add(UserDTO);
                    }

                    if (search != "" && search != null)
                    {
                        //int LocationId = LocationService.GetByLocationName(search, ClientId);
                        string LocationIdString = LocationService.GetLocationIdarrayByName(search, ClientId);

                        bool IsDate = CommonService.IsDate(search);
                        if (IsDate != true)
                        {
                            // string search
                            List <UserDTO>    UserDTOListSearch = new List <UserDTO>();
                            IQueryable <User> UserSearch        = uow.UserRepo.GetAll().Where(e => (e.Email.ToLower().Contains(search.ToLower()) || e.Name.ToLower().Contains(search.ToLower()) || e.FirstName.ToLower().Contains(search.ToLower()) || e.LastName.ToLower().Contains(search.ToLower()) || (e.Mobile != null ? (e.Mobile.Contains(search)) : false) || (LocationIdString != null ? (e.LocationId.ToString().Split(',').Any(LocationId => LocationIdString.Contains(LocationId.ToString()))) : false)) && e.IsActive == IsActive && e.ClientId == ClientId).AsQueryable();//.OrderBy(e => e.Name).ToList().Skip(skip).Take(take); //(e.Location != null ? (e.Location.ToLower().Contains(search.ToLower())) : false)
                            UserSearch = PagingService.Sorting <User>(UserSearch, pagingInfo.SortBy, pagingInfo.Reverse);
                            UserSearch = UserSearch.Skip(skip).Take(take);

                            foreach (var user in UserSearch)
                            {
                                UserDTO UserDTO = new UserDTO();
                                UserDTO = Transform.UserToDTO(user);
                                LocationDTO LocationDTO = new LocationDTO();
                                UserDTO.Location = LocationService.GetById(UserDTO.LocationId).Name;
                                UserDTOListSearch.Add(UserDTO);
                            }
                            return(UserDTOListSearch);
                        }
                        else
                        {
                        }
                    }
                    ////else
                    ////{
                    ////    ////foreach (var item in User)
                    ////    ////{
                    ////    ////    //UserDTO UserDTO = new UserDTO();
                    ////    ////    UserDTOList.Add(Transform.UserToDTO(item));
                    ////    ////}
                    ////}
                }

                return(UserDTOList);
            }
            catch (Exception)
            {
                throw;
            }
        }