예제 #1
0
 public async Task Commit()
 {
     try
     {
         // For some odd reasons, current LiteDB version does not support transaction
         using (LiteRepository _liteRepo = new LiteRepository(LiteDBLocation))
         {
             if (ToSave.Any() || ToModify.Any())
             {
                 IList <T> _combinedList = ToSave.Concat(ToModify).ToList();
                 _liteRepo.Upsert <T>(_combinedList, CollectionName);
             }
             if (ToRemove.Any())
             {
                 _liteRepo.Delete <T>(Query.Where("_id", id => ToRemove.Contains(id)), CollectionName);
             }
         }
         await Task.Run(() =>
         {
             ToSave.Clear();
             ToModify.Clear();
             ToRemove.Clear();
         });
     }
     catch (Exception ex)
     { throw ex; }
 }
예제 #2
0
 public bool Delete(T item)
 {
     using (var db = new LiteRepository(ConnectionString))
     {
         return(db.Delete <T>(item.Id));
     }
 }
예제 #3
0
 /// <summary>
 /// Delete entity based on _id key
 /// </summary>
 public bool Delete <T>(BsonValue id, string collectionName = null)
 {
     using (var db = new LiteRepository(_configService.ConnectionString))
     {
         return(db.Delete <T>(id, collectionName));
     }
 }
예제 #4
0
 public void Delete(int id)
 {
     using (var db = new LiteRepository(_pathToDb))
     {
         db.Delete <UserProfile>(id, CollectionName);
     }
 }
예제 #5
0
 /// <summary>
 /// Delete entity based on Query
 /// </summary>
 public int Delete <T>(Query query, string collectionName = null)
 {
     using (var db = new LiteRepository(_configService.ConnectionString))
     {
         return(db.Delete <T>(query, collectionName));
     }
 }
예제 #6
0
 /// <summary>
 /// Delete entity based on predicate filter expression
 /// </summary>
 public int Delete <T>(Expression <Func <T, bool> > predicate, string collectionName = null)
 {
     using (var db = new LiteRepository(_configService.ConnectionString))
     {
         return(db.Delete <T>(predicate, collectionName));
     }
 }
예제 #7
0
 public void Remove(string objectKey)
 {
     using (var db = new LiteRepository(_db.Context))
     {
         db.Delete <AluguelDbModel>(new BsonValue(objectKey));
     }
 }
예제 #8
0
 public void Delete(Guid id)
 {
     using (var repo = new LiteRepository(_connectionString))
     {
         repo.Delete <Todo>(t => t.Id == id);
     }
 }
예제 #9
0
 public int DeleteProfile(string profileName)
 {
     using (var repository = new LiteRepository(_connectionStringProvider.ConnectionString))
     {
         return(repository.Delete <InferenceProfile>(p => p.ProfileName == profileName));
     }
 }
예제 #10
0
 public bool Delete(Guid id)
 {
     using (var db = new LiteRepository(connectionString))
     {
         var result = db.Delete <Order>(x => x.OrderNumber == id);
         return(Convert.ToBoolean(result));
     }
 }
예제 #11
0
 public IActionResult Delete(string id)
 {
     _db.Delete <WorkingLogItem>(item => item.Id == id);
     return(Content(new JObject
     {
         ["success"] = true
     }.ToString(Formatting.None)));
 }
예제 #12
0
 public void Delete(int id)
 {
     using (var db = new LiteRepository(ConnectionName))
     {
         db.Delete <QueryRecordDocument>(id);
         ConfigCache.Clear();
     }
 }
예제 #13
0
        public ActionResult Delete([Bind(nameof(Event.Id))][FromRoute] Event hggmEvent)
        {
            var eventGuid = hggmEvent.Id;

            _db.Delete <Event>(eventGuid);

            return(RedirectToAction(nameof(PublishedIndex)));
        }
        public bool Delete <T>(int id)
        {
            bool      _ret = false;
            BsonValue bsID = (BsonValue)id;

            _ret = _repo.Delete <T>(id);

            return(_ret);
        }
예제 #15
0
 private static void SaveAnnotations(this LiteRepository repo, PdfFile document, IEnumerable <WordAnnotation> annotations, bool updatePdfLastSeen = true)
 {
     repo.EnsurePdfFile(document, updatePdfLastSeen);
     repo.Delete <WordAnnotation>(wa => wa.Document.Id == document.Id);
     repo.Insert <WordAnnotation>(annotations.Select(a =>
     {
         a.Document = document;
         return(a);
     }));
 }
예제 #16
0
        public Result <bool> Delete(BsonValue id, string collectionName = null)
        {
            var result = new Result <bool>();

            try
            {
                result.ResultObject = _liteRepository.Delete <T>(id, collectionName);
            }
            catch (Exception ex)
            {
                result.ResultCode         = (int)ResultStatusCode.InternalServerError;
                result.ResultMessage      = "Hata Oluştu => " + ex;
                result.ResultInnerMessage = "Hata Oluştu => " + ex.InnerException;

                result.ResultStatus = false;
            }

            return(result);
        }
예제 #17
0
        public void DeleteEvent(Guid id, User userWhoDeleted)
        {
            var eEvent = _db.SingleById <Event>(id);

            _db.Delete <Event>(id);
            _nService.NotifyUsers(new Notification
            {
                Message = _localizer["deleteEventMessage", userWhoDeleted.Name],
                Subject = _localizer["deleteEventSubject", eEvent.Name]
            }, GetUsersFromEvent(eEvent));
        }
예제 #18
0
 public void Delete(Guid id)
 {
     lock (Keylock)
     {
         using (var repo = new LiteRepository(new LiteDatabase(GetPath()), true))
         {
             var bs = new BsonValue(id);
             repo.Delete <T>(bs);
         }
     }
 }
예제 #19
0
 public void ClearPlaylist(string playlistName)
 {
     if (!string.IsNullOrWhiteSpace(playlistName))
     {
         var playlist = jukebox.Playlists.FirstOrDefault(p => p.Name.Equals(playlistName, StringComparison.CurrentCultureIgnoreCase));
         if (playlist != null)
         {
             jukebox.Playlists.Remove(playlist);
             using var db = new LiteRepository(cxstring);
             db.Delete <Playlist>(playlist.ID);
         }
     }
 }
예제 #20
0
        public bool Excluir(int idRegistro)
        {
            EnsureNotDisposed();

            var ehTransiente = EhTransiente(idRegistro);

            if (!ehTransiente)
            {
                int excluidos = _repositorio.Delete <Registro>(item => item.Id == idRegistro, ColecaoRegistros);

                return(excluidos > 0);
            }

            return(ExcluirTransiente(idRegistro));
        }
예제 #21
0
        public bool Delete(Expression <Func <T, bool> > where)
        {
            try
            {
                using (var db = new LiteRepository(conStr))
                {
                    // simple access to Insert/Update/Upsert/Delete
                    int result = db.Delete <T>(where);

                    return(result > 0 ? true : false);
                }
            }
            catch
            {
                return(false);
            }
        }
예제 #22
0
        public void SavePlaylist(Playlist playlist)
        {
            if (playlist is null)
            {
                throw new ArgumentNullException(nameof(playlist));
            }

            using var db = new LiteRepository(cxstring);
            if (playlist.Tunes.Count > 0)
            {
                db.Upsert(playlist);
            }
            else
            {
                db.Delete <Playlist>(playlist.ID);
            }
        }
예제 #23
0
        public bool  DeleteAllEntity()
        {
            try
            {
                using (var db = new LiteRepository(conStr))
                {
                    // simple access to Insert/Update/Upsert/Delete
                    int result = db.Delete <T>(Query.All());

                    return(result > 0 ? true : false);
                }
            }
            catch
            {
                return(false);
            }
        }
예제 #24
0
        public ActionResult Delete([Bind(nameof(Tag.Id))][FromRoute] Tag tag)
        {
            var tagId  = tag.Id;
            var tagObj = db.SingleById <Tag>(tag.Id);

            db.Delete <Tag>(tagId);

            _audit.Add(new TagAudit()
            {
                Tag    = tagObj.TagName,
                TagId  = tag.Id.ToString(),
                Type   = "deleted",
                User   = _userManager.GetUserName(User),
                UserId = _userManager.GetUserId(User)
            });

            return(RedirectToAction(nameof(Index)));
        }
예제 #25
0
        public void Should_use_dynamically_registered_id_mappings()
        {
            BsonMapper.Global.RegisterIdBsonMappers(GetType().Assembly);
            using var repo = new LiteRepository(dbFileName).WithUtcDate();
            var r1 = new Rider {
                Name = "Rider1"
            };

            repo.Insert(r1);
            repo.Insert(new Rider {
                Name = "Rider2"
            });
            repo.Query <Rider>().Count().Should().Be(2);
            var rider = repo.Database.GetCollection("Rider").FindAll().First();

            rider["_id"].Type.Should().Be(BsonType.String);
            Guid.Parse(rider["_id"]).Should().NotBeEmpty();
            repo.Query <Rider>().Where(x => x.Id == r1.Id).First().Should().NotBeNull();
            repo.Delete <Rider>(r1.Id).Should().BeTrue();
        }
예제 #26
0
        public Task CleanseDatabase(Action <string> logger, Action <double> progress)
        {
            return(Task.Run(() =>
            {
                logger($"Cleansing database {cxstring} for MIDI files in {jukebox.Settings.MIDIPath}");
                using var db = new LiteRepository(cxstring);

                progress(.1d);

                var todelete = db.Query <Tune>()
                               .ToEnumerable()
                               .AsParallel()
                               .Where(tune => !File.Exists(Path.Combine(jukebox.Settings.MIDIPath, tune.Filepath)))
                               .ToList();

                logger($"Found {todelete.Count:#,##0} Tunes that no longer exists under {jukebox.Settings.MIDIPath}");

                progress(.5d);

                if (todelete.Any())
                {
                    todelete
                    .Select((tune, i) => new { tune, i })
                    .ToList()
                    .ForEach(e =>
                    {
                        db.Delete <Tune>(e.tune.ID);
                        if (e.i % 10 == 0)
                        {
                            progress(.5 + .5d * e.i / todelete.Count);
                        }
                    });

                    db.Database.Rebuild();

                    jukebox.Tunes = db.Query <Tune>().ToList();
                }
                progress(1d);
                logger("Database cleanse complete");
            }));
        }
 public void RemoveUser(int id) => _liteRepository.Delete <User>(x => x.ID == id);
예제 #28
0
 /// <summary>
 /// Deletes a user from the database based on ID.
 /// </summary>
 bool IDataService.DeleteUser(User user)
 {
     return(repo.Delete <User>(u => u.Id == user.Id) > 0);
 }
예제 #29
0
 public async Task <int> Delete(ApplicationUser user)
 {
     return(await Task.FromResult(db.Delete <ApplicationUser>(e => e.Id == user.Id)));
 }
예제 #30
0
 public bool Delete <T>(object id)
 {
     return(_repository.Delete <T>(new BsonValue(id)));
 }