Beispiel #1
0
        public async Task <PagedList <UserDto> > GetOnlineFriends(Guid userId, PaginationParams paginationParams)
        {
            List <Guid> onlineUsersIds = GetOnlineUsers();
            List <Guid> userFriendsIds = _friendsRelationService.GetUserFriendsId(userId);

            List <Guid>      onlineFriendsIds   = onlineUsersIds.Intersect(userFriendsIds).ToList();
            PagedList <Guid> onlineFriendsPages = PagedList <Guid> .Create(onlineFriendsIds,
                                                                           paginationParams.PageNumber,
                                                                           paginationParams.PageSize,
                                                                           (paginationParams.PageNumber - 1) *paginationParams.PageSize + paginationParams.Skip);

            List <UserDto> onlineFriendsFromApi = await _userService.GetUsersAsync(onlineFriendsPages);

            return(PagedList <UserDto> .CreateNewWithSameParams(onlineFriendsPages, onlineFriendsFromApi));
        }
        public ListaPaginada <UsuariosModel> Get([FromQuery] PaginationParams model)
        {
            var usuarios = RestornaUsuariosList();

            if (!string.IsNullOrEmpty(model.buscaTermo))
            {
                usuarios = usuarios.Where(x => x.Nome.Contains(model.buscaTermo) ||
                                          x.Cpf.Contains(model.buscaTermo) ||
                                          x.Email.Contains(model.buscaTermo)
                                          ).ToList();
            }
            var listaPaginada = new ListaPaginada <UsuariosModel>(model.PageNumber, model.PageSize);

            return(listaPaginada.Carregar(usuarios));
        }
Beispiel #3
0
        public async Task <PagedList <AuditTypeDto> > Search(PaginationParams param, object text)
        {
            var lists = _repoAuditType.FindAll().ProjectTo <AuditTypeDto>(_configMapper)
                        .Where(
                x => x.Audit_Type_ID.Contains(text.ToString()) ||
                x.Brand.Contains(text.ToString()) ||
                x.Audit_Type1.Contains(text.ToString()) ||
                x.Audit_Type2.Contains(text.ToString()) ||
                x.Audit_Type2_Name.Contains(text.ToString()) ||
                x.Updated_By.Contains(text.ToString())
                )
                        .OrderByDescending(x => x.Updated_Time);

            return(await PagedList <AuditTypeDto> .CreateAsync(lists, param.PageNumber, param.PageSize));
        }
Beispiel #4
0
        public async Task <IEnumerable <DistrictDto> > GetDistrictsAsync(
            string countryTag,
            string provinceName,
            PaginationParams paginationParams)
        {
            var query = from country in _locationDbContext.Countries
                        join province in _locationDbContext.Province on country.Id equals province.CountryId
                        join district in _locationDbContext.Districts on province.ProvinceId equals district.ProvinceId
                        where country.CountryTag == countryTag && province.ProvinceName == provinceName
                        select new DistrictDto {
                DistrictId = district.DistrictId, DistrictName = district.DistrictName
            };

            return(await query.ToListAsync());
        }
Beispiel #5
0
        public async Task <IEnumerable <ProvinceDto> > GetProvincesAsync(
            string countyTag,
            PaginationParams paginationParams)
        {
            var query = from country in _locationDbContext.Countries
                        join province in _locationDbContext.Province on country.Id equals province.CountryId
                        where country.CountryTag == countyTag
                        select new ProvinceDto()
            {
                ProvinceId   = province.ProvinceId,
                ProvinceName = province.ProvinceName
            };

            return(await query.ToListAsync());
        }
Beispiel #6
0
 public async Task<PagedList<Transaction_Main_Dto>> FilterMissingPrint(PaginationParams param, FilterMissingParam filterParam)
 {
     var lists = _repoTransactionMain.GetAll()
         .ProjectTo<Transaction_Main_Dto>(_configMapper)
         .Where(x => x.Missing_No != null && x.Transac_Type.Trim() == "I");
     if (filterParam.MO_No != null && filterParam.MO_No != "")
     {
         lists = lists.Where(x => x.MO_No.Trim() == filterParam.MO_No.Trim());
     }
     if (filterParam.Material_ID != null && filterParam.Material_ID != "")
     {
         lists = lists.Where(x => x.Material_ID.Trim() == filterParam.Material_ID.Trim());
     }
     lists = lists.Distinct().OrderByDescending(x => x.Updated_Time);
     return await PagedList<Transaction_Main_Dto>.CreateAsync(lists, param.PageNumber, param.PageSize);
 }
Beispiel #7
0
        public async Task <PagedList <Product_Dto> > GetProducts(PaginationParams param)
        {
            var products  = _repoProduct.FindAll();
            var categorys = _repoCategory.FindAll();
            var data      = (from a in products join b in categorys
                             on a.CatID equals b.ID select new Product_Dto()
            {
                ID = a.ID,
                Name = a.Name,
                category = b,
                Update_By = a.Updated_By,
                Update_Time = a.Update_Time
            }).OrderByDescending(x => x.Update_Time);

            return(await PagedList <Product_Dto> .CreateAsync(data, param.PageNumber, param.PageSize));;
        }
Beispiel #8
0
        public async Task <PageListUtility <Article_Dto> > GetArticleWithPaginations(PaginationParams param, string text)
        {
            var data = _articleRepository.FindAll().ProjectTo <Article_Dto>(_configuration).OrderByDescending(x => x.Article_Cate_ID).ThenBy(x => x.Article_ID);

            if (!string.IsNullOrEmpty(text))
            {
                data = data.Where(x => x.Article_ID.ToString().ToLower().Contains(text.ToLower()) ||
                                  x.Article_Name.ToLower().Contains(text.ToLower()) ||
                                  x.Update_By.ToLower().Contains(text.ToLower()) ||
                                  x.Content.ToLower().Contains(text.ToLower()) ||
                                  x.Alias.ToLower().Contains(text.ToLower()) ||
                                  x.Article_Cate_ID.ToLower().Contains(text.ToLower())
                                  ).OrderByDescending(x => x.Article_Cate_ID).ThenBy(x => x.Article_ID);
            }
            return(await PageListUtility <Article_Dto> .PageListAsync(data, param.PageNumber, param.PageSize));
        }
Beispiel #9
0
        private static bool ValidateOrderBy(this PaginationParams paginationParams)
        {
            if (paginationParams.OrderBy == null)
            {
                return(false);
            }

            //if does not contain any order by, return
            if (!paginationParams.OrderBy.Any())
            {
                return(false);
            }

            //check for null elements
            return(paginationParams.OrderBy.Any(c => !string.IsNullOrWhiteSpace(c.ColumnName.Trim())));
        }
Beispiel #10
0
        public static StringBuilder AddOrderByToSqlString(this StringBuilder sql, PaginationParams paginationParams)
        {
            //Return if no orderby present
            if (!paginationParams.ValidateOrderBy())
            {
                return(sql);
            }

            //Get the order by list
            var notNullElements = paginationParams.OrderBy.Where(c => !string.IsNullOrWhiteSpace(c.ColumnName.Trim())).Select(d => d.ToString());

            //Append new line with oder
            sql.AppendLine($"order by {string.Join(", ", notNullElements)}");

            return(sql);
        }
        public async Task <PagedList <UserDto> > GetUsersPagination(PaginationParams paginationParams)
        {
            var query = _context.Users
                        .Include(p => p.PhotoUsers)
                        .Include(p => p.Downloads)
                        .AsQueryable();

            if (!string.IsNullOrEmpty(paginationParams.Search))
            {
                query = query.Where(e => e.FullName.ToLower().Contains(paginationParams.Search));
            }

            return(await PagedList <UserDto> .CreateAsync(query.ProjectTo <UserDto>(_mapper
                                                                                    .ConfigurationProvider).AsNoTracking(),
                                                          paginationParams.PageNumber, paginationParams.PageSize));
        }
Beispiel #12
0
        public PagedList <NotificationDto> GetUserNotifications(Guid userId, PaginationParams paginationParams, string fromWhoId = null, int notificationType = 0, string eventId = null)
        {
            _logger.LogDebug("Trying to get user notifications: {userid}", userId);
            if (userId == Guid.Empty)
            {
                throw new ArgumentNullException(nameof(Guid));
            }
            try
            {
                var predicate = PredicateBuilder.New <Notification>();
                predicate = predicate.And(x => x.ToWhoId == userId);

                if (fromWhoId != null)
                {
                    Guid.TryParse(fromWhoId, out Guid gFromWhoId);

                    predicate = predicate.And(x => x.FromWho == gFromWhoId);
                }
                if (notificationType != 0)
                {
                    predicate = predicate.And(x => x.NotificationType == (NotificationType)notificationType);
                }
                if (eventId != null)
                {
                    Guid.TryParse(eventId, out Guid gEventId);

                    predicate = predicate.And(x => x.EventId == gEventId);
                }


                List <Notification> notificationsFromRepo = _notificationRepository
                                                            .Get(predicate)
                                                            .OrderByDescending(x => x.WhenAdded)
                                                            .ToList();
                List <NotificationDto> notificationsToReturn = _mapper.Map <List <NotificationDto> >(notificationsFromRepo);
                return(PagedList <NotificationDto> .Create(notificationsToReturn,
                                                           paginationParams.PageNumber,
                                                           paginationParams.PageSize,
                                                           (paginationParams.PageNumber - 1) *paginationParams.PageSize + paginationParams.Skip));
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "Error occured during getting the user notifications.");
                throw;
            }
        }
        public async Task <IActionResult> GetMessagesForUser(int userId, [FromQuery] PaginationParams paginationParams)
        {
            if (userId != Convert.ToInt32(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }

            paginationParams.UserId = userId;

            var messagesFromRepo = await _repo.GetMessagesForUser(paginationParams);

            var messages = _mapper.Map <List <MessageToReturnDTO> >(messagesFromRepo);

            Response.AddPagination(messagesFromRepo.CurrentPage, messagesFromRepo.PageSize, messagesFromRepo.TotalCount, messagesFromRepo.TotalPages);

            return(Ok(messages));
        }
Beispiel #14
0
        public async Task <PagedList <AuditType_D_Dto> > SearchByAuditType(PaginationParams param, string audit_Type_ID, string audit_Item_ID)
        {
            var lists = _repoauditTypeD.FindAll().ProjectTo <AuditType_D_Dto>(_configMapper);

            if (audit_Type_ID != "all")
            {
                if (audit_Item_ID != null)
                {
                    lists = lists.Where(x => x.Audit_Type_ID.Trim() == audit_Type_ID && x.Audit_Item_ID == audit_Item_ID);
                }
                else
                {
                    lists = lists.Where(x => x.Audit_Type_ID.Trim() == audit_Type_ID);
                }
            }
            return(await PagedList <AuditType_D_Dto> .CreateAsync(lists, param.PageNumber, param.PageSize));
        }
Beispiel #15
0
        /// <summary>
        /// List users
        /// </summary>
        /// <param name="pagination"></param>
        /// <returns>Paginated list with all users</returns>
        public async Task <PagedList <User> > ListAsync(PaginationParams pagination)
        {
            try
            {
                //Get paginated users from db
                List <User> paginatedUsers = await _userRepository.List(pagination);

                //Get total count of users in db
                int totalCount = await _userRepository.Table.CountAsync();

                return(new PagedList <User>(paginatedUsers, totalCount, pagination.CurrentPage, pagination.PageSize));
            }
            catch
            {
                throw;
            }
        }
        public async Task <PagedList <User> > GetUsers(PaginationParams paginationParams)
        {
            var users = _context.Users.OrderByDescending(b => b.LastActive).AsQueryable();

            users = users.Where(a => a.Id != paginationParams.UserId && a.Gender == paginationParams.Gender);

            if (paginationParams.minAge != 18 || paginationParams.maxAge != 99)
            {
                var minDob = DateTime.Today.AddYears(-paginationParams.maxAge - 1);
                var maxDob = DateTime.Today.AddYears(-paginationParams.minAge);

                users = users.Where(a => a.DateOfBirth >= minDob && a.DateOfBirth <= maxDob);
            }

            if (paginationParams.Likers)
            {
                var userLikers = await GetUserLikes(paginationParams.UserId, paginationParams.Likers);

                users = users.Where(a => userLikers.Contains(a.Id));
            }

            if (paginationParams.Likees)
            {
                var userLikees = await GetUserLikes(paginationParams.UserId, paginationParams.Likers);

                users = users.Where(a => userLikees.Contains(a.Id));
            }

            if (!string.IsNullOrEmpty(paginationParams.OrderBy))
            {
                switch (paginationParams.OrderBy)
                {
                case "created":
                    users = users.OrderByDescending(a => a.Created);
                    break;

                default:
                    users = users.OrderByDescending(a => a.LastActive);
                    break;
                }
            }


            return(await PagedList <User> .CreateAsync(users, paginationParams.PageNumber, paginationParams.PageSize));
        }
Beispiel #17
0
        public async Task <PagedList <SMEScoreRecordDto> > GetLisSMEScoreRecord(PaginationParams paginationParams, ScoreRecordParam sixsScoreRecordParam, bool isPaging = true)
        {
            var queryAuditRateM = _auditRateMRepository.FindAll().Where(x => x.Audit_Type1.Trim() == "SME2.0");
            var queryAuditRateD = _auditRateDRepository.FindAll();

            if (sixsScoreRecordParam.PDC != "")
            {
                queryAuditRateM = queryAuditRateM.Where(x => x.PDC.Trim() == sixsScoreRecordParam.PDC);
            }
            if (sixsScoreRecordParam.Building != "")
            {
                queryAuditRateM = queryAuditRateM.Where(x => x.Building.Trim() == sixsScoreRecordParam.Building);
            }
            if (sixsScoreRecordParam.Line != "")
            {
                queryAuditRateM = queryAuditRateM.Where(x => x.Line.Trim() == sixsScoreRecordParam.Line);
            }
            if (sixsScoreRecordParam.AuditType2 != "")
            {
                queryAuditRateM = queryAuditRateM.Where(x => x.Audit_Type2.Trim() == sixsScoreRecordParam.AuditType2);
            }
            if (sixsScoreRecordParam.FromDate != "" && sixsScoreRecordParam.ToDate != "")
            {
                DateTime d1 = Convert.ToDateTime(sixsScoreRecordParam.FromDate + " 00:00:00");
                DateTime d2 = Convert.ToDateTime(sixsScoreRecordParam.ToDate + " 23:59:59");
                queryAuditRateM = queryAuditRateM.Where(x => x.Record_Date >= d1 && x.Record_Date <= d2);
            }

            var data = queryAuditRateM.OrderByDescending(x => x.Updated_Time).Select(x => new SMEScoreRecordDto
            {
                RecordId   = x.Record_ID,
                AuditDate  = x.Record_Date,
                AuditType  = x.Audit_Type1,
                AuditType2 = x.Audit_Type2,
                LineId     = x.PDC + " + " + x.Building + " + " + x.Line,
                UpdateBy   = x.Updated_By,
                UpdateTime = x.Updated_Time,
                Rating0    = queryAuditRateD.Where(y => y.Record_ID == x.Record_ID).Sum(z => z.Rating_0),
                Rating1    = queryAuditRateD.Where(y => y.Record_ID == x.Record_ID).Sum(z => z.Rating_1),
                Rating2    = queryAuditRateD.Where(y => y.Record_ID == x.Record_ID).Sum(z => z.Rating_2),
                RatingNa   = queryAuditRateD.Where(y => y.Record_ID == x.Record_ID).Sum(z => z.Rate_NA) == null ? 0 : queryAuditRateD.Where(y => y.Record_ID == x.Record_ID).Sum(z => z.Rate_NA),
            });

            return(await PagedList <SMEScoreRecordDto> .CreateAsync(data, paginationParams.PageNumber, paginationParams.PageSize, isPaging));
        }
Beispiel #18
0
        public async Task <PagedList <AuditRecDto> > GetAllAuditRecViewModel(PaginationParams param)
        {
            var listAuditRecM   = _repoM.FindAll();
            var listAuditRecD   = _repoD.FindAll();
            var listAuditMes    = _repoMes.FindAll(x => x.Status == 1);
            var listAuditRecDto = listAuditRecD.Join(listAuditRecM, x => x.Record_ID, y => y.Record_ID, (x, y) => new { x, y })
                                  .Join(listAuditMes, z => z.y.Line, t => t.Line_ID_2, (z, t)
                                        => new AuditRecDto
            {
                Record_ID      = z.x.Record_ID,
                Record_Time    = z.y.Record_Time,
                After_Picture  = z.x.After_Picture,
                Audit_Item     = z.x.Audit_Item,
                Audit_Type_ID  = z.x.Audit_Type_ID,
                Audit_Type     = (z.x == null || z.x.Audit_Type_ID == "") ? "" : _repoAuditTypeM.FindById(z.x.Audit_Type_ID).Audit_Type1 + "-" + _repoAuditTypeM.FindById(z.x.Audit_Type_ID).Audit_Type2,
                Before_Picture = z.x.Before_Picture,
                Finished_Date  = z.x.Finished_Date,
                ERCS           = z.x.ERCS,
                Implement_Time = z.x.Implement_Time,
                Implement_User = z.x.Implement_User,
                Issue_EN       = z.x.Issue_EN,
                Issue_LL       = z.x.Issue_LL,
                Issue_ZW       = z.x.Issue_ZW,
                Building       = z.y.Building,
                PDC            = z.y.PDC,
                Line           = z.y.Line,
                Line_Name      = t.Line_ID_2_Name,
                ME_PIC         = z.x.ME_PIC,
                Model_Name     = z.y.Model_Name,
                Model_No       = z.y.Model_No,
                Chief          = z.y.Chief,
                Recorder       = z.y.Recorder,
                Attendees      = z.y.Attendees,
                PD_PIC         = z.x.PD_PIC,
                PD_Department  = z.x.PD_Department,
                PD_Building    = z.x.PD_Building,
                Remark         = z.x.Remark,
                Status         = z.x.Status,
                Item_no        = z.x.Item_no,
                Updated_By     = z.x.Updated_By,
                Updated_Time   = z.x.Updated_Time,
            }).OrderBy(x => x.Audit_Type_ID);

            return(await PagedList <AuditRecDto> .CreateAsync(listAuditRecDto, param.PageNumber, param.PageSize));
        }
Beispiel #19
0
        public async Task <PagedList <WMSB_Packing_List> > SearchViewModel(PaginationParams param, FilterPackingListParam filterParam)
        {
            var packingSearch = _repoPackingList.GetAll();

            if (filterParam.From_Date != null && filterParam.To_Date != null)
            {
                packingSearch = packingSearch.
                                Where(x => x.Receive_Date >= DateTime.Parse(filterParam.From_Date + " 00:00:00.000") &&
                                      x.Generated_QRCode.Trim() == "N" &&
                                      x.Receive_Date <= DateTime.Parse(filterParam.To_Date + " 23:59:59.000")
                                      );
            }
            if (filterParam.MO_No != null && filterParam.MO_No != string.Empty)
            {
                packingSearch = packingSearch.Where(x => x.MO_No.Trim() == filterParam.MO_No.Trim());
            }
            return(await PagedList <WMSB_Packing_List> .CreateAsync(packingSearch, param.PageNumber, param.PageSize));
        }
Beispiel #20
0
        public async Task <PagedList <Product_Dto> > Search(PaginationParams param, string filterParam)
        {
            var products  = _repoProduct.FindAll(x => x.ID.Trim().Contains(filterParam.Trim()));
            var categorys = _repoCategory.FindAll();
            var data      = (from a in products join b in categorys
                             on a.CatID equals b.ID select new Product_Dto()
            {
                ID = a.ID,
                Name = a.Name,
                CatID = a.CatID,
                CatName = b.Name_LL,
                CatName_ZW = b.Name_ZW,
                Update_By = a.Updated_By,
                Update_Time = a.Update_Time
            }).OrderByDescending(x => x.Update_Time);

            return(await PagedList <Product_Dto> .CreateAsync(data, param.PageNumber, param.PageSize));
        }
Beispiel #21
0
        public async Task <PagedList <Product_Dto> > Search(PaginationParams param, string filterParam)
        {
            var products  = _repoProduct.FindAll(x => x.ID.Trim().Contains(filterParam.Trim()));
            var categorys = _repoCategory.FindAll();
            var data      = products.Join(categorys, x => x.CatID, y => y.ID, (x, y) => new Product_Dto()
            {
                ID          = x.ID,
                Name        = x.Name,
                CatID       = x.CatID,
                CatName     = y.Name_LL,
                CatName_ZW  = y.Name_ZW,
                category    = y,
                Update_By   = x.Updated_By,
                Update_Time = x.Update_Time
            }).OrderByDescending(x => x.Update_Time);

            return(await PagedList <Product_Dto> .CreateAsync(data, param.PageNumber, param.PageSize));
        }
Beispiel #22
0
        public async Task <IActionResult> ExportExcelSMERecord([FromQuery] PaginationParams paginationParams, ScoreRecordParam scoreRecordParam)
        {
            var data = await _waterSpiderRecordService.GetLisWaterSpiderScoreRecord(paginationParams, scoreRecordParam);

            var path = Path.Combine(_webHostEnvironment.ContentRootPath, "Resource\\Template\\WaterSpider_Score_Record_Template.xlsx");
            WorkbookDesigner designer = new WorkbookDesigner();

            designer.Workbook = new Workbook(path);
            Worksheet ws = designer.Workbook.Worksheets[0];

            designer.SetDataSource("result", data);
            designer.Process();
            MemoryStream stream = new MemoryStream();

            designer.Workbook.Save(stream, SaveFormat.Xlsx);
            byte[] result = stream.ToArray();
            return(File(result, "application/xlsx", "WaterSpider_Score_Record" + DateTime.Now.ToString("dd_MM_yyyy_HH_mm_ss") + ".xlsx"));
        }
Beispiel #23
0
        public async Task <IActionResult> GetUsers([FromQuery] PaginationParams userParams)
        {
            var currentUserId = int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value);
            var userFromRepo  = await _repo.GetUser(currentUserId, true);

            userParams.UserId = currentUserId;
            if (string.IsNullOrEmpty(userParams.Gender))
            {
                userParams.Gender = userFromRepo.Gender == "male" ? "female" : "male";
            }

            var users = await _repo.GetUsers(userParams);

            var usersToReturn = _mapper.Map <IEnumerable <UserForListDTO> >(users);

            Response.AddPagination(users.CurrentPage, users.PageSize, users.TotalPages, users.TotalCount);
            return(Ok(usersToReturn));
        }
Beispiel #24
0
        public async Task <ActionResult> GetUsersWithRoles([FromQuery] PaginationParams paginationParams)
        {
            var users = _userManager.Users
                        .Include(r => r.UserRoles)
                        .ThenInclude(r => r.Role)
                        .OrderBy(u => u.UserName)
                        .Select(u => new UserRolesDto
            {
                Id       = u.Id,
                Username = u.UserName,
                Roles    = u.UserRoles.Select(r => r.Role.Name).ToList()
            });
            var usersRoles = await PagedList <UserRolesDto> .CreateAsync(users, paginationParams.PageNumber,
                                                                         paginationParams.PageSize);

            Response.AddPaginationHeader(usersRoles.CurrentPage, usersRoles.PageSize, usersRoles.TotalCount, usersRoles.TotalPages);
            return(Ok(usersRoles));
        }
Beispiel #25
0
        public async Task <IActionResult> GetFilteredCars([FromQuery] PaginationParams carsParam)
        {
            //if (!User.Identity.IsAuthenticated)
            //    return Unauthorized();
            //if (!User.IsInRole("Admin"))
            //    return Unauthorized();

            var model     = new List <CarForListDto>();
            var carsAsync = await _carService.GetFilteredCarsAsync(carsParam);

            var cars = carsAsync.ToList();

            if (cars == null || cars.Count() <= 0)
            {
                return(BadRequest());
            }

            for (int i = 0; i < cars.Count(); i++)
            {
                var carUpload = await _carUploadService.GetCarUploadByCarIdAsync(cars[i].Id);

                model.Add(new CarForListDto
                {
                    Id              = cars[i].Id,
                    CarNumber       = cars[i].CarNumber,
                    BrandName       = await _brandService.GetBrandNameAsync((int)cars[i].BrandId),
                    ModelYear       = cars[i].ModelYear,
                    NumberOfDoors   = cars[i].NumberOfDoors,
                    CarCapacity     = cars[i].CarCapacity,
                    CarColor        = cars[i].CarColor,
                    PriceForDay     = cars[i].PriceForDay,
                    Description     = cars[i].Description,
                    ModelName       = await _modelService.GetModelNameAsync((int)cars[i].ModelId),
                    FuelType        = await _fuelTypeService.GetFuelTypeNameAsync((int)cars[i].FuelTypeId),
                    TransmisionType = cars[i].TransmisionType.Name,
                    CarLocation     = await _locationService.GetLocationAsync((int)cars[i].CarLocationId),
                    Path            = carUpload != null ? Url.Content(carUpload.Path) : ""
                });
            }

            Response.AddPagination(carsAsync.CurrentPage, carsAsync.PageSize, carsAsync.TotalCount, carsAsync.TotalPages);

            return(Ok(model));
        }
        public async Task <IActionResult> GetFilteredBookings([FromQuery] PaginationParams paginationParams)
        {
            var model         = new List <BookingForListDto>();
            var bookingsAsync = await _bookingService.GetFilteredBookingsAsync(paginationParams);

            var bookings = bookingsAsync.ToList();

            if (bookings == null || bookings.Count <= 0)
            {
                return(BadRequest("Booking not found"));
            }

            for (int i = 0; i < bookings.Count(); i++)
            {
                model.Add(new BookingForListDto
                {
                    Id             = bookings[i].Id,
                    PickUpLocation = await _locationService.GetLocationAsync((int)bookings[i].PreBooking.PickLocationId),
                    ReturnLocation = await _locationService.GetLocationAsync((int)bookings[i].PreBooking.ReturnLocationId),
                    PickUpDate     = (DateTime)bookings[i].PreBooking.PickDate,
                    ReturnDate     = (DateTime)bookings[i].PreBooking.ReturnDate,

                    Car = new CarForListDto
                    {
                        Id        = bookings[i].Car.Id,
                        CarNumber = bookings[i].Car.CarNumber
                    },

                    User = new UserDto
                    {
                        Id          = bookings[i].User.Id,
                        FirstName   = bookings[i].User.FirstName,
                        LastName    = bookings[i].User.LastName,
                        Email       = bookings[i].User.Email,
                        PhoneNumber = bookings[i].User.PhoneNumber
                    }
                });
            }

            Response.AddPagination(bookingsAsync.CurrentPage, bookingsAsync.PageSize, bookingsAsync.TotalCount, bookingsAsync.TotalPages);


            return(Ok(model));
        }
Beispiel #27
0
        public async Task <PagedList <Circle> > GetCircles(PaginationParams paginationParams, CircleSearchParameter searchOptions)
        {
            var query = _context.Circles.Include(c => c.Category)
                        .Include(c => c.City)
                        .Include(c => c.MainPhoto)
                        //  .Include(c => c.CircleMemberList)
                        .AsQueryable();

            if (searchOptions.CityId != null && searchOptions.CityId > 0)
            {
                query = query.Where(c => c.CityId == null || c.CityId == searchOptions.CityId);
            }
            if (searchOptions.CategoryId != null && searchOptions.CategoryId > 0)
            {
                query = query.Where(c => c.Category.Id == searchOptions.CategoryId);
            }

            return(await PagedList <Circle> .CreateAsync(query, paginationParams.PageNumber, paginationParams.PageSize));
        }
Beispiel #28
0
        public async Task <IEnumerable <MessageDto> > GetMessages(int chatId, PaginationParams parameters)
        {
            var messages = await _unitOfWork.Repository <Message>().GetAll()
                           .Include(m => m.Chat)
                           .Include(m => m.Poster)
                           .ThenInclude(u => u.Details)
                           .Where(m => m.ChatId == chatId)
                           .OrderByDescending(m => m.Timestamp)
                           .Skip(parameters.Skip)
                           .Take(parameters.Take)
                           .ToListAsync();

            var mapper = new MapperConfiguration(cfg => cfg.CreateMap <Message, MessageDto>()
                                                 .ForMember(m => m.PosterName, opt => opt.MapFrom(m => m.Poster.Details.FirstName))).CreateMapper();

            var messagesDto = mapper.Map <IEnumerable <Message>, IEnumerable <MessageDto> >(messages);

            return(messagesDto);
        }
Beispiel #29
0
        public async Task <IActionResult> PagedHomePosts([FromQuery] PaginationParams input)
        {
            var token = GetToken();

            if (!String.IsNullOrEmpty(token))
            {
                var userId = LoginHelper.GetClaim(token, "UserId");
                input.EntityId = Guid.Parse(userId);
            }

            if (input.EntityId == null)
            {
                return(Unauthorized());
            }

            var post = await _postAppService.PagedHomePosts(input);

            return(Ok(post));
        }
Beispiel #30
0
        public async Task <PagedResultDto <GetAllPostDto> > DailyTrends(PaginationParams input)
        {
            var result = await _postRepository.GetAll().Where(x => x.IsDeleted == false)
                         .Include(x => x.User)
                         .Include(x => x.Community).Select(
                x => new GetAllPostDto
            {
                Id               = x.Id,
                Slug             = x.Slug,
                Content          = x.Content,
                LinkUrl          = x.LinkUrl,
                UserPostVote     = x.Votes.FirstOrDefault(l => l.UserId == input.EntityId && l.IsDeleted == false && l.PostId == x.Id),
                VoteCount        = x.Votes.Count(v => v.IsDeleted == false && v.Value == 1) - x.Votes.Count(v => v.IsDeleted == false && v.Value == -1),
                MediaContentPath = x.MediaContentPath == null ? null : BlobService.BlobService.GetImageUrl(x.MediaContentPath),
                ContentType      = x.ContentType,
                CreatedDateTime  = x.CreatedDate,
                PageNumber       = input.PageNumber,
                Comments         = x.Comments.Where(f => f.IsDeleted == false).Select(f => new Comment
                {
                    ReplyCount = f.Replies.Count(v => v.IsDeleted == false)
                }).ToList(),
                Community = new PostCommunityDto
                {
                    Slug     = x.Community.Slug,
                    Name     = x.Community.Name,
                    LogoPath = x.Community.LogoPath == null ? null : BlobService.BlobService.GetImageUrl(x.Community.LogoPath)
                },
                User = new PostUserDto
                {
                    UserName         = x.User.Username,
                    ProfileImagePath = BlobService.BlobService.GetImageUrl(x.User.ProfileImagePath)
                }
            }).OrderByDescending(x => x.CreatedDateTime).ThenByDescending(x => x.VoteCount).
                         Skip((input.PageNumber - 1) * input.PageSize).Take(input.PageSize).ToListAsync();

            var hasNext = await _postRepository.GetAll().Where(x => x.IsDeleted == false).Skip((input.PageNumber) * input.PageSize).AnyAsync();

            var bb = new PagedResultDto <GetAllPostDto> {
                Results = result, HasNext = hasNext
            };

            return(bb);
        }