public async Task <IActionResult> PostLectureItem([FromBody] Lecture lectureItem) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } else if (lectureExists(lectureItem.ID)) { return(await GetLecture(lectureItem.ID)); } _context.Lectures.Add(lectureItem); await _context.SaveChangesAsync(); return(CreatedAtAction(nameof(GetLecture), new { id = lectureItem.ID }, lectureItem)); }
public async Task <IActionResult> AddPackageDependency([FromRoute] int id, [FromRoute] int rid) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var packages = _context.GetFullTable <Package>(); var packageItem = await packages.SingleOrDefaultAsync(m => m.ID == id); var rPackageItem = await packages.SingleOrDefaultAsync(m => m.ID == rid); if (packageItem == null || rPackageItem == null) { return(NotFound()); } if (!packageItem.Dependencies.Contains(rPackageItem)) { try { packageItem.Dependencies.Add(rPackageItem); _context.Packages.Update(packageItem); await _context.SaveChangesAsync(); } catch (Exception e) { Tracer.TraceMessage(e.Message); return(StatusCode(500)); } } packageItem.Version++; return(Ok(packageItem)); }
public async Task <IActionResult> PutArtifact([FromBody] Artifact artifact) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } else if (!artifactExists(artifact.ID)) { return(NotFound($"Artifact with id {artifact.ID} not found!")); } var toChange = _context.Artifacts.Single(ar => ar.ID == artifact.ID); try { var backup = generateBackup(toChange); _context.ArtifactsBackup.Add(backup); toChange.InstallAction = string.IsNullOrWhiteSpace(artifact.InstallAction) ? toChange.InstallAction : artifact.InstallAction; toChange.RemoveAction = string.IsNullOrWhiteSpace(artifact.RemoveAction) ? toChange.RemoveAction : artifact.RemoveAction; toChange.SwitchAction = string.IsNullOrWhiteSpace(artifact.SwitchAction) ? toChange.SwitchAction : artifact.SwitchAction; toChange.UnswitchAction = string.IsNullOrWhiteSpace(artifact.UnswitchAction) ? toChange.UnswitchAction : artifact.UnswitchAction; toChange.UpgradeAction = string.IsNullOrWhiteSpace(artifact.UpgradeAction) ? toChange.UpgradeAction : artifact.UpgradeAction; toChange.Version++; _context.Artifacts.Update(toChange); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { throw; } return(Ok(toChange)); }