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"); }
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"); }
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"); }
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"); }
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 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"); }
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"); }
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"); }
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"); }
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"); }
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"); }
public static bool Initialize() { using(RmmDataContext datacontext = new RmmDataContext(RmmDataContext.CONNECTIONSTRING)) { if (datacontext.DatabaseExists() == false) { datacontext.CreateDatabase(); datacontext.SubmitChanges(); return true; } else { return false; } } }
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"); }
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"); }
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<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"); }
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<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<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"); }
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"); }
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"); }
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"); }
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"); }
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<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"); }
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"); }