public async Task <bool> Update(string id, Jar item) { try { ReplaceOneResult actionResult = await _context.Jars.ReplaceOneAsync( n => n.Id.Equals(id), item, new UpdateOptions { IsUpsert = true }); return(actionResult.IsAcknowledged && actionResult.ModifiedCount > 0); } catch (Exception ex) { throw new ApplicationException("Error: " + ex.Message); } }
public async Task Add(Jar item) { try { if (item.Id == null || item.Id == ObjectId.Empty) { item.Id = ObjectId.GenerateNewId(); } await _context.Jars.InsertOneAsync(item); } catch (Exception ex) { throw new ApplicationException("Error: " + ex.Message); } }