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


C# IRepository.GetDocument方法代码示例

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


在下文中一共展示了IRepository.GetDocument方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: FavoritesModule

        public FavoritesModule(IFavoritesRepository favorites, IRepository documents)
            : base("/favorites")
        {
            this.RequiresAuthentication();

            Get["/"] = _ => favorites.GetFavorites(Context.GetUserInfo()).Select(MapToDto).ToArray();

            Delete["/{documentId}"] = args =>
            {
                var document = documents.GetDocument(args.documentId, true);

                favorites.RemoveFavorite(document, Context.GetUserInfo());
                
                return new RequestReplyDto { Success = true };
            };

            Put["/{documentId}"] = args =>
            {
                var document = documents.GetDocument(args.documentId, true);
                favorites.AddFavorite(document, Context.GetUserInfo());

                return new RequestReplyDto { Success = true };
            };
        }
开发者ID:khellang,项目名称:Solvberget,代码行数:24,代码来源:FavoritesModule.cs

示例3: Map

        public static ReservationDto Map(Reservation reservation, IRepository documents)
        {
            DateTime holdEnd;
            DateTime holdFrom;
            DateTime holdTo;

            DateTime.TryParse(reservation.HoldRequestEnd, out holdEnd);
            DateTime.TryParse(reservation.HoldRequestFrom, out holdFrom);
            DateTime.TryParse(reservation.HoldRequestTo, out holdTo);

            return new ReservationDto
            {
                Document = Map(documents.GetDocument(reservation.DocumentNumber, true)),
                Reserved = holdFrom,
                ReadyForPickup = !UnavailableStatuses.Contains(reservation.Status), // business logic should not be here! :(
                PickupLocation = reservation.PickupLocation,
                PickupDeadline = holdTo
            };
        }
开发者ID:khellang,项目名称:Solvberget,代码行数:19,代码来源:DtoMaps.cs

示例4: UserModule

        public UserModule(IRepository documents) : base("/user")
        {
            this.RequiresAuthentication();

            Get["/notifications/count"] = args =>
            {
                //var since = Request.Query.since.HasValue ? Request.Query.since : DateTime.MinValue;
                
                // we have no idea when a notification was created. Or rather, all notifications are always created 'now'...

                return new NotificationCountDto {Count = Context.GetUserInfo().Notifications.Count()};
            };

            Get["/info"] = _ =>
            {
                var user = Context.GetAlephUserIdentity();
                UserInfo results = documents.GetUserInformation(user.UserName, user.Password);

                var reservationsList = results.Reservations ?? new List<Reservation>();
                var finesList = results.ActiveFines ?? new List<Fine>();
                var loansList = results.Loans ?? new List<Loan>();
                var notificationList = results.Notifications ?? new List<Notification>();
                var reservations = reservationsList.Select(r => DtoMaps.Map(r, documents));

                var fines = finesList.Select(f => new FineDto
                {
                    Date = ParseDateString(f.Date),
                    Description = f.Description,
                    Document = String.IsNullOrEmpty(f.DocumentNumber) ? null : DtoMaps.Map(documents.GetDocument(f.DocumentNumber, true)),
                    Status = f.Status,
                    Sum = f.Sum
                }).OrderByDescending(f => f.Date);

                var loans = loansList.Select(l => new LoanDto
                {
                    Document = String.IsNullOrEmpty(l.DocumentNumber) ? null : DtoMaps.Map(documents.GetDocument(l.DocumentNumber, true)),
                    AdminisrtativeDocumentNumber = l.AdminisrtativeDocumentNumber,
                    Barcode = l.Barcode,
                    DocumentNumber = l.DocumentNumber,
                    DocumentTitle = l.DocumentTitle,
                    DueDate = ParseDateString(l.DueDate),
                    ItemSequence = l.ItemSequence,
                    ItemStatus = l.ItemStatus,
                    LoanDate = ParseDateString(l.LoanDate),
                    LoanHour = l.LoanHour,
                    Material = l.Material,
                    OriginalDueDate = ParseDateString(l.OriginalDueDate),
                    SubLibrary = l.SubLibrary
                });

                var notifications = notificationList.Select(n => new NotificationDto
                {
                     Content = n.Content,
                     DocumentNumber = n.DocumentNumber,
                     DocumentTitle = n.DocumentTitle,
                     Title = n.Title,
                     Type = n.Type
                });

                var userDto = new UserInfoDto
                {
                    BorrowerId = results.BorrowerId,
                    Balance = results.Balance,
                    CashLimit = results.CashLimit,
                    CellPhoneNumber = results.CellPhoneNumber,
                    CityAddress = results.CityAddress,
                    DateOfBirth = results.DateOfBirth,
                    Email = results.Email,
                    HomeLibrary = results.HomeLibrary,
                    HomePhoneNumber = results.HomePhoneNumber,
                    Id = results.Id,
                    IsAuthorized = results.IsAuthorized,
                    Name = results.Name,
                    PrefixAddress = results.PrefixAddress,
                    StreetAddress = results.StreetAddress,
                    Zip = results.Zip,

                    Reservations = reservations,
                    Fines = fines,
                    Loans = loans,
                    Notifications = notifications
                };

                return userDto;

            };
        }
开发者ID:khellang,项目名称:Solvberget,代码行数:87,代码来源:UserModule.cs


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