示例#1
0
        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);
            }
        }
示例#2
0
 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);
     }
 }