public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "post", Route = "reserveBook")] ReserveBook command,
            ILogger log)
        {
            try
            {
                var repo = new CosmosRepo(command.LibraryId);
                repo.StartTransaction();

                var copyToReserve = await repo.GetFreeCopy(new BrandId(command.BrandId));

                var reservation = new Reservation(new ReaderId(command.ReaderId), copyToReserve.CopyId);
                copyToReserve.Block(new OwnerId(reservation.ReservationId));

                repo.Create(reservation);
                await repo.ExecuteAsync();

                return(new OkObjectResult(new { reservationId = reservation.ReservationId }));
            }
            catch (Exception e)
            {
                log.LogError(e, e.StackTrace);

                throw;
            }
        }
示例#2
0
        public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "post", Route = "copies")] AddCopies command,
            ILogger log)
        {
            try
            {
                var repo = new CosmosRepo(command.LibraryId);
                repo.StartTransaction();

                foreach (var copyNumber in command.CopyNumbers)
                {
                    var copy = new Copy(new BrandId(command.BrandId), copyNumber);
                    repo.Create(copy);
                }

                await repo.ExecuteAsync();

                return(new OkResult());
            }
            catch (Exception e)
            {
                log.LogError(e, e.StackTrace);

                throw;
            }
        }
        public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "post", Route = "borrowBook")] BorrowBook command,
            ILogger log)
        {
            try
            {
                var repo = new CosmosRepo(command.LibraryId);
                repo.StartTransaction();

                var(reservation, copy) = await repo.GetReservationToBorrow(
                    new ReaderId(command.ReaderId),
                    new ReservationId(command.ReservationId));

                var borrow = reservation.Borrow();
                copy.ChangeOwner(new OwnerId(borrow.BorrowId));

                repo.Create(borrow);
                await repo.ExecuteAsync();

                return(new OkObjectResult(new { borrowId = borrow.BorrowId }));
            }
            catch (Exception e)
            {
                log.LogError(e, e.StackTrace);

                throw;
            }
        }