Beispiel #1
0
        public async Task <int> SetRemainingOrderQuantity(BookStatusViewModel bookStatus)
        {
            BookingOrder model = await BookingOrderLogic.ReadModelById(bookStatus.BookingOrderId);

            int total = 0;

            foreach (BookingOrderDetail item in model.DetailConfirms)
            {
                total += item.Total;
            }

            if (model.InitialOrderQuantity == null)
            {
                model.InitialOrderQuantity = model.OrderQuantity;
            }

            var orderQuantity          = model.OrderQuantity;
            var orderCanceledOrDeleted = Math.Abs(total - orderQuantity);
            var nowDateAndTime         = DateTimeOffset.Now;

            model.OrderQuantity = total;
            var blockingPlan = await BlockingPlanLogic.searchByBookingOrderId(bookStatus.BookingOrderId);

            if (bookStatus.StatusBooking == StatusConst.CANCEL_REMAINING)
            {
                if (blockingPlan != null)
                {
                    if (total == 0)
                    {
                        BlockingPlanLogic.UpdateModelStatus(blockingPlan.Id, blockingPlan, BlockingPlanStatus.CANCELLED);
                    }
                    else
                    {
                        BlockingPlanLogic.UpdateModelStatus(blockingPlan.Id, blockingPlan, BlockingPlanStatus.CHANGED);
                    }
                }

                model.CanceledBookingOrder = orderCanceledOrDeleted;
                model.CanceledDate         = nowDateAndTime;
            }
            else if (bookStatus.StatusBooking == StatusConst.DELETE_REMAINING)
            {
                if (blockingPlan != null)
                {
                    if (total == 0)
                    {
                        BlockingPlanLogic.UpdateModelStatus(blockingPlan.Id, blockingPlan, BlockingPlanStatus.EXPIRED);
                    }
                    else
                    {
                        BlockingPlanLogic.UpdateModelStatus(blockingPlan.Id, blockingPlan, BlockingPlanStatus.CHANGED);
                    }
                }

                model.ExpiredBookingOrder = orderCanceledOrDeleted;
                model.ExpiredDeletedDate  = nowDateAndTime;
            }

            return(await Update(bookStatus.BookingOrderId, model));
        }
Beispiel #2
0
        public async Task <ActionResult> Details(int id)
        {
            if (id == 0)
            {
                return(null);
            }
            BookStatusViewModel bvm = new BookStatusViewModel();
            var book = await _db.Books.Where(a => a.ID == id).SingleOrDefaultAsync();

            var loanStatus = await _loanservice.GetBookLoanStatus(id);

            if (book != null)
            {
                bvm.ID            = book.ID;
                bvm.Title         = book.Title;
                bvm.Author        = book.Author;
                bvm.Genre         = book.Genre;
                bvm.Location      = book.Location;
                bvm.YearPublished = book.YearPublished;
                bvm.Edition       = book.Edition;
                bvm.Genre         = book.Genre;
                bvm.DateCreated   = book.DateCreated;
                bvm.DateUpdated   = book.DateUpdated;

                bvm.Status     = loanStatus.Status.ToString().ToUpper();
                bvm.DateLoaned = loanStatus.DateLoaned;
                bvm.DateReturn = loanStatus.DateReturn;
            }
            BookLoan.Views.Book.DetailsModel detailsModel = new DetailsModel(_db);
            loanStatus.Status                = loanStatus.Status.ToUpper();
            detailsModel.BookViewModel       = bvm;
            detailsModel.BookStatusViewModel = loanStatus;

            return(View(detailsModel));
        }
Beispiel #3
0
        public async Task <IActionResult> SetRemainingOrderQuantity([FromBody] BookStatusViewModel bookStatus)
        {
            try
            {
                VerifyUser();

                await Facade.SetRemainingOrderQuantity(bookStatus);

                return(NoContent());
            }
            catch (Exception e)
            {
                Dictionary <string, object> Result =
                    new ResultFormatter(ApiVersion, General.INTERNAL_ERROR_STATUS_CODE, e.Message)
                    .Fail();
                return(StatusCode(General.INTERNAL_ERROR_STATUS_CODE, Result));
            }
        }
        //[Authorize(Policy = "BookReadAccess")]
        public async Task <ActionResult> Details(int id)
        {
            if (id == 0)
            {
                return(NotFound(new { id }));
            }
            try
            {
                BookStatusViewModel bvm = new BookStatusViewModel();
                var book = await _db.Books.Where(a => a.ID == id).SingleOrDefaultAsync();

                //var loanStatus = await _loanservice.GetBookLoanStatus(id);
                if (book != null)
                {
                    bvm.ID            = book.ID;
                    bvm.Title         = book.Title;
                    bvm.Author        = book.Author;
                    bvm.Genre         = book.Genre;
                    bvm.Location      = book.Location;
                    bvm.YearPublished = book.YearPublished;
                    bvm.Edition       = book.Edition;
                    bvm.Genre         = book.Genre;
                    bvm.ISBN          = book.ISBN;
                    bvm.DateCreated   = book.DateCreated;
                    bvm.DateUpdated   = book.DateUpdated;

                    //bvm.Status = loanStatus.Status.ToString().ToUpper();
                    //bvm.DateLoaned = loanStatus.DateLoaned;
                    //bvm.DateReturn = loanStatus.DateReturn;
                }
                //BookLoan.Views.Book.DetailsModel detailsModel = new DetailsModel(_db);
                //loanStatus.Status = loanStatus.Status.ToUpper();
                //detailsModel.BookViewModel = bvm;
                //detailsModel.BookStatusViewModel = loanStatus;

                return(Ok(bvm));
            }
            catch (Exception ex)
            {
                return(BadRequest(new { ex.Message }));
            }
        }
        public async Task <AccountResult> MakeABookRequest(BookStatusViewModel statusViewModel)
        {
            var resultMessage = new AccountResult();


            var book = await _dataContext.Books.FindAsync(statusViewModel.BookId);

            if (book == null)
            {
                throw new RestException(HttpStatusCode.NotFound, new { book = "Book Not Found" });
            }

            if (statusViewModel.requestCancelBook == "request")
            {
                if (book.isAvailable == false)
                {
                    throw new RestException(HttpStatusCode.NotFound, new { book = "Book Not Available" });
                }

                book.isRequested = true;
                book.isAvailable = false;
                book.requestedBy = statusViewModel.UserId;
            }
            else
            {
                book.isRequested = false;
                book.isAvailable = true;
                book.requestedBy = null;
            }

            var success = _dataContext.SaveChanges() > 0;

            if (success)
            {
                return(resultMessage);
            }

            throw new Exception("Problem Saving Changes");
        }
Beispiel #6
0
        public void CreateNewLoanTest()
        {
            var bookService = new BookService(context, null);
            var loanService = new LoanService(context, null, contextAccessor, bookService, null, null);

            // create book
            var book = new BookViewModel()
            {
                ID = 1, Author = "W.Smith", Title = "Rivers Run Dry", YearPublished = 1954
            };
            var bookSaveAction = bookService.SaveBook(book).GetAwaiter();

            bookSaveAction.GetResult();

            // generate and post a sample loan.
            LoanViewModel lvm = loanService.CreateNewBookLoan(book.ID);

            lvm.DateLoaned = DateTime.Now;
            lvm.DateDue    = DateTime.Now.AddDays(7);
            lvm.LoanedBy   = "*****@*****.**";
            var loanSaveAction = loanService.SaveLoan(lvm).GetAwaiter();

            loanSaveAction.GetResult();

            // test the book was saved as an existing loan.
            var loanListAction = loanService.GetBookLoans(book.ID).GetAwaiter();
            List <LoanViewModel> loanListResult = loanListAction.GetResult();

            Assert.AreEqual(loanListResult.Count, 1);

            // test loan status.
            var loanStatusAction = loanService.GetBookLoanStatus(book.ID).GetAwaiter();
            BookStatusViewModel loanStatusReult = loanStatusAction.GetResult();

            Assert.AreEqual(loanStatusReult.Status, "On Loan");

            // return loan.
            var loanReturnAction = loanService.GetReturnLoan(book.ID).GetAwaiter();

            (LoanViewModel, BookViewModel)loanReturnResult = loanReturnAction.GetResult();
            Assert.IsTrue(loanReturnResult.Item1.DateReturn > lvm.DateLoaned);
            Assert.AreEqual(loanReturnResult.Item1.LoanedBy, "");
            Assert.AreEqual(loanReturnResult.Item1.DateDue.DayOfYear, lvm.DateDue.DayOfYear);

            // get loan details
            var           loanDetailAction = loanService.GetLoan(lvm.ID).GetAwaiter();
            LoanViewModel loanDetailResult = loanDetailAction.GetResult();

            loanDetailResult.DateReturn = DateTime.Now;

            // post loan return data
            var loanUpdateAction = loanService.UpdateLoan(loanDetailResult).GetAwaiter();

            loanUpdateAction.GetResult();

            // re-test loan status
            var loanReturnStatusAction = loanService.GetBookLoanStatus(book.ID).GetAwaiter();
            BookStatusViewModel loanReturnStatusResult = loanReturnStatusAction.GetResult();

            Assert.AreEqual(loanReturnStatusResult.Status, "Available");

            Assert.Pass();
        }
        public async Task <ActionResult> MakeABookRequest(BookStatusViewModel statusViewModel)
        {
            await _bookStatus.MakeABookRequest(statusViewModel);

            return(Ok());
        }