Esempio n. 1
0
        public HttpResponseMessage PutReserve(int reserveId)
        {
            #region Kontrol
            var reserve = reserveService.GetReserve(reserveId);
            if (reserve == null)
            {
                return(Request.CreateResponse(HttpStatusCode.NotFound, new { message = "Kiralama bulunamadı!" }));
            }
            //Başkasının kitabını güncellemesini engeller.
            var reserveObj = reserveService.GetBooksUserStillHave(User.Identity.GetUserId()).FirstOrDefault(e => e.ReserveId == reserveId);
            if (reserveObj == null)
            {
                return(Request.CreateResponse(HttpStatusCode.NotFound, new { message = "Kiralama bulunamadı!" }));
            }
            #endregion
            //Kitabın kopyasının durumunu Available yap.
            var bookId = reserveObj.BookIds;
            bookId.BookStatus = BookStatus.Available;
            bookIdService.UpdateBookId(bookId);
            //Kitapbın reserve durumuna geri dönüş tarihi ekle
            reserveObj.UserReturnedDate = DateTime.Now;
            reserveService.UpdateReserve(reserveObj);

            try
            {
                reserveService.SaveChanges();
                var viewModel = Mapper.Map <Reserve, ReserveViewModel>(reserveObj);
                return(Request.CreateResponse <IReserveViewModel>(System.Net.HttpStatusCode.Created, viewModel));
            }
            catch (Exception ex)
            {
                if (ex.InnerException != null)
                {
                    return(Request.CreateResponse(HttpStatusCode.BadRequest,
                                                  new { exeption = ex.Message, innerException = ex.InnerException.Message }));
                }
                else
                {
                    return(Request.CreateResponse(HttpStatusCode.BadRequest,
                                                  new { exeption = ex.Message }));
                }
            }
        }
Esempio n. 2
0
 public async Task <Reserve> GetReserve(Guid Id)
 {
     return(await _ReserveService.GetReserve(Id));
 }