public async Task <ActionResult <MongodbBattery> > Post([FromBody] MongodbBattery Battery) { Battery.Id = await _repo.GetNextId(); await _repo.Create(Battery); return(new OkObjectResult(Battery)); }
public async Task <ActionResult <MongodbBattery> > Put(long id, [FromBody] MongodbBattery Battery) { var BatteryFromDb = await _repo.GetBattery(id); if (BatteryFromDb == null) { return(new NotFoundResult()); } Battery.Id = BatteryFromDb.Id; Battery.InternalId = BatteryFromDb.InternalId; await _repo.Update(Battery); return(new OkObjectResult(Battery)); }
public async Task <bool> Update(MongodbBattery Battery) { ReplaceOneResult updateResult = await _context .Batteries .ReplaceOneAsync( filter : g => g.Id == Battery.Id, replacement : Battery); return(updateResult.IsAcknowledged && updateResult.ModifiedCount > 0); }
public async Task Create(MongodbBattery Battery) { await _context.Batteries.InsertOneAsync(Battery); }