Ejemplo n.º 1
0
        /// <summary>
        /// Sets state of outstanding request to given document
        /// </summary>
        /// <param name="state">State of outstanding request</param>
        /// <param name="documentId">Given document id</param>
        public static void SetOutstanding(bool state, long documentId)
        {
            if (state)
            {
                string title = GetTakableById(documentId).Title;

                string message = title + " is not available now.";
                foreach (Patron p in UsersDataManager.GetQueueToDocument(documentId))
                {
                    NotificationsDataManager.AddNotification(new Notification()
                    {
                        PatronId = p.CardNumber, Message = message
                    });
                }
                message = "You have to return document " + title + ".";
                foreach (Patron p in UsersDataManager.GetPatronsCheckedByDocumentId(documentId))
                {
                    NotificationsDataManager.AddNotification(new Notification()
                    {
                        PatronId = p.CardNumber, Message = message
                    });
                }
            }
            DatabaseHelper.Execute("dbo.spTakable_SetOutstanding @State, @DocumentId", new { State = state, DocumentId = documentId });
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Returns document in the database
 /// </summary>
 /// <param name="documentId">Id of document that will be returned</param>
 /// <param name="patronId">Id of patron that returns the document</param>
 public static void ReturnDocument(long documentId, long patronId)
 {
     DatabaseHelper.Execute("dbo.spCopies_ReturnDocument @DocumentId, @UserId", new { DocumentId = documentId, UserId = patronId });
     Patron[] patrons = UsersDataManager.GetQueueToDocument(documentId);
     if (patrons.Length != 0)
     {
         Takable takable = GetTakableById(documentId);
         NotificationsDataManager.AddNotification(new Notification()
         {
             PatronId = patrons[0].CardNumber,
             Message  = takable.Title + " now waiting for you."
         });
         DatabaseHelper.Execute("dbo.spQueue_RemovePatronByDocumentId @DocumentId, @PatronId", new { DocumentId = documentId, PatronId = patronId });
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Check out document in database
        /// </summary>
        /// <param name="documentId">Id of document that will be checked out</param>
        /// <param name="patronId">Id of patron that checks out the document</param>
        public static void CheckOutDocument(long documentId, long patronId)
        {
            if (!IsAvailable(documentId, patronId))
            {
                return;
            }

            string patronType = UsersDataManager.GetPatronType(patronId);

            Takable takable = GetTakableById(documentId);

            long returningDate = takable.EvaluateReturnDate(DateManager.GetLong(DateTime.Today), patronType);

            long availableCopyId = DatabaseHelper.Query <long>("dbo.spCopies_GetAvailableCopies @BookId, @UserId", new { BookId = documentId, UserId = patronId }).FirstOrDefault();

            DatabaseHelper.Execute("dbo.spCopies_takeCopyWithReturningDate @CopyId, @UserId, @ReturningDate", new { CopyId = availableCopyId, UserId = patronId, ReturningDate = returningDate });
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Renews copy by given document id and patron id
        /// </summary>
        /// <param name="documentId">Given document id</param>
        /// <param name="patronId">Given patron id</param>
        public static void RenewCopy(long documentId, long patronId)
        {
            Copy[] copies = GetCopiesCheckedOutByPatron(patronId);
            Copy   copy   = null;

            foreach (Copy c in copies)
            {
                if (c.DocumentId == documentId && c.PatronId == patronId)
                {
                    copy = c;
                }
            }
            if (copy == null)
            {
                return;
            }
            string patronType = UsersDataManager.GetPatronType(patronId);

            if (copy.IsRenewed && patronType != "Guest")
            {
                return;
            }
            Takable takable = GetTakableById(documentId);

            if (takable.IsOutstanding)
            {
                return;
            }
            long returningDate = takable.EvaluateReturnDate(copy.ReturningDate, patronType);

            DatabaseHelper.Execute("dbo.spCopies_RenewDocument @DocumentId, @PatronId, @ReturningDate", new {
                DocumentId    = documentId,
                PatronId      = patronId,
                ReturningDate = returningDate
            });
        }