コード例 #1
0
		public async Task<IHttpActionResult> PutRating(int id, Rating rating)
		{
			if (!ModelState.IsValid)
			{
				return BadRequest(ModelState);
			}

			if (id != rating.Id)
			{
				return BadRequest();
			}

			_db.Entry(rating).State = EntityState.Modified;

			try
			{
				await _db.SaveChangesAsync();
			}
			catch (DbUpdateConcurrencyException)
			{
				if (!RatingExists(id))
				{
					return NotFound();
				}
				throw;
			}

			return StatusCode(HttpStatusCode.NoContent);
		}
コード例 #2
0
		public async Task<IHttpActionResult> PostRating(Rating rating)
		{
			if (!ModelState.IsValid)
			{
				return BadRequest(ModelState);
			}

			_db.Ratings.Add(rating);
			await _db.SaveChangesAsync();

			return CreatedAtRoute("DefaultApi", new {id = rating.Id}, rating);
		}