当前位置: 首页>>代码示例>>C#>>正文


C# IRepository.Search方法代码示例

本文整理汇总了C#中IRepository.Search方法的典型用法代码示例。如果您正苦于以下问题:C# IRepository.Search方法的具体用法?C# IRepository.Search怎么用?C# IRepository.Search使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IRepository的用法示例。


在下文中一共展示了IRepository.Search方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DocumentModule

        public DocumentModule(IRepository documents, IImageRepository images, IRatingRepository ratings, IReviewRepository reviews, IFavoritesRepository favorites, IEnvironmentPathProvider pathProvider)
            : base("/documents")
        {
            Get["/{id}/thumbnail"] = args =>
            {
                var doc = documents.GetDocument(args.id, true);
                string img = images.GetDocumentImage(args.id);

                if (String.IsNullOrEmpty(img))
                {
                    return ResolvePlaceHolderImageForDocumentType(pathProvider, doc);
                }

                return Response.AsFile(Path.Combine(pathProvider.GetImageCachePath(), img));
            };

            Get["/{id}"] = args =>
            {
                Document document = documents.GetDocument(args.id, false);
                return Response.AsJson(DtoMaps.Map(document, favorites, Context.GetUserInfo()));
            };
            
            Get["/{id}/rating"] = args =>
            {
                try
                {
                    DocumentRating rating = ratings.GetDocumentRating(args.id);

                    return Response.AsJson(new DocumentRatingDto
                    {
                        MaxScore = rating.MaxScore,
                        Score = rating.Score,
                        Source = rating.Source,
                        SourceUrl = rating.SourceUrl,
                        HasRating = true
                    }).AsCacheable(DateTime.Now.AddDays(1));
                }
                catch
                {
                    return new DocumentRatingDto {Success = true, HasRating = false};
                }
            };

            Get["/{id}/review"] = args =>
            {
                string review = reviews.GetDocumentReview(args.id);
                return Response.AsJson(new DocumentReviewDto{ Review = review, Url = "" }).AsCacheable(DateTime.Now.AddDays(1));
            };

            Get["/search"] = _ =>
            {
                string query = Request.Query.query.HasValue ? Request.Query.query : null;

                if (null == query) throw new InvalidOperationException("Ingenting å søke etter.");

                return Response.AsJson(documents.Search(query).Select(doc => DtoMaps.Map(doc, favorites, Context.GetUserInfo())).ToArray()).AsCacheable(DateTime.Now.AddHours(12));
            };
        }
开发者ID:khellang,项目名称:Solvberget,代码行数:58,代码来源:DocumentModule.cs

示例2: IndexModule

        public IndexModule (IRepository repository)
        {
            repo = repository;

            Get ["/"] = parameters => 
            {
                return View ["index"];
            };

            Get ["/search/{text}", true] = async (parameters, ct) => 
            {
                Card [] cards = await repo.Search ((string)parameters.text);

                return Response.AsJson (cards);
            };

            Get ["/cards", true] = async (parameters, ct) => 
            {
                JsonSettings.MaxJsonLength =    100000000;
                Card[] cards =                  null;
                cards =                         await repo.GetCards (Request.Query);
                  
                if(Request.Query.Fields != null)
                {
                    var c = cards.AsQueryable()
                        .Select(string.Format("new ({0})",
                            (string)Request.Query.Fields));

                    return Response.AsJson(c);
                }
                    
                return Response.AsJson (cards);
            };

            Get ["/cards/{id}", true] = async (parameters, ct) => 
            {
                try
                {
                    int[] multiverseIds = 
                        Array.ConvertAll(((string)parameters.id).Split(','), int.Parse);

                    if(multiverseIds.Length > 1)
                    {
                        Card [] cards = await repo.GetCards(multiverseIds);

                        return Response.AsJson(cards);
                    }
                }
                catch(Exception e)
                {
                    //swallo it, cannot convert parameter to int array 
                }


                int id = 0; 
                if(int.TryParse((string)parameters.id, out id))
                {
                    Card card = await repo.GetCard ((int)parameters.id);
                    return Response.AsJson (card);
                }
                else
                {
                    Card [] cards = await repo.GetCards ((string)parameters.id);
                    return Response.AsJson (cards);
                }
            };

            Get ["/sets/{id}", true] = async (parameters, ct) =>  
            {
                string [] ids = ((string)parameters.id).Split(',');

                if(ids.Length > 1)
                {
                    CardSet[] cardSets = await repo.GetSets (ids);
                    return Response.AsJson (cardSets);
                }

                CardSet cardSet = await repo.GetSet ((string)parameters.id);
                return Response.AsJson (cardSet);
            };

            Get ["/sets/", true] = async (parameters, ct) => 
            {
                CardSet[] cardset =             await repo.GetSets ();
                JsonSettings.MaxJsonLength =    1000000;

                return Response.AsJson (cardset);
            };

            Get ["/sets/{id}/cards/", true] = async (parameters, ct) => 
            {
                JsonSettings.MaxJsonLength =    100000000;
                int start =                     0; 
                int end =                       0; 

                if(Request.Query.start != null )
                {
                    int.TryParse((string)Request.Query.start, out start);
                }

//.........这里部分代码省略.........
开发者ID:jesseflorig,项目名称:api.mtgdb.info,代码行数:101,代码来源:IndexModule.cs

示例3: IndexModule

        public IndexModule (IRepository repository, Cache cache)
        {
            repo = repository;

            Get ["/"] = parameters => 
            {
                return View ["index"];
            };

            Get ["/search/", true] = async (parameters, ct) => 
            {
                string query = (string)Request.Query.q;
                int limit = 0; 
                int start = 0; 
                string total = "";

                if(Request.Query.limit != null)
                {
                    limit = (int)Request.Query.limit;
                }

                if(Request.Query.start != null)
                {
                    start = (int)Request.Query.start;
                }

                if(Request.Query.total != null)
                {
                    total = (string)Request.Query.total;
                    if(total.ToLower() == "true")
                    {
                        long count = await repo.SearchTotal(query,true);
                        return Response.AsJson (count);
                    }
                }
                    
                Card [] cards = await repo.Search (query,start,limit,true);

                return Response.AsJson (cards);
            };


            Get ["/search/{text}", true] = async (parameters, ct) => 
            {
                int limit = 0; 
                int start = 0; 
               

                if(Request.Query.limit != null)
                {
                    limit = (int)Request.Query.limit;
                }

                if(Request.Query.start != null)
                {
                    start = (int)Request.Query.start;
                }
                    
                Card [] cards = await repo.Search ((string)parameters.text,
                    start, limit, false);

                return Response.AsJson (cards);
            };

            Get ["/cards/types", true] = async (parameters, ct) => 
            {
                string [] types  = await repo.GetCardTypes();
                return Response.AsJson (types.OrderBy(x => x));
            };

            Get ["/cards/subtypes", true] = async (parameters, ct) => 
            {
                string [] types  = await repo.GetCardSubTypes();
                return Response.AsJson (types.OrderBy(x => x));
            };
                
            Get ["/cards/rarity", true] = async (parameters, ct) => 
            {
                string [] rarity  = await repo.GetCardRarity();
                return Response.AsJson (rarity.OrderBy(x => x));
            };

            Get ["/cards/random", true] = async (parameters, ct) => 
            {
                JsonSettings.MaxJsonLength =    100000000;
                Card card =                    null;
            
                card = await repo.GetRandomCard();

                return Response.AsJson (card);
            };

            Get ["/cards", true] = async (parameters, ct) => 
            {
                JsonSettings.MaxJsonLength =    100000000;
                Card[] cards =                  null;
               
                if(Request.Query.Fields != null)
                {
                    string[] fields = ((string)Request.Query.Fields).Split(',');
//.........这里部分代码省略.........
开发者ID:chasepark,项目名称:api.mtgdb.info,代码行数:101,代码来源:IndexModule.cs


注:本文中的IRepository.Search方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。