Пример #1
0
 public async Task Add(UnicornModel item)
 {
     try
     {
         await _context.Unicorns.InsertOneAsync(item);
     }
     catch (Exception ex)
     {
         // log or manage the exception
         throw ex;
     }
 }
Пример #2
0
        public async Task <bool> UpdateUnicorn(string id, UnicornModel item)
        {
            try
            {
                ReplaceOneResult actionResult
                    = await _context.Unicorns
                      .ReplaceOneAsync(n => n.Id.Equals(id)
                                       , item
                                       , new UpdateOptions { IsUpsert = true });

                return(actionResult.IsAcknowledged &&
                       actionResult.ModifiedCount > 0);
            }
            catch (Exception ex)
            {
                // log or manage the exception
                throw ex;
            }
        }