public void RemoveFavorite(Document document, UserInfo user)
        {
            var favs = GetFavoritesForUser(user);
            favs.Remove(document.DocumentNumber);

            SaveFavorites(favs, user);
        }
Example #2
0
        public static DocumentDto Map(Document document, IFavoritesRepository favorites, UserInfo user)
        {
            DocumentDto dto;

            if (document is Book)
            {
                dto = Map((Book)document);
            }
            else if (document is Film)
            {
                dto = Map((Film) document);
            }
            else if (document is Cd)
            {
                dto = Map((Cd) document);
            }
            else if (document is AudioBook)
            {
                dto = Map((AudioBook) document);
            }
            else if (document is SheetMusic)
            {
                dto = Map((SheetMusic) document);
            }
            else if (document is Game)
            {
                dto = Map((Game) document);
            }
            else if (document is Journal)
            {
                dto = Map((Journal) document);
            }
            else
            {
                dto = new DocumentDto(); // todo other types
            }


            dto.WebAppUrl = Bootstrapper.Container != null ? Bootstrapper.Container.Resolve<IEnvironmentPathProvider>().GetWebAppDocumentDetailsPath(document) : string.Empty;
            dto.Id = document.DocumentNumber;
            dto.Type = document.DocType;
            dto.Title = document.Title;
            if(null == dto.SubTitle) dto.SubTitle = document.CompressedSubTitle; // default only if specific type does not map it
            dto.Availability = MapAvailability(document).ToArray();
            dto.Year = document.PublishedYear;
            dto.Publisher = document.Publisher;
            dto.Language = document.Language;
            dto.Languages = null != document.Languages ? document.Languages.ToArray() : new string[0];
            if(null != user && null != favorites) dto.IsFavorite = favorites.IsFavorite(document, user);
            if (null != user) dto.IsReserved = null != user.Reservations && user.Reservations.Any(r => r.DocumentNumber == document.DocumentNumber);

            return dto;
        }
        public static List<AvailabilityInformation> GenerateLocationAndAvailabilityInfo(IEnumerable<DocumentItem> docItems, Document doc)
        {
            var items = docItems.ToList();
            if (!items.Any()) return null;
            var availabilityinfo = new List<AvailabilityInformation>();

            foreach (var availabilityInfo in AvailabilityInformation.BranchesToHandle.Select(branch => AvailabilityRepository.GenerateInfoFor(doc, branch, items)).Where(availabilityInfo => availabilityInfo != null))
            {
                availabilityinfo.Add(availabilityInfo);
            }
            return availabilityinfo;
        }
 public bool IsFavorite(Document document, UserInfo user)
 {
     return GetFavoritesForUser(user).Contains(document.DocumentNumber);
 }
 public AvailabilityInformationTest()
 {
     _document = new Document();
     var docItems = DocumentItemRepository.GetDocumentItemsFromXml(getDocumentItemsXml(), getDocumentCircItemsXml(), new RulesRepository());
     _document.AvailabilityInfo = AvailabilityRepository.GenerateLocationAndAvailabilityInfo(docItems, _document); 
 }
 public string GetWebAppDocumentDetailsPath(Document document)
 {
     return "http://www.solvberget.no"; // until web app deployed
     var docUrl = Path.Combine(GetWebAppUrl(), GetWebType(document.DocType), document.DocumentNumber, HttpUtility.UrlEncode(document.Title));
     return docUrl;
 }
Example #7
0
 public static DocumentDto Map(Document document)
 {
     return Map(document, null, null);
 }
Example #8
0
        private static IEnumerable<DocumentAvailabilityDto> MapAvailability(Document document)
        {
            if (null == document.AvailabilityInfo) yield break;

            foreach (var availability in document.AvailabilityInfo)
            {
                if (null == availability) continue;

                var dto = new DocumentAvailabilityDto
                {
                    Branch = availability.Branch,
                    AvailableCount = availability.AvailableCount,
                    TotalCount = availability.TotalCount,

                    Department = availability.Department.DefaultIfEmpty("").Aggregate((acc, dep) =>
                    {
                        if (String.IsNullOrEmpty(acc)) return dep;
                        return acc + ", " + dep;
                    }),

                    Collection = availability.PlacementCode,
                    Location = document.LocationCode
                };
                
                DateTime date;

                if (DateTime.TryParse(availability.EarliestAvailableDateFormatted, out date))
                {
                    dto.EstimatedAvailableDate = date;
                }

                yield return dto;
            }

        }
Example #9
0
 private void GenerateDocumentLocationAndAvailabilityInfo(Document document)
 {
     var documentItems = GetDocumentItems(document.DocumentNumber);
     document.AvailabilityInfo = AvailabilityRepository.GenerateLocationAndAvailabilityInfo(documentItems, document);
 }
 public static AvailabilityInformation GenerateInfoFor(Document doc, string branch, IEnumerable<DocumentItem> docItems)
 {
     var availabilityInformation = FillProperties(doc, branch, docItems);
     return availabilityInformation.Branch != null ? availabilityInformation : null;
 }
        private static AvailabilityInformation FillProperties(Document doc, string branch, IEnumerable<DocumentItem> docItems)
        {
            var availability = new AvailabilityInformation();
            var items = docItems.Select(x => x).Where(x => x.Branch.Equals(branch) && x.IsReservable).ToList();

            if (items.Any())
            {
                availability.Branch = branch;
                availability.Department = items.Where(x => x.Department != null).Select(x => x.Department).Distinct();
                availability.PlacementCode = items.FirstOrDefault().PlacementCode;

                availability.TotalCount = items.Count();
                availability.AvailableCount = items.Count(x => x.LoanStatus == null && !x.OnHold);

                if (availability.AvailableCount == 0)
                {
                    var dueDates = items.Where(x => x.LoanDueDate != null).Select(x => x.LoanDueDate.Value);
                    if (dueDates.Any())
                    {
                        var earliestDueDate = dueDates.OrderBy(x => x).FirstOrDefault();

                        if (!items.Any(x => x.NoRequests > 0))
                        {
                            if (earliestDueDate.CompareTo(DateTime.Now) < 0)
                            {
                                // The due date has passed, but the document is not handed in yet. Set to next day.
                                availability.EarliestAvailableDateFormatted = DateTime.Now.AddDays(1).ToShortDateString();
                            }
                            else
                            {
                                availability.EarliestAvailableDateFormatted = earliestDueDate.ToShortDateString();
                            }
                        }
                        else
                        {
                            var totalNumberOfReservations = items.Sum(x => x.NoRequests);
                            var calculation1 = (totalNumberOfReservations * (doc.StandardLoanTime + AvailabilityInformation.AveragePickupTimeInDays));
                            // Below for added days: if it is required to round up the result of dividing m by n 
                            // (where m and n are integers), one should compute (m+n-1)/n
                            // Source: Number Conversion, Roland Backhouse, 2001
                            var calculation2 = (calculation1 + availability.TotalCount - 1) / availability.TotalCount;

                            if (availability.TotalCount == 1)
                                availability.EarliestAvailableDateFormatted = earliestDueDate.AddDays(calculation2).ToShortDateString();
                            else
                                availability.EarliestAvailableDateFormatted = earliestDueDate.AddDays(calculation2 + doc.StandardLoanTime).ToShortDateString();

                        }
                    }
                    else
                    {
                        availability.EarliestAvailableDateFormatted = "Ukjent";
                        ;
                    }
                }
                else
                {
                    availability.EarliestAvailableDateFormatted = "";
                }
            }
            return availability;
        }
Example #12
0
 public static Document GetObjectFromFindDocXmlBsMarcLight(string xml)
 {
     var document = new Document();
     document.FillPropertiesLight(xml);
     return document;
 }