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.InsertOnSubmit(newCategoryEntity);

                    datacontext.SubmitChanges();

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

                    result.Value = AddedCategory;

                }

            }, () => "error");
        }
        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");
        }
Exemplo n.º 3
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");


        }
 public static bool Initialize()
 {
     using(RmmDataContext datacontext = new RmmDataContext(RmmDataContext.CONNECTIONSTRING))
     {
         
         if (datacontext.DatabaseExists() == false)
         {
             datacontext.CreateDatabase();
             datacontext.SubmitChanges();
             return true;
         }
         else
         {
             return false;
         }
     }
 }
Exemplo n.º 5
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");
        }
        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");
        }
Exemplo n.º 7
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");
        }
        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.Where(a => a.CreatedDate == newAccountEntity.CreatedDate).First();

                    result.Value = AddedAccount;

                }

            }, () => "error");
        }
Exemplo n.º 9
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");
        }
        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");
        }
        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");


        }
        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");
        }
Exemplo n.º 13
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");
        }
Exemplo n.º 14
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");
        }
Exemplo n.º 15
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,
                        ModifiedDate = DateTime.Now
                    };

                    datacontext.Option.InsertOnSubmit(newFirstTimeOption);

                    datacontext.SubmitChanges();

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