Ejemplo n.º 1
0
        public override async ValueTask <IHttpActionResult> Get(ODataQueryOptions <TEntity> options)
        {
            var result = await RepositoryAdapter
                         .GetAsync(options, QuerySettings, IgnoreQueryOptions).ConfigureAwait(false);

            return(Ok(result));
        }
Ejemplo n.º 2
0
        public override async ValueTask <IHttpActionResult> Put([FromODataUri] object key, TEntity putEntity)
        {
            var result = await RepositoryAdapter.PutAsync(putEntity).ConfigureAwait(false);

            await RepositoryAdapter.PersistChangesAsync().ConfigureAwait(false);

            return(Updated(result));
        }
Ejemplo n.º 3
0
        public override async ValueTask <IHttpActionResult> Post([FromBody] TEntity postEntity)
        {
            var result = await RepositoryAdapter.InsertAsync(postEntity).ConfigureAwait(false);

            await RepositoryAdapter.PersistChangesAsync().ConfigureAwait(false);

            return(Created(result));
        }
Ejemplo n.º 4
0
        public override async ValueTask <IActionResult> Get([FromODataUri] object key,
                                                            ODataQueryOptions <TEntity> options)
        {
            var result = await RepositoryAdapter
                         .GetAsync(key, options, QuerySettings, IgnoreQueryOptions).ConfigureAwait(false);

            return(Accepted(result));
        }
Ejemplo n.º 5
0
        public override async ValueTask <IHttpActionResult> Patch([FromODataUri] object key, Delta <TEntity> delta)
        {
            var patchEntity = await RepositoryAdapter
                              .GetAsync(key, null, QuerySettings, IgnoreQueryOptions).ConfigureAwait(false);

            var result = await RepositoryAdapter.PatchAsync(patchEntity, delta).ConfigureAwait(false);

            await RepositoryAdapter.PersistChangesAsync().ConfigureAwait(false);

            return(Updated(result));
        }
Ejemplo n.º 6
0
        public override async ValueTask <IHttpActionResult> Delete([FromODataUri] object key)
        {
            var entityToBeDeleted = await RepositoryAdapter
                                    .GetAsync(key, null, QuerySettings, IgnoreQueryOptions).ConfigureAwait(false);

            if (await RepositoryAdapter.RemoveAsync(entityToBeDeleted).ConfigureAwait(false) <= 0)
            {
                return(BadRequest());
            }
            await RepositoryAdapter.PersistChangesAsync().ConfigureAwait(false);

            return(Ok());
        }
Ejemplo n.º 7
0
        private string GenerateTestRepo(RepositoryAdapter adapter)
        {
            var templateFunction = Util.GetCompiledTemplate("TestRepository");

            try
            {
                return(templateFunction(adapter));
            }
            catch (Exception ex)
            {
                Log.Error(ex, "Error executing test repository template for {TypeName}", adapter.Type.Name);
                throw;
            }
        }
Ejemplo n.º 8
0
        public bool DeleteBank(int id)
        {
            bool result = false;

            using (KapitalDataContext context = new KapitalDataContext(ConnectionString))
            {
                RepositoryAdapter<BO.Bank, Bank, BankCopyExtensions> adapter =
                    new RepositoryAdapter<BO.Bank, Bank, BankCopyExtensions>(this);

                result = adapter.Delete(context.Banks.Where(x => x.BankId == id), context);
            }

            return result;
        }
Ejemplo n.º 9
0
        public List<BO.Account> GetAccountsByBank(int bankId)
        {
            List<BO.Account> accounts = null;

            using (KapitalDataContext context = new KapitalDataContext(ConnectionString))
            {
                RepositoryAdapter<BO.Account, Account, AccountCopyExtensions> adapter =
                    new RepositoryAdapter<BO.Account, Account, AccountCopyExtensions>(this);

                accounts = adapter.GetAllByParentID(context.Accounts.Where(a => a.BankId == bankId));
            }

            return accounts;
        }
Ejemplo n.º 10
0
        public bool DeleteTransaction(int transactionId)
        {
            bool result = false;

            using (KapitalDataContext context = new KapitalDataContext(ConnectionString))
            {
                RepositoryAdapter<BO.Transaction, Transaction, TransactionCopyExtensions> adapter =
                    new RepositoryAdapter<BO.Transaction, Transaction, TransactionCopyExtensions>(this);

                result = adapter.Delete(context.Transactions.Where(x => x.TransactionId == transactionId), context);

                Transaction item = (from x in context.Transactions
                                    where x.TransactionId == transactionId
                                    select x).SingleOrDefault();

                context.Transactions.DeleteOnSubmit(item);

                context.SubmitChanges();
            }

            return result;
        }
Ejemplo n.º 11
0
        public List <CodeFile> GenerateTestRepositories(Domain domain)
        {
            Util.RegisterHelpers(domain.TypeProvider);
            var files = new List <CodeFile>();

            foreach (var type in domain.Types.OrderBy(t => t.Name))
            {
                if (!type.Ignore)
                {
                    var repo = new RepositoryAdapter(domain, type);
                    if (repo.Operations.Any())
                    {
                        var file = new CodeFile {
                            Name = Util.CSharpNameFromName(type.Name) + "InMemoryRepository.cs", Contents = GenerateTestRepo(repo)
                        };
                        files.Add(file);
                    }
                }
            }

            return(files);
        }
Ejemplo n.º 12
0
        public BO.Bank GetBank(int id)
        {
            BO.Bank bank = null;

            using (KapitalDataContext context = new KapitalDataContext(ConnectionString))
            {
                RepositoryAdapter<BO.Bank, Bank, BankCopyExtensions> adapter =
                    new RepositoryAdapter<BO.Bank, Bank, BankCopyExtensions>(this);

                bank = adapter.Get(context.Banks.Where(b => b.BankId == id));
            }

            return bank;
        }
Ejemplo n.º 13
0
        public bool SetTransaction(BO.Transaction transaction)
        {
            bool insert = (transaction.Id <= 0);
            bool result = false;

            using (KapitalDataContext context = new KapitalDataContext(ConnectionString))
            {
                RepositoryAdapter<BO.Transaction, Transaction, TransactionCopyExtensions> adapter =
                    new RepositoryAdapter<BO.Transaction, Transaction, TransactionCopyExtensions>(this);

                if (insert)
                {
                    result = adapter.Insert(transaction, context.Transactions, context);
                }
                else
                {
                    result = adapter.Update(transaction, context.Transactions.Where(t => t.TransactionId == transaction.Id), context);
                }
            }

            return result;
        }
Ejemplo n.º 14
0
        public bool SetBank(BO.Bank bank)
        {
            bool insert = (bank.ID <= 0);
            bool result = false;

            using (KapitalDataContext context = new KapitalDataContext(ConnectionString))
            {
                RepositoryAdapter<BO.Bank, Bank, BankCopyExtensions> adapter =
                    new RepositoryAdapter<BO.Bank, Bank, BankCopyExtensions>(this);

                if (insert)
                {
                    result = adapter.Insert(bank, context.Banks, context);
                }
                else
                {
                    throw new NotImplementedException();
                }

            }

            return result;
        }
Ejemplo n.º 15
0
        public bool SetAccount(BO.Account account)
        {
            bool insert = (account.Id <= 0);
            bool result = false;

            using (KapitalDataContext context = new KapitalDataContext(ConnectionString))
            {
                RepositoryAdapter<BO.Account, Account, AccountCopyExtensions> adapter =
                    new RepositoryAdapter<BO.Account, Account, AccountCopyExtensions>(this);

                if (insert)
                {
                    result = adapter.Insert(account, context.Accounts, context);
                }
                else
                {
                    result = adapter.Update(account, context.Accounts.Where(x => x.AccountId == account.Id), context);
                }
            }

            return result;
        }
Ejemplo n.º 16
0
        public List<BO.User> GetUsers()
        {
            List<BO.User> users = null;

            using (KapitalDataContext context = new KapitalDataContext(ConnectionString))
            {
                RepositoryAdapter<BO.User, User, UserCopyExtensions> adapter =
                    new RepositoryAdapter<BO.User, User, UserCopyExtensions>(this);

                users = adapter.GetAll(context.Users);
            }

            return users;
        }
Ejemplo n.º 17
0
        public BO.User GetUser(string username)
        {
            BO.User user = null;

            using (KapitalDataContext context = new KapitalDataContext(ConnectionString))
            {
                RepositoryAdapter<BO.User, User, UserCopyExtensions> adapter =
                    new RepositoryAdapter<BO.User, User, UserCopyExtensions>(this);

                user = adapter.Get(context.Users.Where(u => String.Compare(u.Username, username, true) == 0));
            }

            return user;
        }
Ejemplo n.º 18
0
        public BO.User GetUser(int id)
        {
            BO.User user = null;

            using (KapitalDataContext context = new KapitalDataContext(ConnectionString))
            {
                RepositoryAdapter<BO.User, User, UserCopyExtensions> adapter =
                    new RepositoryAdapter<BO.User, User, UserCopyExtensions>(this);

                user = adapter.Get(context.Users.Where(u => u.UserId == id));
            }

            return user;
        }
Ejemplo n.º 19
0
        public List<Models.Transaction> GetTransactionsWithinRange(Guid accountId, DateTime start, DateTime end, TagType type)
        {
            List<BO.Transaction> transactions = null;

            using (KapitalDataContext context = new KapitalDataContext(ConnectionString))
            {
                RepositoryAdapter<BO.Transaction, Transaction, TransactionCopyExtensions> adapter =
                    new RepositoryAdapter<BO.Transaction, Transaction, TransactionCopyExtensions>(this);

                var query = context.Transactions.Where(t => t.AccountId == accountId);

                query = query.Where(t => t.Date >= start && t.Date <= end);

                transactions = adapter.GetAllByParentID(query);
            }

            return transactions;
        }
Ejemplo n.º 20
0
        public List<Models.Transaction> GetTransactionsByAccount(Guid accountId, string sort)
        {
            List<BO.Transaction> transactions = null;

            using (KapitalDataContext context = new KapitalDataContext(ConnectionString))
            {
                RepositoryAdapter<BO.Transaction, Transaction, TransactionCopyExtensions> adapter =
                    new RepositoryAdapter<BO.Transaction, Transaction, TransactionCopyExtensions>(this);

                var query = context.Transactions.Where(t => t.AccountId == accountId);

                if (String.Compare(sort, "date-desc", true) == 0)
                {
                    query = query.OrderByDescending(t => t.Date);
                }
                else
                {
                    query = query.OrderBy(t => t.Date);
                }

                transactions = adapter.GetAllByParentID(query);
            }

            return transactions;
        }
Ejemplo n.º 21
0
        public List<Models.Transaction> GetTransactionsByAccount(Guid accountId)
        {
            List<BO.Transaction> transactions = null;

            using (KapitalDataContext context = new KapitalDataContext(ConnectionString))
            {
                RepositoryAdapter<BO.Transaction, Transaction, TransactionCopyExtensions> adapter =
                    new RepositoryAdapter<BO.Transaction, Transaction, TransactionCopyExtensions>(this);

                transactions = adapter.GetAllByParentID(context.Transactions.Where(t => t.AccountId == accountId));
            }

            return transactions;
        }
Ejemplo n.º 22
0
        private List <QuestionsAnswer> ReadAllQuestionAnswers()
        {
            RepositoryAdapter repositoryAdapter = new RepositoryAdapter();

            return(repositoryAdapter.GetQuestionAnswers());
        }
Ejemplo n.º 23
0
        private List <RuleRegulation> GetRuleRegulations()
        {
            RepositoryAdapter repositoryAdapter = new RepositoryAdapter();

            return(repositoryAdapter.GetRules());
        }
Ejemplo n.º 24
0
        public List<BO.Bank> GetAllBanks()
        {
            List<BO.Bank> banks = null;

            using (KapitalDataContext context = new KapitalDataContext(ConnectionString))
            {
                RepositoryAdapter<BO.Bank, Bank, BankCopyExtensions> adapter =
                    new RepositoryAdapter<BO.Bank, Bank, BankCopyExtensions>(this);
                banks = adapter.GetAll(context.Banks);
            }

            return banks;
        }
Ejemplo n.º 25
0
        public BO.Transaction GetTransaction(int transactionId)
        {
            BO.Transaction transaction = null;

            using (KapitalDataContext context = new KapitalDataContext(ConnectionString))
            {
                RepositoryAdapter<BO.Transaction, Transaction, TransactionCopyExtensions> adapter =
                    new RepositoryAdapter<BO.Transaction, Transaction, TransactionCopyExtensions>(this);

                transaction = adapter.Get(context.Transactions.Where(t => t.TransactionId == transactionId));
            }

            return transaction;
        }