コード例 #1
0
        public TopTweetersRetweetersModule(IRepository<string, IEnumerable<TweetRetweet>> tweets)
        {
            this.Get["/top-tweeters-retweeters/{track}", true] = async (parameters, __) =>
            {
                // see https://github.com/NancyFx/Nancy/issues/1154
                var track = ((string)parameters.track).Replace("해시", "#");
                var trackTweets = (await tweets.GetAsync(track)).ToList();
                var entries = trackTweets
                    .GroupBy(tweet => tweet.UserId)
                    .Select(g => new UserEntry
                    {
                        Id = g.Key,
                        IdStr = g.First().UserIdStr,
                        Name = g.First().UserName,
                        ScreenName = g.First().UserScreenName,
                        Count = g.Count(),
                    })
                    .OrderByDescending(entry => entry.Count)
                    .Select((entry, index) =>
                    {
                        entry.Position = index + 1;
                        return entry;
                    })
                    .Take(10)
                    .ToList();

                return new Leaderboard<UserEntry>
                {
                    Entries = entries,
                    Count = trackTweets.Count,
                    Since = trackTweets.FirstOrDefault()?.TweetedRetweetedAt,
                };
            };
        }
コード例 #2
0
        public MostMentionedModule(IRepository<string, IEnumerable<Mention>> mentions)
        {
            this.Get["/most-mentioned/{track}", true] = async (parameters, __) =>
            {
                // see https://github.com/NancyFx/Nancy/issues/1154
                var track = ((string)parameters.track).Replace("해시", "#");
                var trackMentions = (await mentions.GetAsync(track)).ToList();
                var entries = trackMentions
                    .GroupBy(mention => mention.UserMentionId)
                    .Select(g => new UserEntry
                    {
                        Id = g.Key,
                        IdStr = g.First().UserMentionIdStr,
                        Name = g.First().UserMentionName,
                        ScreenName = g.First().UserMentionScreenName,
                        Count = g.Count(),
                    })
                    .OrderByDescending(entry => entry.Count)
                    .Select((entry, index) =>
                    {
                        entry.Position = index + 1;
                        return entry;
                    })
                    .Take(10)
                    .ToList();

                return new Leaderboard<UserEntry>
                {
                    Entries = entries,
                    Count = trackMentions.Count,
                    Since = trackMentions.FirstOrDefault()?.MentionedAt,
                };
            };
        }
コード例 #3
0
        public MostHashtaggedModule(IRepository<string, IEnumerable<Hashtag>> hashtags)
        {
            this.Get["/most-hashtagged/{track}", true] = async (parameters, __) =>
            {
                // see https://github.com/NancyFx/Nancy/issues/1154
                var track = ((string)parameters.track).Replace("해시", "#");
                var trackHashtags = (await hashtags.GetAsync(track)).ToList();
                var entries = trackHashtags
                    .GroupBy(tweet => tweet.Text, StringComparer.InvariantCultureIgnoreCase)
                    .Select(g => new HashtagEntry
                    {
                        Text = g.Key,
                        Count = g.Count(),
                    })
                    .OrderByDescending(entry => entry.Count)
                    .Select((entry, index) =>
                    {
                        entry.Position = index + 1;
                        return entry;
                    })
                    .Take(10)
                    .ToList();

                return new Leaderboard<HashtagEntry>
                {
                    Entries = entries,
                    Count = trackHashtags.Count,
                    Since = trackHashtags.Any() ? trackHashtags.Min(hashtag => hashtag.HashtaggedAt) : (DateTime?)null,
                    LastActivityDateTime = trackHashtags.Any() ? trackHashtags.Max(hashtag => hashtag.HashtaggedAt) : (DateTime?)null,
                };
            };
        }
コード例 #4
0
        static async Task MainAsync(IRepository<SampleEntity> repo)
        {
            foreach (var s in await repo.GetAllAsync())
            {
                Console.WriteLine("{0} | {1}", s.ID, s.Name);
            }

            // Paged Set //
            Console.WriteLine("\nPage = 2 - Page Size = 2 :");
            var some = await repo.GetAsync(2, 2, s => s.ID);
            foreach (var s in some)
            {
                Console.WriteLine("{0} | {1}", s.ID, s.Name);
            }
                
            // Updating //
            var fox = await repo.FindAsync(e => e.Name == "Fox");
            fox.Name = "Dog";

            repo.Update(fox, fox.ID);

            // Deleting //
            Console.WriteLine("\n " + await repo.DeleteAsync(repo.Get(5)) + "\n");

            foreach (var e in repo.GetAll())
                Console.WriteLine(e.ID + " | " + e.Name);
        }
コード例 #5
0
        public MostMentionedModule(
            IRepository<string, IEnumerable<Mention>> mentions, IIgnoredUserNamesService ignoredUserNamesService)
        {
            this.Get["/most-mentioned/{track}", true] = async (parameters, __) =>
            {
                // see https://github.com/NancyFx/Nancy/issues/1154
                var track = ((string)parameters.track).Replace("해시", "#");
                var trackMentions = (await mentions.GetAsync(track)).ToList();
                var entries = trackMentions
                    .Where(item => !ignoredUserNamesService.Get().Contains(item.UserMentionScreenName))
                    .GroupBy(mention => mention.UserMentionId)
                    .Select(g => new UserEntry
                    {
                        Id = g.Key,
                        IdStr = g.First().UserMentionIdStr,
                        Name = g.First().UserMentionName,
                        ScreenName = g.First().UserMentionScreenName,
                        Count = g.Count(),
                    })
                    .OrderByDescending(entry => entry.Count)
                    .Select((entry, index) =>
                    {
                        entry.Position = index + 1;
                        return entry;
                    })
                    .Take(10)
                    .ToList();

                return new Leaderboard<UserEntry>
                {
                    Entries = entries,
                    Count = trackMentions.Count,
                    Since = trackMentions.Any() ? trackMentions.Min(mention => mention.MentionedAt) : (DateTime?) null,
                    LastActivityDateTime = trackMentions.Any()? trackMentions.Max(mention => mention.MentionedAt): (DateTime?) null,
                };
            };
        }
コード例 #6
0
        public async Task <EditDeliverInput> GetDeliverById(OneParam param)
        {
            var deliver = await _deliverRepository.GetAsync(param.Id);

            return(deliver.MapTo <EditDeliverInput>());
        }
コード例 #7
0
        /// <summary>
        /// 通过指定id获取RetailerListDto信息
        /// </summary>
        public async Task <RetailerListDto> GetRetailerByIdAsync(Guid id)
        {
            var entity = await _entityRepository.GetAsync(id);

            return(entity.MapTo <RetailerListDto>());
        }
コード例 #8
0
        public async Task <ScholarshipSectionDto> Get(int id)
        {
            var elm = await _repository.GetAsync(id);

            return(elm.MapTo <ScholarshipSectionDto>());
        }
コード例 #9
0
        public async Task <CloudBookListListDto> GetById(EntityDto <long> input)
        {
            var entity = await _entityRepository.GetAsync(input.Id);

            return(entity.MapTo <CloudBookListListDto>());
        }
コード例 #10
0
 public async Task <IEnumerable <Customer> > GetAllAsync()
 {
     return(await _repository.GetAsync(_ => true)
            .AnyContext());
 }
コード例 #11
0
        public async Task <GetIncidentForViewDto> GetIncidentForView(int id, PagedAndSortedResultRequestDto input)
        {
            var incident = await _incidentRepository.GetAsync(id);

            var output = new GetIncidentForViewDto {
                Incident = ObjectMapper.Map <IncidentDto>(incident)
            };

            if (output?.Incident != null)
            {
                if (output.Incident.Id > 0)
                {
                    var filteredIncidentUpdates = _incidentUpdateRepository.GetAll()
                                                  .Include(e => e.UserFk)
                                                  .Include(e => e.IncidentFk)
                                                  .Where(e => e.IncidentId == output.Incident.Id);

                    var pagedAndFilteredIncidentUpdates = filteredIncidentUpdates
                                                          .OrderBy(input.Sorting ?? "id asc")
                                                          .PageBy(input);

                    var incidentUpdates = from o in pagedAndFilteredIncidentUpdates
                                          join o1 in _lookup_userRepository.GetAll() on o.UserId equals o1.Id into j1
                                          from s1 in j1.DefaultIfEmpty()

                                          join o2 in _lookup_incidentRepository.GetAll() on o.IncidentId equals o2.Id into j2
                                          from s2 in j2.DefaultIfEmpty()

                                          select new GetIncidentUpdateForViewDto()
                    {
                        IncidentUpdate = new IncidentUpdateDto
                        {
                            Updated    = o.Updated,
                            Update     = o.Update,
                            Id         = o.Id,
                            IncidentId = o.IncidentId
                        },
                        UserName = s1 == null ? "" : s1.Name.ToString(),
                        IncidentDescription = s2 == null ? "" : s2.Description.ToString()
                    };

                    var totalCount = await filteredIncidentUpdates.CountAsync();

                    output.IncidentUpdates = new PagedResultDto <GetIncidentUpdateForViewDto>(
                        totalCount,
                        await incidentUpdates.ToListAsync()
                        );
                }


                if (output.Incident.IncidentPriorityId != null)
                {
                    var _lookupIncidentPriority = await _lookup_incidentPriorityRepository.FirstOrDefaultAsync((int)output.Incident.IncidentPriorityId);

                    output.IncidentPriorityPriority = _lookupIncidentPriority.Priority.ToString();
                }

                if (output.Incident.IncidentStatusId != null)
                {
                    var _lookupIncidentStatus = await _lookup_incidentStatusRepository.FirstOrDefaultAsync((int)output.Incident.IncidentStatusId);

                    output.IncidentStatusStatus = _lookupIncidentStatus.Status.ToString();
                }

                if (output.Incident.CustomerId != null)
                {
                    var _lookupCustomer = await _lookup_customerRepository.FirstOrDefaultAsync((int)output.Incident.CustomerId);

                    output.CustomerName = _lookupCustomer.Name.ToString();
                }

                if (output.Incident.AssetId != null)
                {
                    var _lookupAsset = await _lookup_assetRepository.FirstOrDefaultAsync((int)output.Incident.AssetId);

                    output.AssetReference = _lookupAsset.Reference.ToString();
                }

                if (output.Incident.SupportItemId != null)
                {
                    var _lookupSupportItem = await _lookup_supportItemRepository.FirstOrDefaultAsync((int)output.Incident.SupportItemId);

                    output.SupportItemDescription = _lookupSupportItem.Description.ToString();
                }

                if (output.Incident != null)
                {
                    var _lookupIncidentType = await _lookup_incidentTypeRepository.FirstOrDefaultAsync((int)output.Incident.IncidentTypeId);

                    output.IncidentTypeType = _lookupIncidentType.Type.ToString();
                }

                using (_unitOfWorkManager.Current.DisableFilter(AbpDataFilters.MustHaveTenant, AbpDataFilters.MayHaveTenant))  // BYPASS TENANT FILTER
                {
                    if (output.Incident.UserId != null)
                    {
                        var _lookupUser = await _lookup_userRepository.FirstOrDefaultAsync((long)output.Incident.UserId);

                        output.UserName = _lookupUser.Name.ToString();
                    }
                }
            }

            return(output);
        }
コード例 #12
0
 public async Task <Weed> GetAsync(Guid id)
 {
     return(await _repository.GetAsync(id));
 }
コード例 #13
0
 public async Task <CustomerSubjectTranslation> GetInfo(string customerSubjectId, string languageId, bool isReadOnly = false)
 {
     return(await _customerSubjectTranslationRepository.GetAsync(isReadOnly, x => x.CustomerSubjectId == customerSubjectId && x.LanguageId == languageId));
 }
コード例 #14
0
        public async Task <PersonelTypeDTO> GetPersonelTypeAsync(Guid Id)
        {
            var personelType = await _personelTypeRepository.GetAsync(x => x.Id == Id);

            return(MapperFactory.CurrentMapper.Map <PersonelTypeDTO>(personelType));
        }
コード例 #15
0
        /// <summary>
        /// Return the List of Model Data, in our case it will be Category
        /// </summary>
        /// <returns></returns>
        public async Task <IActionResult> Index()
        {
            var res = await repository.GetAsync();

            return(View(res)); // this will return Index View as the name of method is 'Index'
        }
コード例 #16
0
        public async Task <DicDataResultModel> GetByIdAsync(int id)
        {
            var dicdata = await _dicdataRepository.GetAsync(id);

            return(_mapper.Map <DicDataResultModel>(dicdata));
        }
コード例 #17
0
        public async Task <PersonListDto> GetById(EntityDto <int> input)
        {
            var entity = await _entityRepository.GetAsync(input.Id);

            return(entity.MapTo <PersonListDto>());
        }
コード例 #18
0
 public async Task <PageTranslation> GetInfo(int pageId, string languageId, bool isReadOnly = false)
 {
     return(await _pageTranslationRepository.GetAsync(isReadOnly, x => x.PageId == pageId && x.LanguageId == languageId && !x.IsDelete));
 }
コード例 #19
0
 public async Task <MailTempContentTranslation> GetInfo(string tenantId, string mailTempContentId, string languageId, bool isReadOnly = false)
 {
     return(await _mailTempContentTranslationRepository.GetAsync(isReadOnly, x => x.MailTempContentId == mailTempContentId && x.TenantId == tenantId && x.LanguageId == languageId));
 }
コード例 #20
0
        public async Task <Book> GetBook(int id)
        {
            return(await _cacheManager.GetAsync <int, Book>(id, async (bookId) => await _bookRepository.GetAsync(bookId)));

            //return await _cacheManager.GetAsync<int, Book>(id, async (bookId) => await Task.FromResult(new Book() { Id = bookId,  }));
        }
コード例 #21
0
 public async Task <UserDelegation> GetAsync(long userDelegationId)
 {
     return(await _userDelegationRepository.GetAsync(userDelegationId));
 }
コード例 #22
0
        public IEnumerable <Test> GetTests()
        {
            var spec = new Specification <Test>(x => x.Taken == false);

            return(testRepository.GetAsync(spec, 1, 20).Result.Items);
        }
コード例 #23
0
 public async Task <BeerType> GetBeerType(int id)
 {
     return(await _beerTypeRepository.GetAsync(id));
 }
コード例 #24
0
        public async Task <EmailDto> GetAsync(int id)
        {
            var email = await _repository.GetAsync <Email>(id);

            return(_mapper.Map <EmailDto>(email));
        }
コード例 #25
0
        /// <summary>
        /// 根据生产厂家Id获取某个厂家信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task <ManufactoryDto> GetManufactoryById(Guid id)
        {
            var manufactory = await _manufactoryRepository.GetAsync(id);

            return(ObjectMapper.Map <Manufactory, ManufactoryDto>(manufactory));
        }
コード例 #26
0
        public async Task CheckAttachment <T>(int AttachmentTypeId, string ObjectID, AttachmentsViewModelWithEntityDto <T> input, AttachmentUploadType type)
        {
            var attachmentType = await _lookup_attachmentTypeRepository.GetAsync(AttachmentTypeId);

            if (attachmentType == null)
            {
                throw new UserFriendlyException(L("InvalidAttachmentTypeIdCode"), L("InvalidAttachmentTypeIdCode_Detail"));
            }

            if ((input.Attachments != null && input.Attachments.Count > 0) || (input.AttachmentsToDelete != null && input.AttachmentsToDelete.Count > 0))
            {
                var version       = 1;
                var numOfAttached = input.Attachments.Count;

                if (type == AttachmentUploadType.edit)
                {
                    var oldAttachments = await _attachmentFileRepository.GetAll().Where(e => e.ObjectId == ObjectID && e.AttachmentTypeId == AttachmentTypeId).OrderByDescending(e => e.Version).ToListAsync();

                    var anyAttachment = oldAttachments.FirstOrDefault();

                    if (anyAttachment != null)
                    {
                        var lastGroup = oldAttachments.Where(e => e.Version == anyAttachment.Version).ToList();

                        var tokensToDelete = new Dictionary <string, string>();
                        foreach (var item in input.AttachmentsToDelete)
                        {
                            if (!tokensToDelete.ContainsKey(item.FileToken))
                            {
                                tokensToDelete.Add(item.FileToken, item.FileToken);
                            }
                        }
                        version = anyAttachment.Version;

                        var notDeletedAttaches = lastGroup.Where(e => !tokensToDelete.ContainsKey(e.FileToken)).ToList();
                        var DeletedAttaches    = lastGroup.Where(e => tokensToDelete.ContainsKey(e.FileToken)).ToList();
                        if (notDeletedAttaches.Count != lastGroup.Count)
                        {
                            version = anyAttachment.Version + 1;

                            foreach (var att in notDeletedAttaches)
                            {
                                att.Version = version;
                            }
                        }
                        foreach (var item in DeletedAttaches)
                        {
                            await _attachmentFileRepository.DeleteAsync(item);
                        }
                        numOfAttached += notDeletedAttaches.Count;
                    }
                }

                if (numOfAttached > attachmentType.MaxAttachments)
                {
                    throw new UserFriendlyException(L("MaxAttachmentsCode"), L("MaxAttachmentsCode_Detail"));
                }
                var listAttachments = new List <UploadFilesInputDto>();
                foreach (var att in input.Attachments)
                {
                    var FileByte = _tempFileCacheManager.GetFile(att.FileToken);
                    if (FileByte == null)
                    {
                        throw new UserFriendlyException("There is no such image file with the token: " + att.FileToken);
                    }
                    CheckFileType(att.FileName, attachmentType);
                    if (attachmentType.MaxSize != 0 && FileByte.Length > attachmentType.MaxSize * 1000)
                    {
                        throw new UserFriendlyException(L("FileSizeNotAllowdCode"), L("FileSizeNotAllowdCode_Detail"));
                    }
                    var UploadFilesInputDto = ObjectMapper.Map <UploadFilesInputDto>(att);
                    UploadFilesInputDto.FileByte = FileByte;
                    UploadFilesInputDto.Version  = version;
                    listAttachments.Add(UploadFilesInputDto);
                }
                await AddAttachment(
                    attachmentType, ObjectID,
                    listAttachments
                    );
            }
            else
            {
                if (attachmentType.IsRequired)
                {
                    throw new UserFriendlyException(L("AttachmentNotFoundCode"), L("AttachmentNotFoundCode_Detail"));
                }
            }
        }
コード例 #27
0
 public async Task <Car> GetCar(ObjectId id)
 {
     return(await _repository.GetAsync(id));
 }
コード例 #28
0
        public async Task <ICollection <ZoneListListModel> > GetAllAsync()
        {
            var entities = await heatingZoneRepository.GetAsync();

            return(entities.Select(x => new ZoneListListModel(x.Id, x.Name, x.Code)).ToList());
        }
コード例 #29
0
        /// <summary>
        /// 通过指定id获取ActivityListDto信息
        /// </summary>
        public async Task <ActivityListDto> GetActivityByIdAsync(EntityDto <Guid> input)
        {
            var entity = await _activityRepository.GetAsync(input.Id);

            return(entity.MapTo <ActivityListDto>());
        }
コード例 #30
0
        public async Task <JobDto> Get(Guid id)
        {
            var result = await _repository.GetAsync(id);

            return(ObjectMapper.Map <Job, JobDto>(result));
        }
コード例 #31
0
 public async Task <BackgroundJobInfo> GetAsync(long jobId)
 {
     return(await _unitOfWorkManager.WithUnitOfWorkAsync(async() =>
                                                         await _backgroundJobRepository.GetAsync(jobId)
                                                         ));
 }
コード例 #32
0
 public async Task LoadStateAsync(object consumer, object message)
 {
     Consumer(consumer).State = await repository.GetAsync(CorrelationId(message));
 }
コード例 #33
0
 /// <summary>
 /// Gets all the records that matches the query
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="repository"></param>
 /// <param name="connection"></param>
 /// <param name="commandDefinition"></param>
 /// <returns></returns>
 public static async Task <IEnumerable <T> > QueryAsync <T>(this IRepository <T> repository, IDbConnection connection, CommandDefinition commandDefinition) where T : class
 => await repository.GetAsync(connection, commandDefinition);
コード例 #34
0
 public Task <ReasonCode> GetAsync(string id)
 => _repository.GetAsync(id);
コード例 #35
0
        public virtual async Task <T> Get(int id)
        {
            T result = await _repository.GetAsync(id).ConfigureAwait(false);

            return(result);
        }