public async Task<IActionResult> PutSzkolenieCel(int id, SzkolenieCel szkolenieCel) { if (id != szkolenieCel.ID) { return BadRequest(); } _context.Entry(szkolenieCel).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!SzkolenieCelExists(id)) { return NotFound(); } else { throw; } } return NoContent(); }
public async Task<ActionResult<SzkolenieCel>> PostSzkolenieCel(SzkolenieCel szkolenieCel) { var temp = _context.SzkolenieCele.Where(w => w.KwalifikacjaID == szkolenieCel.KwalifikacjaID && w.WydzialID == szkolenieCel.WydzialID ) .AsNoTracking() .ToList(); if (!temp.Any()) { _context.SzkolenieCele.Add(szkolenieCel); await _context.SaveChangesAsync(); return CreatedAtAction("GetSzkolenieCel", new { id = szkolenieCel.ID }, szkolenieCel); } else { szkolenieCel.ID= temp.FirstOrDefault().ID; _context.Entry(szkolenieCel).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!SzkolenieCelExists(szkolenieCel.ID)) { return NotFound(); } else { throw; } } return CreatedAtAction("GetSzkolenieCel", new { id = szkolenieCel.ID }, szkolenieCel); } }