public async Task <IActionResult> Update(string lawnId, LawnForUpdate updatedLawn) { try { await _lawnService.Update(lawnId, updatedLawn); return(Ok()); } catch (LawnNotFoundException) { return(NotFound()); } }
public async Task Update(string lawnId, LawnForUpdate updatedLawn) { var lawn = await GetLawnAsync(lawnId); lawn.Id = lawnId; lawn.Name = updatedLawn.Name; lawn.Description = updatedLawn.Description; lawn.ImageUrl = updatedLawn.ImageUrl; lawn.UpdatedDate = DateTime.UtcNow; var result = await _lawns.ReplaceOneAsync(l => l.Id == lawnId, lawn); if (result.MatchedCount == 0) { throw new LawnNotFoundException(lawnId); } }