Example #1
0
        public IHttpActionResult GetTransactions(int userID, BookTransactionStatus?status = null)
        {
            List <BookTransaction> bookTransactions = new List <BookTransaction>();

            if (status == null)
            {
                bookTransactions = BookTransactionRepository.GetCacheBookTransactions().Where(x => x.UserID == userID).ToList();
                return(Json(bookTransactions.Select(x => new
                {
                    BookName = BookRepository.GetCacheBooks().FirstOrDefault(y => y.ID == x.BookID).Name,
                    x.DateOfReserved,
                    x.DateOfReturned
                })));
            }
            else
            {
                bookTransactions = BookTransactionRepository.GetCacheBookTransactions().Where(x => x.UserID == userID && x.Status == status).ToList();
                return(Json(bookTransactions.Select(x => new
                {
                    BookName = BookRepository.GetCacheBooks().FirstOrDefault(y => y.ID == x.BookID).Name,
                    x.DateOfReserved,
                    x.DateOfReturned
                })));
            }
        }
Example #2
0
        public IHttpActionResult ReserveBook(int bookID, int userID)
        {
            try
            {
                BookStock bs = BookStockRepository.GetCacheBookStocks().FirstOrDefault(x => x.BookID == bookID && x.Status == BookStockStatus.Available);
                if (bs == null)
                {
                    //The stocks of the book you have researched for is insufficient
                    return(Json("0"));
                }
                int returnedCount = BookTransactionRepository.GetCacheBookTransactions().Where(x => x.UserID == userID && x.Status != BookTransactionStatus.Returned).Count();
                if (returnedCount == 3)
                {
                    return(Json("-2"));
                }

                BookTransaction bt = new BookTransaction();
                bt.BookID                  = bookID;
                bt.DateOfReserved          = DateTime.Now;
                bt.ExpirationOfReserveDate = DateTime.Now.AddDays(7);
                bt.UserID                  = userID;
                bt.Status                  = BookTransactionStatus.Reserved;

                BookTransactionRepository btr = new BookTransactionRepository();
                btr.AddEntity(bt);

                bs.Status = BookStockStatus.Reserved;
                BookStockRepository bsr = new BookStockRepository();
                bsr.UpdateEntity(bs);

                LogRepository.NewLog(bookID, userID);
            }
            catch (Exception)
            {
                return(Json("-1"));
            }

            return(Json("1"));
        }
Example #3
0
        //IGenericRepository IUnitOfWork.Repository => throw new NotImplementedException();

        public UnitOfWork()
        {
            dbContext                  = new DatabaseContext();
            Repository                 = new GenericRepository(dbContext);
            SchoolRepository           = new SchoolRepository(dbContext);
            ExceptionLoggerRepository  = new ExceptionLoggerRepository(dbContext);
            ApiLogRepository           = new ApiLogRepository(dbContext);
            ImageFileTypeRepository    = new ImageFileTypeRepository(dbContext);
            AssessmentRepository       = new AssessmentRepository(dbContext);
            AttendanceRepository       = new AttendanceRepository(dbContext);
            BookRepository             = new BookRepository(dbContext);
            BookTransactionRepository  = new BookTransactionRepository(dbContext);
            EventRepository            = new EventRepository(dbContext);
            HomeworkRepository         = new HomeworkRepository(dbContext);
            ImageFileUrlRepository     = new ImageFileUrlRepository(dbContext);
            ParentRepository           = new ParentRepository(dbContext);
            StandardRepository         = new StandardRepository(dbContext);
            StudentRepository          = new StudentRepository(dbContext);
            SubjectRepository          = new SubjectRepository(dbContext);
            TeacherRepository          = new TeacherRepository(dbContext);
            YearRepository             = new YearRepository(dbContext);
            OperationalStaffRepository = new OperationalStaffRepository(dbContext);
        }