public async Task <IHttpActionResult> PostFileAllocationAsync(FileAllocation fileAllocation) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { _fileAllocationService.Add(fileAllocation); await _fileAllocationService.CommitAsync(); } catch (DbUpdateException) { if (await FileAllocationExistsAsync(fileAllocation.Id)) { return(Conflict()); } else { throw; } } return(CreatedAtRoute("ApiRoute", new { id = fileAllocation.Id }, fileAllocation)); }
public async Task <IHttpActionResult> PutFileAllocationAsync(Guid id, FileAllocation fileAllocation) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != fileAllocation.Id) { return(BadRequest()); } try { _fileAllocationService.Update(fileAllocation); await _fileAllocationService.CommitAsync(); } catch (DbUpdateConcurrencyException) { if (!await FileAllocationExistsAsync(id)) { return(NotFound()); } else { throw; } } return(Ok()); }