public async Task <ActionResult <MakerEquipment> > PostMakerEquipment(MakerEquipmentDto entry) { var profile = await GetLoggedInProfile(); var dbEntry = SetUpMakerEquipment(entry, profile); await _context.SaveChangesAsync(); return(CreatedAtAction("Post", new { id = entry.Id }, _mapper.Map <MakerEquipmentDto>(dbEntry))); }
private MakerEquipment SetUpMakerEquipment(MakerEquipmentDto entry, DBModels.Profile profile) { MakerEquipment dbEntry = _mapper.Map <MakerEquipment>(entry); dbEntry.Profile = profile; if (dbEntry.Id > 0) { _context.Entry(dbEntry).State = EntityState.Modified; } else { _context.MakerEquipment.Add(dbEntry); } return(dbEntry); }
public async Task <IActionResult> PutMakerEquipment(int id, MakerEquipmentDto entry) { if (id != entry.Id) { return(BadRequest("Payload does not match identifier")); } var profile = await GetLoggedInProfile(); if (!await _context.MakerEquipment.AnyAsync(e => e.ProfileId == profile.Id && e.Id == entry.Id)) { return(NotFound()); } var dbEntry = _mapper.Map <MakerEquipment>(entry); _context.Entry(dbEntry).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!MakerEquipmentExists(id)) { return(NotFound()); } else { throw; } } return(Ok()); }