コード例 #1
0
        public Result<Option> SetFirstTimeOption()
        {
            return Result<Option>.SafeExecute<IOptionService>(result =>
            {
                using (DataContext = new RmmDataContext(RmmDataContext.CONNECTIONSTRING))
                {
                    var newFirstTimeOption = new Option()
                    {
                        id = 1,
                        IsPrimaryTile = false,
                        IsPassword = false,
                        IsSynchro = false,
                        Favorite = 0,
                        LastBackupVersion = 0,
                        ModifiedDate = DateTime.Now,
                        RefreshTimeBackup = DateTime.Now
                    };

                    DataContext.Option.Log().InsertOnSubmit(newFirstTimeOption);

                    DataContext.SubmitChanges();

                    result.Value = newFirstTimeOption;
                }
            }, () => "erreur");


        }
コード例 #2
0
        public Result<Transaction> DeleteTransactionById(int transactionDtoId)
        {
            return Result<Transaction>.SafeExecute<TransactionService>(result =>
                {

                    using (DataContext = new RmmDataContext(RmmDataContext.CONNECTIONSTRING))
                    {
                        DataContext.LoadOptions = DBHelpers.GetConfigurationLoader<Transaction>(t => t.Account);

                        var transaction = (from t in DataContext.Transaction.Log()
                                           where t.ID == transactionDtoId
                                           select t).First();



                        if (transaction != null)
                        {
                            transaction.Account.Balance -= transaction.Amount;
                            DataContext.Transaction.Log().DeleteOnSubmit(transaction);
                            DataContext.SubmitChanges();
                        }


                        result.Value = transaction;
                    }

                }, () => "erreur");
        }
コード例 #3
0
        public Result<Account> CreateAccount(CreateAccountCommand newAccountCommand)
        {
            return Result<Account>.SafeExecute<AccountService>(result =>
            {
                using (DataContext = new RmmDataContext(RmmDataContext.CONNECTIONSTRING))
                {
                    var newAccountEntity = new Account();
                    newAccountEntity.Name = newAccountCommand.Name;
                    newAccountEntity.BankName = newAccountCommand.BankName;
                    newAccountEntity.CreatedDate = DateTime.Now;
                    newAccountEntity.Balance = 0;


                    DataContext.Account.InsertOnSubmit(newAccountEntity);

                    DataContext.SubmitChanges();

                    var AddedAccount = DataContext.Account.Log().Where(a => a.CreatedDate == newAccountEntity.CreatedDate).First();

                    result.Value = AddedAccount;

                }

            }, () => "error");
        }
コード例 #4
0
        public Result<Category> CreateCategory(CreateCategoryCommand newCategoryCommand)
        {
            return Result<Category>.SafeExecute<CategoryService>(result =>
            {
                using (DataContext = new RmmDataContext(RmmDataContext.CONNECTIONSTRING))
                {
                    var newCategoryEntity = new Category()
                    {
                        Balance = 0,
                        Color = newCategoryCommand.Color,
                        CreatedDate = DateTime.Now,
                        Name = newCategoryCommand.Name
                    };



                    DataContext.Category.Log().InsertOnSubmit(newCategoryEntity);

                    DataContext.SubmitChanges();

                    var AddedCategory = DataContext.Category.Log().Where(a => a.CreatedDate == newCategoryEntity.CreatedDate).First();

                    result.Value = AddedCategory;

                }

            }, () => "error");
        }
コード例 #5
0
        public Result<Option> UpdateOption(Option optionToUpdate)
        {
            return Result<Option>.SafeExecute<IOptionService>(result =>
            {

                using (DataContext = new RmmDataContext(RmmDataContext.CONNECTIONSTRING))
                {
                    var entityToUpdate = DataContext.Option.Log().First();

                    entityToUpdate.IsPassword = optionToUpdate.IsPassword;
                    entityToUpdate.IsPrimaryTile = optionToUpdate.IsPrimaryTile;
                    entityToUpdate.IsSynchro = optionToUpdate.IsSynchro;
                    entityToUpdate.Favorite = optionToUpdate.Favorite;
                    entityToUpdate.ModifiedDate = DateTime.Now;
                    entityToUpdate.RefreshTimeBackup = optionToUpdate.RefreshTimeBackup;

                    DataContext.SubmitChanges();

                    result.Value = entityToUpdate;
                }

            }, () => "erreur");


        }
コード例 #6
0
        public Result<bool?> IsPrimaryTileOptionEnable()
        {
            return Result<bool?>.SafeExecute<IOptionService>(result =>
                {
                    using (datacontext = new RmmDataContext(RmmDataContext.CONNECTIONSTRING))
                    {
                        var isPrimaryTile = (from t in datacontext.Option
                                             select t.IsPrimaryTile).First();

                        result.Value = isPrimaryTile;
                    }
                }, () => "erreur");
        }
コード例 #7
0
        public Result<Option> GetOption()
        {
            return Result<Option>.SafeExecute<IOptionService>(result =>
            {

                using (datacontext = new RmmDataContext(RmmDataContext.CONNECTIONSTRING))
                {
                    var option = (from t in datacontext.Option
                                  select t).First();

                    result.Value = option;
                }

            }, () => "erreur");
        }
コード例 #8
0
        public Result<int> GetFavoriteIdAccount()
        {
            return Result<int>.SafeExecute<IOptionService>(result =>
            {

                using (datacontext = new RmmDataContext(RmmDataContext.CONNECTIONSTRING))
                {
                    var idFavorite = (from t in datacontext.Option
                                      select t.Favorite).First();

                    result.Value = idFavorite;
                }

            }, () => "erreur");
        }
コード例 #9
0
        public Result<Transaction> GetTransactionById(int transactionId, bool OnMinimal)
        {
            return Result<Transaction>.SafeExecute<TransactionService>(result =>
                {
                    using (DataContext = new RmmDataContext(RmmDataContext.CONNECTIONSTRING))
                    {
                        if (!OnMinimal)
                            DataContext.LoadOptions = DBHelpers.GetConfigurationLoader<Transaction>(t => t.Category, t => t.Account);

                        var transaction = DataContext.Transaction.Log().Where(t => t.ID == transactionId).First();


                        result.Value = transaction;
                    }
                }, () => "erreur");
        }
コード例 #10
0
        public Result<Account> GetAccountById(int accountId, bool OnMinimal)
        {
            return Result<Account>.SafeExecute<AccountService>(result =>
            {
                using (datacontext = new RmmDataContext(RmmDataContext.CONNECTIONSTRING))
                {
                    if (!OnMinimal)
                        datacontext.LoadOptions = DBHelpers.GetConfigurationLoader<Account>(acc => acc.TransactionList);

                    var account = datacontext.Account.Where(a => a.ID == accountId).First();

                    result.Value = account;
                }

            }, () => "error");
        }
コード例 #11
0
        public Result<List<Category>> GetAllCategories(bool OnMinimal)
        {
            return Result<List<Category>>.SafeExecute<CategoryService>(result =>
            {
                using (datacontext = new RmmDataContext(RmmDataContext.CONNECTIONSTRING))
                {
                    if (!OnMinimal)
                    {
                        datacontext.LoadOptions = DBHelpers.GetConfigurationLoader<Category>(cat => cat.TransactionList);
                    }

                    var categories = datacontext.Category.ToList();

                    result.Value = categories;
                }
            }, () => "error");
        }
コード例 #12
0
 public static bool Initialize()
 {
     using(RmmDataContext datacontext = new RmmDataContext(RmmDataContext.CONNECTIONSTRING))
     {
         
         if (datacontext.DatabaseExists() == false)
         {
             datacontext.CreateDatabase();
             datacontext.SubmitChanges();
             return true;
         }
         else
         {
             return false;
         }
     }
 }
コード例 #13
0
        public Result<List<Transaction>> GetTransactionsByCategoryId(int categoryId, bool OnMinimal)
        {
            return Result<List<Transaction>>.SafeExecute<TransactionService>(result =>
            {
                using (DataContext = new RmmDataContext(RmmDataContext.CONNECTIONSTRING))
                {
                    if (!OnMinimal)
                        DataContext.LoadOptions = DBHelpers.GetConfigurationLoader<Transaction>(t => t.Account, t => t.Category);


                    var transactions = (from t in DataContext.Transaction.Log()
                                        where t.Category.ID == categoryId
                                        select t).ToList();


                    result.Value = transactions;
                }
            }, () => "erreur");
        }
コード例 #14
0
        public Result<Category> GetCategoryById(int categoryId, bool OnMinimal)
        {
            return Result<Category>.SafeExecute<CategoryService>(result =>
            {
                using (DataContext = new RmmDataContext(RmmDataContext.CONNECTIONSTRING))
                {
                    if(!OnMinimal)
                        DataContext.LoadOptions = DBHelpers.GetConfigurationLoader<Category>(c => c.TransactionList);

                    var category = DataContext.Category.Log().Where(a => a.ID == categoryId).First();




                    result.Value = category;
                }

            }, () => "error");
        }
コード例 #15
0
        public Result<Category> DeleteCategorieById(int categoryId)
        {
            return Result<Category>.SafeExecute<CategoryService>(result =>
                {
                    using (DataContext = new RmmDataContext(RmmDataContext.CONNECTIONSTRING))
                {
                    var category = (from t in DataContext.Category
                                    where t.ID == categoryId
                                    select t).First();

                    if (category != null)
                    {
                        DataContext.Category.Log().DeleteOnSubmit(category);

                        DataContext.SubmitChanges();
                    }

                    result.Value = category;
                    }

                },() => "error");
        }
コード例 #16
0
        public Result<Transaction> CreateTransaction(CreateTransactionCommand newTransactionCommand)
        {
            return Result<Transaction>.SafeExecute<TransactionService>(result =>
            {
                using (datacontext = new RmmDataContext(RmmDataContext.CONNECTIONSTRING))
                {
                    var transaction = new Transaction();

                    Category attachedCategoryEntity;
                    Account attachedAccountEntity;

                    if (newTransactionCommand.categoryId.HasValue)
                    {
                        attachedCategoryEntity = datacontext.Category.Where(c => c.ID == newTransactionCommand.categoryId).First();
                        transaction.Category = attachedCategoryEntity;
                    }

                    if (newTransactionCommand.accountId != 0)
                    {
                        attachedAccountEntity = datacontext.Account.Where(c => c.ID == newTransactionCommand.accountId).First();
                        attachedAccountEntity.Balance += newTransactionCommand.Amount;
                        transaction.Account = attachedAccountEntity;
                    }

                    transaction.Amount = newTransactionCommand.Amount;
                    transaction.Description = newTransactionCommand.Description;
                    transaction.Name = newTransactionCommand.Name;
                    transaction.CreatedDate = DateTime.Now;

                    datacontext.Transaction.InsertOnSubmit(transaction);
                    datacontext.SubmitChanges();

                    var AddedTransac = datacontext.Transaction.Where(a => a.CreatedDate == transaction.CreatedDate).First();

                    result.Value = AddedTransac;

                }
            }, () => "erreur");
        }
コード例 #17
0
        public Result<Account> DeleteAccountById(int accountId)
        {
            return Result<Account>.SafeExecute<AccountService>(result =>
            {
                 
                using (DataContext = new RmmDataContext(RmmDataContext.CONNECTIONSTRING))
                {
                    var account = (from t in DataContext.Account
                                    where t.ID == accountId
                                    select t).First();

                    if (account != null)
                    {
                        DataContext.Account.Log().DeleteOnSubmit(account);
                        DataContext.SubmitChanges();
                    }

                    result.Value = account;
                }

            }, () => "error");
        }
コード例 #18
0
        public Result<Account> UpdateAccount(EditAccountCommand editAccountCommand)
        {
            return Result<Account>.SafeExecute<AccountService>(result =>
            {

                using (DataContext = new RmmDataContext(RmmDataContext.CONNECTIONSTRING))
                {

                    var entityToUpdate = DataContext.Account.Log().Where(t => t.ID == editAccountCommand.id).First();

                    entityToUpdate.ID = editAccountCommand.id;
                    entityToUpdate.Name = editAccountCommand.Name;
                    entityToUpdate.BankName = editAccountCommand.BankName;
                    entityToUpdate.CreatedDate = DateTime.Now;


                    DataContext.SubmitChanges();

                    result.Value = entityToUpdate;
                }

            }, () => "error");
        }
コード例 #19
0
        public Result<int> SetFavoriteIdAccount(int AccountId)
        {
            return Result<int>.SafeExecute<IOptionService>(result =>
            {

                using (datacontext = new RmmDataContext(RmmDataContext.CONNECTIONSTRING))
                {

                    var entityToUpdate = datacontext.Option.First();

                    entityToUpdate.Favorite = AccountId;

                    datacontext.SubmitChanges();

                    result.Value = AccountId;
                }

            }, () => "erreur");
        }
コード例 #20
0
        public Result<Category> UpdateCategory(EditCategoryCommand editCategoryCommand)
        {
            return Result<Category>.SafeExecute<CategoryService>(result =>
            {

                using (DataContext = new RmmDataContext(RmmDataContext.CONNECTIONSTRING))
                {

                    var entityToUpdate = DataContext.Category.Log().Where(t => t.ID == editCategoryCommand.id).First();

                    entityToUpdate.ID = editCategoryCommand.id;
                    entityToUpdate.Name = editCategoryCommand.Name;
                    entityToUpdate.Color = editCategoryCommand.Color;
                    entityToUpdate.CreatedDate = DateTime.Now;


                    DataContext.SubmitChanges();

                    result.Value = entityToUpdate;
                }

            }, () => "error");
        }
コード例 #21
0
        public Result<List<Account>> GetAllAccounts(bool OnMinimal)
        {
            return Result<List<Account>>.SafeExecute<AccountService>(result =>
            {
                DataContext = new RmmDataContext(RmmDataContext.CONNECTIONSTRING);

                using (DataContext = new RmmDataContext(RmmDataContext.CONNECTIONSTRING))
                {
                          if (!OnMinimal)
                              DataContext.LoadOptions = DBHelpers.GetConfigurationLoader<Account>(Acc => Acc.TransactionList);

                          var accounts = DataContext.Account.Log().ToList();

                          result.Value = accounts;
                }

            }, () => "error");
        }
コード例 #22
0
        public Result<List<Transaction>> GetTransactionsByAccountId(int accountId, bool OnMinimal)
        {
            return Result<List<Transaction>>.SafeExecute<TransactionService>(result =>
              {
                  using (datacontext = new RmmDataContext(RmmDataContext.CONNECTIONSTRING))
                  {
                      if (!OnMinimal)
                          datacontext.LoadOptions = DBHelpers.GetConfigurationLoader<Transaction>(t => t.Category, t => t.Account);

                      var transactions = datacontext.Transaction.Where(t => t.Account.ID == accountId).ToList();

                      result.Value = transactions;
                  }
              }, () => "erreur");
        }
コード例 #23
0
        public Result<List<Transaction>> DeleteTransactionsByAccountId(int accountId)
        {
            return Result<List<Transaction>>.SafeExecute<TransactionService>(result =>
            {
                using (datacontext = new RmmDataContext(RmmDataContext.CONNECTIONSTRING))
                {
                    var transaction = datacontext.Transaction.Where(t => t.AccountID == accountId).ToList();
                    var account = datacontext.Account.Where(a => a.Balance == accountId).First();

                    if (transaction != null)
                    {
                        account.Balance = 0;
                        datacontext.Transaction.DeleteAllOnSubmit(transaction);
                        datacontext.SubmitChanges();
                    }

                    result.Value = transaction;
                }
            }, () => "erreur");
        }
コード例 #24
0
        public Result<List<Transaction>> DeleteTransactionsByCategoryId(int categoryId)
        {
            return Result<List<Transaction>>.SafeExecute<TransactionService>(result =>
            {
                using (DataContext = new RmmDataContext(RmmDataContext.CONNECTIONSTRING))
                {
                    var transaction = DataContext.Transaction.Log().Where(t => t.CategoryID == categoryId).ToList();
                    var category = DataContext.Category.Log().Where(t => t.ID == categoryId).First();


                    if (transaction != null)
                    {
                        category.Balance = 0;
                        DataContext.Transaction.Log().DeleteAllOnSubmit(transaction);
                        DataContext.SubmitChanges();
                    }


                    result.Value = transaction;
                }
            }, () => "erreur");
        }
コード例 #25
0
        public Result<List<Transaction>> GetAllTransactions(bool OnMinimal)
        {
            return Result<List<Transaction>>.SafeExecute<TransactionService>(result =>
            {
                using (DataContext = new RmmDataContext(RmmDataContext.CONNECTIONSTRING))
                {
                    if (!OnMinimal)
                        DataContext.LoadOptions = DBHelpers.GetConfigurationLoader<Transaction>(t => t.Account, t => t.Category);

                    var query = DataContext.Transaction.Log().ToList();

                    result.Value = query;
                }
            }, () => "erreur");
        }
コード例 #26
0
        public Result<Transaction> UpdateTransaction(EditTransactionCommand EditTransactionCommand)
        {
            return Result<Transaction>.SafeExecute<TransactionService>(result =>
            {
                using (DataContext = new RmmDataContext(RmmDataContext.CONNECTIONSTRING))
                {

                    DataLoadOptions options = new DataLoadOptions();
                    options.LoadWith<Transaction>(c => c.Category);
                    options.LoadWith<Transaction>(c => c.Account);

                    DataContext.LoadOptions = options;


                    var entityToUpdate = DataContext.Transaction.Log().Where(t => t.ID == EditTransactionCommand.id).First();


                    entityToUpdate.Name = EditTransactionCommand.Name;

                    if (entityToUpdate.Category.ID != EditTransactionCommand.categoryId)
                    {
                        var categoryAttachedByUpdate = DataContext.Category.Log().Where(c => c.ID == EditTransactionCommand.categoryId).First();
                        entityToUpdate.Category = categoryAttachedByUpdate;
                    }


                    if (entityToUpdate.Account.ID != EditTransactionCommand.accountId)
                    {
                        var accountAttachedByUpdate = DataContext.Account.Log().Where(c => c.ID == EditTransactionCommand.accountId).First();
                        entityToUpdate.Account = accountAttachedByUpdate;
                    }

                    if (string.IsNullOrEmpty(EditTransactionCommand.Description))
                        entityToUpdate.Description = EditTransactionCommand.Description;

                    entityToUpdate.Amount = EditTransactionCommand.Amount;

                    entityToUpdate.CreatedDate = DateTime.Now;

                    DataContext.SubmitChanges();

                    result.Value = entityToUpdate;

                }
            }, () => "erreur");


        }