Esempio n. 1
0
        public HttpResponseMessage AcceptBorrowRequest(BorrowRequestViewModel model)
        {
            if (!ModelState.IsValid)
            {
                _logger.Error($"BooksController/AcceptBorrowRequest Bad request: From={model.From},BookId={model.BookId}");
                HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.BadRequest);
                return(response);
            }
            string loggedInUserId = RequestContext.Principal.Identity.GetUserId();

            try
            {
                _bookService.AcceptBorrowBookRequest(model.From, loggedInUserId, model.BookId);
                HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK);
                return(response);
            }
            catch (Exception e)
            {
                _logger.Error($"BooksController/AcceptBorrowRequest Message={e.Message}");
                HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.InternalServerError, new { Message = e.Message });
                return(response);
            }
        }