public async Task <List <ObjectDto> > GetObjects(PagingArguments arguments) { var(login, user) = await _userDataManager.AddCurrentUserIfNeeded(); var userLocation = login.LoginLocation; var filteredObjects = _objectRepo.Table.Where(_queryHelper.IsValidObject) .Where(_queryHelper.ValidForFreeAndLendibg); var objects = from o in filteredObjects let distance = o.OwnerLogin.User.Logins.OrderByDescending(l => l.LoggedAt).FirstOrDefault().LoginLocation.Distance(userLocation) orderby o.OfferedObjectId select new ObjectDto { Id = o.OfferedObjectId, CountOfImpressions = o.Impressions.Count, CountOfViews = 0, Description = o.Description, Name = o.Name, Rating = null, OwnerId = o.OwnerLogin.UserId.ToString(), Photos = o.Photos.Select(op => _photoConstructor.Construct(op)).ToList(), Tags = o.Tags.Select(ot => ot.Tag.Name).ToList(), Type = o.CurrentTransactionType, }; var objectsList = await objects.SkipTakeAsync(arguments); await _impressionManager.AddImpressions(objectsList); return(objectsList); }
public async Task <List <ObjectDtoV1_1> > GetObjects(OrderByType orderBy, PagingArguments pagingArgs) { var(login, user) = await _userDataManager.AddCurrentUserIfNeeded(); var userId = user.UserId; var userLocation = login.LoginLocation; var selectExp = _queryHelper.ObjectDtoSelectExpV1_1(_photoUrlConstructor, userId.ToString(), userLocation); var filteredObjects = _objectRepo.Table.Where(_queryHelper.IsValidObject) .Where(_queryHelper.ValidForFreeAndLendibg) .Where(_queryHelper.DistanceFilter(userLocation, IncludeObjectLessThan)); var DbF = Microsoft.EntityFrameworkCore.EF.Functions; var x = (from o in _objectRepo.Table select new { dd = o.Views.Count / (double)(DbF.DateDiffSecond(o.PublishedAt, DateTime.UtcNow) + 1), c = o.Views.Count, diff = (DbF.DateDiffSecond(o.PublishedAt, DateTime.UtcNow) + 1), id = o.OfferedObjectId }) .ToList(); var orderResult = _queryHelper.OrderObject(filteredObjects, userLocation, orderBy); var objectList = await orderResult .Select(selectExp) .SkipTakeAsync(pagingArgs); return(objectList); }
public async Task <IActionResult> GetForObject(int objectId, PagingArguments pagingArguments = null) { if (pagingArguments is null) { var result = await _commentsGetter.GetCommentsForObject(objectId); return(Ok(result)); } else { var result = await _commentsGetter.GetCommentsForObject(objectId, pagingArguments); return(Ok(result)); } }
protected async override Task ExecuteAsync() { var organizationIdentifier = GetOrganizationIdentifier(OrganizationIdentifier); var paging = new PagingArguments { PageSize = 10 }; var directives = new[] { new PopulationDirective(nameof(OrganizationModel.Folders)) { Paging = paging } }; var model = await API.Organization.GetOrThrowAsync(organizationIdentifier, directives); int count = 0; long total = model.Folders.TotalMatches; bool done = false; while (!done) { foreach (var batch in model.Folders.Rows.Batch(1000)) { await API.Queue.EnqueueAsync("Patrol", batch); Console.WriteLine($"Enqueued {count}/{total} [{Math.Floor(1.0 * count / total * 100)}%]"); } var newRows = model.Folders.Rows.Count(); count += newRows; if (newRows > 0 && count < total) { paging.PageIndex++; model = await API.Organization.GetOrThrowAsync(organizationIdentifier, directives); } else { done = true; } } }
public async Task <List <UserForAdministrationDto> > GetUsersAsync(PagingArguments args) { var x = from u in _usersRepo.Table select new UserForAdministrationDto { Id = Guid.Parse(u.Id), Email = u.Email, Gender = u.Gender.ToString(), IsEmailConfirmed = u.EmailConfirmed, PhoneNumber = u.PhoneNumber, RegisteredAt = u.CreatedAt, Username = u.UserName, AccessFeildCount = u.AccessFailedCount, PictureUrl = _urlConstructor.ConstructOrDefault(u.Photos.OrderByDescending(pp => pp.AddedAtUtc).FirstOrDefault()), }; return(await x.SkipTakeAsync(args)); }
public async Task <List <ObjectDto> > GetObjects(PagingArguments arguments) { var(login, user) = await _userDataManager.AddCurrentUserIfNeeded(); var userLocation = login.LoginLocation; var filteredObjects = _objectRepo.Table.Where(_queryHelper.IsValidObject) .Where(_queryHelper.ValidForFreeAndLendibg); var objects = from o in filteredObjects let distance = o.OwnerLogin.User.Logins.OrderByDescending(l => l.LoggedAt).FirstOrDefault().LoginLocation.Distance(userLocation) orderby o.OfferedObjectId select o; var objectsList = await objects.Select(ObjectDtoSelectExp).SkipTakeAsync(arguments); await _impressionManager.AddImpressions(objectsList); return(objectsList); }
public async Task <IActionResult> GetForObject(int objectId, PagingArguments pagingArguments = null) { if (pagingArguments is object) { var comments = from comment in _commentsRepo.Table where comment.ObjectId == objectId orderby comment.AddedAtUtc descending select new { UserId = comment.Login.UserId.ToString(), ObjectId = comment.ObjectId, Comment = comment.Comment, CommentedAtUtc = comment.AddedAtUtc, CommentId = comment.ObjectCommentId }; return(Ok(new { Comments = await comments.SkipTakeAsync(pagingArguments), CommentsCount = comments.Count() })); } else { var comments = from comment in _commentsRepo.Table where comment.ObjectId == objectId orderby comment.AddedAtUtc descending select new { UserId = comment.Login.UserId.ToString(), ObjectId = comment.ObjectId, Comment = comment.Comment, CommentedAtUtc = comment.AddedAtUtc, CommentId = comment.ObjectCommentId }; return(Ok(new { Comments = await comments.ToListAsync(), CommentsCount = comments.Count() })); } }
public async Task <CommentListDto> GetCommentsForObject(int objectId, PagingArguments pagingArguments) { var comments = from comment in _commentsRepo.Table where comment.ObjectId == objectId orderby comment.AddedAtUtc descending select new CommentDto { UserId = comment.Login.UserId.ToString(), ObjectId = comment.ObjectId, Comment = comment.Comment, CommentedAtUtc = comment.AddedAtUtc, CommentId = comment.ObjectCommentId }; return(new CommentListDto { Comments = await comments.SkipTakeAsync(pagingArguments), CommentsCount = comments.Count() }); }
public async Task <IActionResult> GetUserObjectsTransactions([FromQuery] PagingArguments pagingArguments) { var currentUser = _credentialsGetter.GetCuurentUser(); if (currentUser?.UserId is null) { throw new UnauthorizedAccessException(); } var userId = currentUser.UserId; var trans = from rg in _registrationsRepo.Table where rg.RecipientLogin.UserId == Guid.Parse(userId) let isReceived = rg.ObjectReceiving != null let isReturned = rg.ObjectReceiving != null && rg.ObjectReceiving.ObjectReturning != null orderby rg.RegisteredAtUtc descending select new RegistrationDto { RegistrationId = rg.ObjectRegistrationId, ObjectId = rg.Object.OriginalObjectId, OwnerId = rg.Object.OwnerUserId.ToString(), ReceiverId = rg.RecipientLogin.UserId.ToString(), ReceivingId = rg.ObjectReceiving.ObjectReceivingId, ReturnId = isReturned ? rg.ObjectReceiving.ObjectReturning.ObjectReturningId : (Guid?)null, RegistredAtUtc = rg.RegisteredAtUtc, ReceivedAtUtc = isReceived ? rg.ObjectReceiving.ReceivedAtUtc : (DateTime?)null, ReturenedAtUtc = isReturned ? rg.ObjectReceiving.ObjectReturning.ReturnedAtUtc : (DateTime?)null, TranscationType = !rg.Object.ShouldReturn ? TransactionType.Free : rg.Object.HourlyCharge.HasValue ? TransactionType.Renting : TransactionType.Lending, HourlyCharge = rg.Object.HourlyCharge, ShouldReturnAfter = rg.ShouldReturnItAfter, TransactionStatus = rg.Status == ObjectRegistrationStatus.Canceled ? TransactionStatus.Canceled : isReturned ? TransactionStatus.Returned : isReceived ? TransactionStatus.Received : TransactionStatus.RegisteredOnly, }; return(Ok(await trans.SkipTakeAsync(pagingArguments))); }
public async Task <IActionResult> GetObjectsOrdered(string orderType, PagingArguments pagingArguments) { OrderByType type; if (orderType == null) { type = OrderByType.Default; } if (!Enum.TryParse <OrderByType>(orderType, true, out type)) { return(BadRequest(new ErrorMessage { ErrorCode = "CATALOG.OBJECT.LIST.ORDER.NOT.DEFINED", Message = "The order type is not recognized", StatusCode = System.Net.HttpStatusCode.BadRequest })); } var result = await _objectsOrderedGetter.GetObjects(type, pagingArguments); return(Ok(result)); }
public async Task <IActionResult> GetObjectsV1_1(PagingArguments pagings) { var objects = await _objectGetter.GetObjectsV1_1(pagings); return(StatusCode(200, objects)); }
public Task <List <ObjectDtoV1_1> > GetObjectsV1_1(PagingArguments arguments) { return(_objectService.GetObjectsV1_1(arguments)); }
public static List <T> SkipTake <T>(this IQueryable <T> query, PagingArguments arguments) { return(query.Skip(arguments.StartObject).Take(arguments.Size).ToList()); }
Task <List <ObjectDtoV1_1> > IObjectService.GetObjectsV1_1(PagingArguments arguments) => _objectGetter.GetObjectsV1_1(arguments);
Task <List <ObjectDtoV1_1> > IObjectService.GetObjects(OrderByType orderBy, PagingArguments pagingArgs) => _objectGetter.GetObjects(orderBy, pagingArgs);
public async Task <IActionResult> GetUsersRegistrationsOnOtherUsersObjects([FromQuery] PagingArguments pagingArguments) { var result = await _transactionsGetter.GetTransactionsWhereUserIsRecipient(pagingArguments); return(Ok(result)); }
public async Task <IActionResult> GetUserObjectsTransactions([FromQuery] PagingArguments pagingArguments) { var result = await _transactionsGetter.GetTransactionsWhereUserIsOwner(pagingArguments); return(Ok(result)); }
public static async Task <List <T> > SkipTakeAsync <T, TKey, TEntity>(this IQueryable <T> query, IRepository <TKey, TEntity> repo, PagingArguments arguments) where TEntity : class, IEntity <TKey> { return(await repo.ToListAsync(query.Skip(arguments.StartObject).Take(arguments.Size))); }
public Task <List <ObjectDtoV1_1> > GetObjects(OrderByType orderBy, PagingArguments pagingArgs) { return(_objectService.GetObjects(orderBy, pagingArgs)); }