Beispiel #1
0
 public void IncreaseSignout(AvailableBookModel data)
 {
     try
     {
         var result = _db.Library_Book.Where(r => r.LibraryBookSId == data.Id).FirstOrDefault();
         if (result != null)
         {
             BookSignedOut info = new BookSignedOut
             {
                 LibraryBookSId = data.Id.Value,
                 MemberId       = data.MemberId,
                 WhenSignedOut  = DateTime.UtcNow,
                 WhenReturned   = null
             };
             _db.BookSignedOuts.Add(info);
             result.Signout = result.Signout == null ? 1 : result.Signout.Value + 1;
             _db.SaveChangesAsync();
         }
     }
     catch (Exception ex)
     {
         ErrorLog.GetDefault(null).Log(new Error(ex));
         throw;
     }
 }
Beispiel #2
0
        public async Task <ActionResult> Return(int id, int libraryId, int bookId)
        {
            AvailableBookModel model = new AvailableBookModel();

            model.Id        = id;
            model.LibraryId = libraryId;
            model.BookId    = bookId;
            return(View(model));
        }
Beispiel #3
0
        public async Task <ActionResult> Return(AvailableBookModel data)
        {
            bool canReturn = _cm.CanReturn(data);

            if (canReturn)
            {
                _cm.DeacreasingSignout(data);
            }
            return(RedirectToAction("List", "LibraryBook", new { id = data.Id }));
        }
Beispiel #4
0
        public async Task <ActionResult> Signout(AvailableBookModel data)
        {
            var  t                =;
            bool isMemberExist    = _cm.IsMemberExist(data.MemberId);
            bool isAvailable      = _cm.IsAvailable(data);
            bool isMemberExceeded = _cm.IsMemberExceeded(data);

            if (isMemberExist && isAvailable)
            {
                _cm.IncreaseSignout(data);
            }
            return(RedirectToAction("List", "LibraryBook", new { id = data.Id }));
        }
Beispiel #5
0
 public bool IsAvailable(AvailableBookModel data)
 {
     try
     {
         var  result      = _db.Library_Book.Where(r => r.BookId == data.BookId && r.LibraryId == data.LibraryId).FirstOrDefault();
         bool isAvailable = result.TotalPurchasedByLibrary > (result.Signout == null ? 0 : result.Signout.Value) ? true : false;
         return(isAvailable);
     }
     catch (Exception ex)
     {
         ErrorLog.GetDefault(null).Log(new Error(ex));
         throw;
     }
 }
Beispiel #6
0
 public void DeacreasingSignout(AvailableBookModel data)
 {
     try
     {
         var result      = _db.Library_Book.Where(r => r.LibraryBookSId == data.Id).FirstOrDefault();
         var bookSignout = _db.BookSignedOuts.Where(r => r.MemberId == data.MemberId && r.LibraryBookSId == data.Id && r.WhenReturned == null).FirstOrDefault();
         if (result != null)
         {
             bookSignout.WhenReturned = DateTime.UtcNow;
             result.Signout           = result.Signout.Value - 1;
             _db.SaveChangesAsync();
         }
     }
     catch (Exception ex)
     {
         ErrorLog.GetDefault(null).Log(new Error(ex));
         throw;
     }
 }
Beispiel #7
0
 public bool CanReturn(AvailableBookModel data)
 {
     try
     {
         var result = _db.BookSignedOuts.Where(r => r.MemberId == data.MemberId && r.LibraryBookSId == data.Id && r.WhenReturned == null).FirstOrDefault();
         if (result == null)
         {
             return(false);
         }
         else
         {
             return(true);
         }
     }
     catch (Exception ex)
     {
         ErrorLog.GetDefault(null).Log(new Error(ex));
         throw;
     }
 }
Beispiel #8
0
 public bool IsMemberExceeded(AvailableBookModel data)
 {
     try
     {
         var result = _db.BookSignedOuts.Where(r => r.LibraryBookSId == data.Id && r.WhenReturned == null).ToList();
         if (result?.Count() >= 2)
         {
             return(false);
         }
         else
         {
             return(true);
         }
     }
     catch (Exception ex)
     {
         ErrorLog.GetDefault(null).Log(new Error(ex));
         throw;
     }
 }