public IHttpActionResult CreateAcceptSwapReq(int id)
        {
            var resultRequest = db.Requests.Where(ww => ww.Id == id).FirstOrDefault();

            if (resultRequest == null)
            {
                return(NotFound());
            }
            else
            {
                resultRequest.RequestStatusId = RequestStatusEnum.AcceptSwap;
                db.Entry(resultRequest).State = EntityState.Modified;
                var userHaveBookCheck = db.UserHaveBooks.Where(uhb => uhb.UserId == resultRequest.SenderId && uhb.BookId == resultRequest.BookId).FirstOrDefault();
                if (userHaveBookCheck == null)
                {
                    return(StatusCode(HttpStatusCode.NotAcceptable));
                }
                var userWantBookCheck = db.UserWantBooks.Where(uwb => uwb.UserId == resultRequest.RecieverId && uwb.BookId == resultRequest.RequestedBookId).FirstOrDefault();
                if (userWantBookCheck == null)
                {
                    return(StatusCode(HttpStatusCode.NotAcceptable));
                }
                var temp = new UserHaveBook()
                {
                    BookId = userWantBookCheck.BookId, UserId = userWantBookCheck.UserId, BookConditionId = userHaveBookCheck.BookConditionId
                };
                var temp2 = new UserWantBook()
                {
                    BookId = userHaveBookCheck.BookId, UserId = userHaveBookCheck.UserId
                };
                db.Entry(temp).State              = EntityState.Added;
                db.Entry(temp2).State             = EntityState.Added;
                db.Entry(userHaveBookCheck).State = EntityState.Deleted;
                db.Entry(userWantBookCheck).State = EntityState.Deleted;

                return(Ok(resultRequest));
            }
        }
        public IHttpActionResult CreateAcceptSwapReq(int id)
        {
            var resultRequest = db.Requests.Where(ww => ww.Id == id).FirstOrDefault();

            if (resultRequest == null)
            {
                return(NotFound());
            }
            else
            {
                resultRequest.RequestStatusId = RequestStatusEnum.AcceptSwap;
                db.Entry(resultRequest).State = EntityState.Modified;
                var userHaveBookCheck = db.UserHaveBooks.Where(uhb => uhb.UserId == resultRequest.SenderId && uhb.BookId == resultRequest.BookId).FirstOrDefault();
                if (userHaveBookCheck == null)
                {
                    return(StatusCode(HttpStatusCode.NotAcceptable));
                }
                //var userWantBookCheck = db.UserWantBooks.Where(uwb => uwb.UserId == resultRequest.RecieverId && uwb.BookId == resultRequest.RequestedBookId).FirstOrDefault();
                //if(userWantBookCheck == null)
                //{
                //    return StatusCode(HttpStatusCode.NotAcceptable);

                //}
                // var temp = new UserHaveBook() { BookId = userWantBookCheck.BookId, UserId = userWantBookCheck.UserId , BookConditionId = userHaveBookCheck.BookConditionId};
                //var temp2 = new UserWantBook() { BookId = userHaveBookCheck.BookId, UserId = userHaveBookCheck.UserId };
                //var temp = new UserHaveBook() { BookId= userHaveBookCheck.BookId, UserId = userHaveBookCheck.UserId, BookConditionId = userHaveBookCheck.BookConditionId };
                //temp.UserId = resultRequest.RecieverId;
                //db.Entry(temp).State = EntityState.Added;
                //db.Entry(temp2).State = EntityState.Added;
                //;
                //db.Entry(userWantBookCheck).State = EntityState.Deleted;
                db.Entry(userHaveBookCheck).State = EntityState.Deleted;
                var temp = new UserHaveBook()
                {
                    BookId = userHaveBookCheck.BookId, UserId = userHaveBookCheck.UserId, BookConditionId = userHaveBookCheck.BookConditionId, DateOfAdded = DateTime.Now
                };
                //userHaveBookCheck.UserId = resultRequest.RecieverId.Value;
                db.Entry(temp).State = EntityState.Added;

                db.SaveChanges();
                resultRequest.RequestStatusId = RequestStatusEnum.AcceptSwap;
                db.Entry(resultRequest).State = EntityState.Modified;
                return(Ok(new
                {
                    resultRequest.Id,
                    resultRequest.DateOfMessage,
                    resultRequest.SenderId,
                    resultRequest.SendSwapUsertId,
                    resultRequest = new
                    {
                        resultRequest.RecieverUser.UserId,
                        resultRequest.RecieverUser.FirstName,
                        resultRequest.RecieverUser.LastName,
                        resultRequest.RecieverUser.PhotoUrl
                    },
                    SenderUser = new
                    {
                        resultRequest.SenderUser.UserId,
                        resultRequest.SenderUser.FirstName,
                        resultRequest.SenderUser.LastName,
                        resultRequest.SenderUser.PhotoUrl
                    },
                    RequestedBook = new
                    {
                        resultRequest.RequestedBook.Book_Id,
                        resultRequest.RequestedBook.Title,
                        resultRequest.RequestedBook.Photo_Url,
                    },
                    SendedBook = new
                    {
                        resultRequest.SendedBook.Book_Id,
                        resultRequest.SendedBook.Title,
                        resultRequest.SendedBook.Photo_Url,
                    },
                    RequestStatus = resultRequest.RequestStatusId
                }));
            }
        }