Ejemplo n.º 1
0
        public void RemoveFavorite(Document document, UserInfo user)
        {
            var favs = GetFavoritesForUser(user);
            favs.Remove(document.DocumentNumber);

            SaveFavorites(favs, user);
        }
Ejemplo n.º 2
0
        private List<string> GetFavoritesForUser(UserInfo user)
        {
            var file = _pathProvider.GetFavoritesPath(user.Id);

            if(!File.Exists(file)) return new List<string>();

            List<string> favoritesForUser = File.ReadAllText(file).Split(';').Where(f => !String.IsNullOrEmpty(f)).ToList();
            return favoritesForUser;
        }
Ejemplo n.º 3
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;
        }
Ejemplo n.º 4
0
        public void RemoveReservation(Reservation res, UserInfo user)
        {
            var reservations = GetReservationsForUser(user);

            reservations.Remove(res);

            GetReservationsForUser(user).Remove(res);

            var flkjgd = GetReservationsForUser(user);

            var ldkjgf = "";
        }
Ejemplo n.º 5
0
        public void LoanTest()
        {
            const string userId = "164916";
            var user = new UserInfo { BorrowerId = userId };
            user.FillProperties(getUserLoansXml());

            Assert.Equal("*****@*****.**", user.Email);
            Assert.Equal("530185", user.Loans.ElementAt(0).AdminisrtativeDocumentNumber);
            Assert.Equal("1001 filmer du må se før du dør", user.Loans.ElementAt(0).DocumentTitle);
            Assert.Equal("Hovedbiblioteket", user.Loans.ElementAt(0).SubLibrary);
            Assert.Equal("15.08.2012", user.Loans.ElementAt(0).OriginalDueDate);
            Assert.Equal("4 uker", user.Loans.ElementAt(0).ItemStatus);
            Assert.Equal("18.07.2012", user.Loans.ElementAt(0).LoanDate);
            Assert.Equal("15:04", user.Loans.ElementAt(0).LoanHour);
            Assert.Equal("15.08.2012", user.Loans.ElementAt(0).DueDate);

        }
Ejemplo n.º 6
0
        public void FineTest()
        {
            const string userId = "159222";
            var user = new UserInfo { BorrowerId = userId };
            user.FillProperties(getUserXml());

            Assert.Equal("08.02.2007", user.Fines.ElementAt(0).Date);
            Assert.Equal("Ikke betalt ", user.Fines.ElementAt(0).Status);
            Assert.Equal('D', user.Fines.ElementAt(0).CreditDebit);
            Assert.Equal(30.00 , user.Fines.ElementAt(0).Sum);
            Assert.Equal("Nytt lånekort", user.Fines.ElementAt(0).Description);


            Assert.Equal(2, user.Fines.Count());
            Assert.Equal("19.03.2007", user.Fines.ElementAt(1).Date);
            Assert.Equal("For sent levert", user.Fines.ElementAt(1).Description);
            Assert.Equal("000230544", user.Fines.ElementAt(1).DocumentNumber);
            Assert.Equal("Gift", user.Fines.ElementAt(1).DocumentTitle);


        }
Ejemplo n.º 7
0
        public void PropertiesTest()
        {
            const string userId = "159222";
            var user = new UserInfo { BorrowerId = userId };
            user.FillProperties(getUserXml());
            Assert.Equal(userId, user.BorrowerId);
            Assert.Equal("STV000060009", user.Id);

            Assert.Equal("60.00", user.Balance);
            Assert.Equal("350.00", user.CashLimit);
            Assert.Equal("91562303", user.CellPhoneNumber);
            Assert.Equal("4019 STAVANGER", user.CityAddress);
            Assert.Equal("09.04.1989", user.DateOfBirth);
            Assert.Equal("*****@*****.**", user.Email);
            Assert.Equal("Hovedbibl.", user.HomeLibrary);
            Assert.Equal("51536695", user.HomePhoneNumber);
            Assert.Equal("Sindre Haaland", user.Name);
            Assert.Equal("Sindre Haaland", user.PrefixAddress);
            Assert.Equal("Bakkesvingen 8", user.StreetAddress);
            Assert.Equal("4019", user.Zip); 

        }
Ejemplo n.º 8
0
 private void SaveFavorites(List<string> favs, UserInfo user)
 {
     var file = _pathProvider.GetFavoritesPath(user.Id);
     File.WriteAllText(file, String.Join(";", favs));
 }
Ejemplo n.º 9
0
        public IEnumerable<Favorite> GetFavorites(UserInfo user)
        {
            var favoritesForUser = GetFavoritesForUser(user);

            return favoritesForUser.Select(docId => new Favorite{User = user, Document = _documents.GetDocument(docId, true)});
        }
Ejemplo n.º 10
0
        private bool AuthenticateUser(ref UserInfo user, string userId, string verification)
        {

            const Operation function = Operation.AuthenticateUser;
            var options = new Dictionary<string, string> { { "bor_id", userId }, { "verification", verification } };
            
            var authenticationDoc = GetDocumentFromAleph(function, options);

            if (authenticationDoc != null && authenticationDoc.Root != null)
            {

                var xElement = authenticationDoc.Root.DescendantsAndSelf("z303").FirstOrDefault();
                user.IsAuthorized = xElement != null;

            }

            return user.IsAuthorized;
        }
Ejemplo n.º 11
0
        public UserInfo GetUserInformation(string userId, string verification)
        {
            var user = new UserInfo { BorrowerId = userId };
            
            if (!AuthenticateUser(ref user, userId, verification))
            {
                return null;
            }

            const Operation function = Operation.UserInformation;
            var options = new Dictionary<string, string> { { "bor_id", userId }, { "verification", verification } };
           
            var userXDoc = GetDocumentFromAleph(function, options);

            user.FillProperties(userXDoc.ToString());
            
            return user;
        }
Ejemplo n.º 12
0
 public IEnumerable<Reservation> GetReservations(UserInfo user)
 {
     return GetReservationsForUser(user);
 }
Ejemplo n.º 13
0
 private List<Reservation> GetReservationsForUser(UserInfo user)
 {
     return user.Reservations.ToList();
 }
Ejemplo n.º 14
0
 public bool IsReserved(Reservation res, UserInfo user)
 {
     return GetReservationsForUser(user).Contains(res);
 }
Ejemplo n.º 15
0
 public void AddReservation(Reservation res, UserInfo user)
 {
     GetReservationsForUser(user).Add(res);
 }
Ejemplo n.º 16
0
 public bool IsFavorite(Document document, UserInfo user)
 {
     return GetFavoritesForUser(user).Contains(document.DocumentNumber);
 }
Ejemplo n.º 17
0
 public AlephUserIdentity(string username, string password, UserInfo userInfo)
 {
     UserName = username;
     Password = password;
     UserInfo = userInfo;
 }
Ejemplo n.º 18
0
        private IEnumerable<Notification> GetNotification(UserInfo user)
        {
            var notifications = new List<Notification>();

            if (user.Loans != null)
            {
                foreach (var loan in user.Loans)
                {
                    var day = Convert.ToInt32(loan.DueDate.Substring(0, 2));
                    var month = Convert.ToInt32(loan.DueDate.Substring(3, 2));
                    var year = Convert.ToInt32(loan.DueDate.Substring(6, 4));

                    var dueDate = new DateTime(year, month, day);
                    var today = DateTime.Now;

                    TimeSpan span = dueDate.Subtract(today);
                    var timeLeft = span.Days;

                    if (timeLeft > 0 && timeLeft < 4)
                    {
                        notifications.Add(new Notification
                                              {
                                                  Type = "Loan",
                                                  Title = loan.DocumentTitle + " forfaller snart",
                                                  DocumentTitle = loan.DocumentTitle,
                                                  Content =
                                                      "Lånet forfaller om mindre enn " + timeLeft +
                                                      " dager. Lever eller forny " +
                                                      "lånet for å unngå å få gebyr."
                                              });
                    }
                    else if (timeLeft == 0)
                    {
                        notifications.Add(new Notification
                                              {
                                                  Type = "Loan",
                                                  Title = loan.DocumentTitle + " forfaller snart",
                                                  DocumentTitle = loan.DocumentTitle,
                                                  Content = "Lånet forfaller om mindre ett døgn. Lever eller forny " +
                                                            "lånet for å unngå å få gebyr."
                                              });
                    }
                    else if (timeLeft < 0)
                    {
                        notifications.Add(new Notification
                                              {
                                                  Type = "Fine",
                                                  Title = loan.DocumentTitle + " skulle vært levert",
                                                  DocumentTitle = loan.DocumentTitle,
                                                  Content =
                                                      "Lånet har forfalt. Ved å fornye eller levere tilbake innen forfallsdato unngår du gebyr."
                                              });

                    }

                }

            }

            if (user.Reservations != null)
            {
                foreach (var reservation in user.Reservations)
                {
                    if (reservation.HoldRequestEnd != "")
                    {
                        notifications.Add(new Notification
                                              {
                                                  Type = "Reservation",
                                                  Title = reservation.DocumentTitle + " er klar til henting.",
                                                  DocumentTitle = reservation.DocumentTitle,
                                                  Content = "Den kan hentes på " + reservation.PickupLocation + " innen " + reservation.HoldRequestEnd,
                                              });
                    }
                }
            }

            return notifications;
        }