コード例 #1
0
		public async Task<IHttpActionResult> PostSoundRecord(SoundRecord soundRecord)
		{
			if (!this.ModelState.IsValid)
				return BadRequest(this.ModelState);

			this.db.SoundRecords.Add(soundRecord);
			await this.db.SaveChangesAsync();

			return CreatedAtRoute("DefaultApi", new {id = soundRecord.Id}, soundRecord);
		}
コード例 #2
0
		public async Task<IHttpActionResult> PutSoundRecord(int id, SoundRecord soundRecord)
		{
			if (!this.ModelState.IsValid)
				return BadRequest(this.ModelState);

			if (id != soundRecord.Id)
				return BadRequest();

			this.db.Entry(soundRecord).State = EntityState.Modified;

			try
			{
				await this.db.SaveChangesAsync();
			}
			catch (DbUpdateConcurrencyException)
			{
				if (!SoundRecordExists(id))
					return NotFound();
				else
					throw;
			}

			return StatusCode(HttpStatusCode.NoContent);
		}