Beispiel #1
0
        public async Task <Unit> Handle(RemoveVaultCommand request, CancellationToken cancellationToken)
        {
            if (!VaultService.ValidateVaultPassword(request.VaultId, request.MasterPassword))
            {
                throw new Exception("Podano nie poprawne hasło");
            }
            var vault = await(from v in PmContext.Vaults
                              where v.Username == UserResolverService.GetUsername() && v.Id == request.VaultId
                              select v).FirstOrDefaultAsync();

            if (vault == null)
            {
                throw new Exception();
            }
            var entries = await(from en in PmContext.Entries
                                where en.VaultId == vault.Id
                                select en
                                ).ToListAsync();

            using var trans = PmContext.Database.BeginTransaction();

            PmContext.Entries.RemoveRange(entries);
            PmContext.Vaults.Remove(vault);
            PmContext.SaveChanges();
            await trans.CommitAsync();

            return(Unit.Value);
        }
        public async Task <Unit> Handle(DeleteEntryCommand request, CancellationToken cancellationToken)
        {
            var entry = await PmContext.Entries.FirstOrDefaultAsync(x => x.Id == request.EntryId);

            if (entry == null)
            {
                throw new Exception();
            }
            if (!VaultService.ValidateVaultPassword(entry.VaultId, request.MasterPassword))
            {
                throw new Exception("Podano nie poprawne hasło");
            }
            PmContext.Remove(entry);
            PmContext.SaveChanges();
            return(Unit.Value);
        }
Beispiel #3
0
        public async Task <Unit> Handle(UpdateEntryCommand request, CancellationToken cancellationToken)
        {
            var entry = await PmContext.Entries.FirstOrDefaultAsync(item => item.Id == request.Id);

            if (entry == null)
            {
                throw new Exception();
            }

            if (!VaultService.ValidateVaultPassword(entry.VaultId, request.MasterPassword))
            {
                throw new Exception("Podano nie poprawne hasło");
            }
            entry.Email    = request.Email;
            entry.Login    = request.Login;
            entry.Password = request.Password;
            entry.Portal   = request.Portal;

            PmContext.Update(entry);
            PmContext.SaveChanges();
            return(Unit.Value);
        }