コード例 #1
0
        public async Task <IActionResult> PutPaymentDetail(int id, PaymentDetail paymentDetail)
        {
            if (id != paymentDetail.PMId)
            {
                return(BadRequest());
            }

            _context.Entry(paymentDetail).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PaymentDetailExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
コード例 #2
0
        public async Task <IHttpActionResult> Delete(int id)
        {
            using (var context = new CnBContext())
            {
                var review = await context.reviews.FirstOrDefaultAsync(r => r.Id == id);

                if (review == null)
                {
                    return(NotFound());
                }

                context.reviews.Remove(review);
                await context.SaveChangesAsync();
            }
            return(Ok());
        }
コード例 #3
0
        public async Task <IHttpActionResult> Post([FromBody] ReviewViewModel review)
        {
            using (var context = new CnBContext())
            {
                var book = await context.books.FirstOrDefaultAsync(b => b.Id == review.BookId);

                if (book == null)
                {
                    return(NotFound());
                }

                var newReview = context.reviews.Add(new Review
                {
                    BookId      = book.Id,
                    Description = review.Description,
                    Rating      = review.Rating
                });

                await context.SaveChangesAsync();

                return(Ok(new ReviewViewModel(newReview)));
            }
        }