Example #1
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 });
        }
Example #2
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
            });
        }