/// <summary> /// Returns a list of all of the account types /// </summary> /// <returns>A List of all of the account types</returns> public List <AccountType> GetAccountTypes() { using (FinPlannerContext _context = new FinPlannerContext()) { return(_context.AccountType.ToList()); } }
public ReturnModel AddAccount(Account account) { ReturnModel model = new ReturnModel(); account.AccountIdentifier = "xxxx" + account.AccountIdentifier; using (FinPlannerContext _context = new FinPlannerContext()) { if (account.Id == null) { account.Id = Guid.NewGuid().ToString(); _context.Account.Add(account); } else { Account account1 = _context.Account.Find(account.Id); account1.Update(account); _context.Entry(account1).State = EntityState.Modified; } try { _context.SaveChanges(); model.result = true; } catch (Exception e) { model.result = false; model.returnStr = e.Message; ExceptionCatcher catcher = new ExceptionCatcher(); catcher.Catch(e.Message); } } return(model);; }
private bool isExists(string accountId) { using (FinPlannerContext _context = new FinPlannerContext()) { return(_context.AccountAmortisation.Where(x => x.AccountId == accountId).Any()); } }
public bool isAmortised(string AccountTypeId) { using (FinPlannerContext _context = new FinPlannerContext()) { return(_context.AccountType.Where(x => x.AccountTypeId == AccountTypeId).Select(x => x.Amortised).FirstOrDefault()); } }
private AutomatedCashFlow getTransaction(string Id) { using (FinPlannerContext _context = new FinPlannerContext()) { return(_context.AutomatedCashFlows.Find(Id)); } }
public ReturnModel CreateCollection(NewCollectionsObj obj) { Collections col = new Collections(obj.durationType, obj.name, obj.User, obj.resetDate); UserCollectionMapping mapping = new UserCollectionMapping(col.CollectionsId, obj.User); ReturnModel returnModel = new ReturnModel(); if (mapping.Id == "999") { returnModel.result = false; return(returnModel); } try { using (FinPlannerContext _context = new FinPlannerContext()) { _context.Collections.Add(col); _context.UserCollectionMapping.Add(mapping); _context.SaveChanges(); } returnModel.result = true; returnModel.returnStr = col.CollectionsId; return(returnModel); } catch (Exception e) { returnModel.result = false; return(returnModel); } }
public List <Collections> GetCollections(List <string> collectionsIds, int count) { //get collections List <Collections> collections = new List <Collections>(); try { using (FinPlannerContext _context = new FinPlannerContext()) { collections = _context .Collections .Where(col => collectionsIds.Contains(col.CollectionsId)) .ToList(); } } catch (Exception e) { ExceptionCatcher catcher = new ExceptionCatcher(); catcher.Catch(e.Message); } //get accounts Account account = new Account(); List <Account> accounts = account.GetAccountIndex(collectionsIds, count); //assign accounts foreach (Collections item in collections) { item.Accounts = accounts.Where(x => x.CollectionsId == item.CollectionsId).ToList(); } return(collections); }
public bool CheckUser() { bool ans = true; if (Id == "999") { ans = false; } else { using (FinPlannerContext _context = new FinPlannerContext()) { List <UserCollectionMapping> mappings = _context.UserCollectionMapping.Where(x => x.CollectionsId == CollectionsId).ToList(); //start off by assuming that the user is not linked //AspNetUsers aspNetUsers = new AspNetUsers(); //userId = aspNetUsers.getUserId(userId); foreach (UserCollectionMapping item in mappings) { if (item.Id == Id || item.FirebaseUserId == Id) { ans = false; break; } } } } return(ans); }
/// <summary> /// Data Layer Application for the retrieval of users /// </summary> /// <param name="email">Email address of the user</param> /// <returns>Returns a single instance of a user</returns> private FirebaseUser Get(string email) { using (FinPlannerContext _context = new FinPlannerContext()) { return(_context.FirebaseUser.Where(x => x.Email == email).FirstOrDefault()); } }
/// <summary> /// Constuctor that returns a single CFClassification by Id or name /// </summary> /// <param name="id">The Id or name of the CFClassification</param> public CFClassification(string id) { using (FinPlannerContext _context = new FinPlannerContext()) { try { CFClassification temp = _context.CFClassifications.Find(id); Id = temp.Id; Name = temp.Name; Sign = temp.Sign; if (temp == null) { temp = _context.CFClassifications.Where(x => x.Name == id).FirstOrDefault(); Id = temp.Id; Name = temp.Name; Sign = temp.Sign; } } catch { try { CFClassification temp = _context.CFClassifications.Where(x => x.Name == id).FirstOrDefault(); Id = temp.Id; Name = temp.Name; Sign = temp.Sign; } catch { Id = ""; Name = ""; Sign = 0; } } } }
/// <summary> /// Accesses the DB and returns a full list /// </summary> /// <returns>Returns a full list of CFClassifications</returns> public List <CFClassification> GetList() { using (FinPlannerContext _context = new FinPlannerContext()) { return(_context.CFClassifications.ToList()); } }
private bool Check(string collectionsId) { using (FinPlannerContext _context = new FinPlannerContext()) { return(_context.YodleeModel.Where(x => x.CollectionsId == collectionsId).Any()); } }
/// <summary> /// Returns a populated collections object /// </summary> /// <param name="collectionsId">Id of the collection object</param> public Collections(string collectionsId) { Collections col = new Collections(); List <Budget> budgets = new List <Budget>(); using (FinPlannerContext _context = new FinPlannerContext()) { col = _context.Collections.Find(collectionsId); budgets = _context.Budget.Where(x => x.CollectionId == collectionsId).ToList(); } if (budgets.Count() == 0) { Budget budget = new Budget(); budgets = budget.NewBudget(col); } BudgetTransaction transaction = new BudgetTransaction(); foreach (Budget item in budgets) { item.Collection = null; item.BudgetTransactions = transaction.GetBudgetTransactions(item.BudgetId); } CollectionsId = collectionsId; Name = col.Name; Accounts = col.Accounts; TotalAmount = col.TotalAmount; DurationType = col.DurationType; DateCreated = col.DateCreated; UserCreated = col.UserCreated; Budgets = budgets; ResetDay = col.ResetDay; }
private string GetLoginName(string collectionsId) { using (FinPlannerContext _context = new FinPlannerContext()) { return(_context.YodleeModel.Where(x => x.CollectionsId == collectionsId).Select(x => x.loginName).FirstOrDefault()); } }
public List <ManualCashFlow> GetManualCashFlows(string accountId, DateTime startDate, DateTime endDate) { using (FinPlannerContext _context = new FinPlannerContext()) { return(_context.ManualCashFlows.Where(x => x.AccountId == accountId).Where(x => x.DateBooked > startDate && x.DateBooked < endDate).ToList()); } }
/// <summary> /// Returns a list of CFTYpes for that collection /// </summary> /// <param name="collectionsId">Collection ID which is pulling the request</param> /// <returns>Returns a list of all CFTYpes applicatble to that collection</returns> public List <CFType> GetCFList(string collectionsId) { using (FinPlannerContext _context = new FinPlannerContext()) { return(_context.CFTypes.Where(x => x.ClientReference == collectionsId || x.Custom == false).OrderBy(x => x.Name).ToList()); } }
/// <summary> /// Add user and collection to collection mapping table /// </summary> /// <param name="obj"> New Collection Object containing user eamil as obj.user and collectionsharing id as obj.name</param> /// <returns></returns> public bool AddUserToCollection(NewCollectionsObj obj) { // 3 checks // 1 - is count == 0 CollectionSharing sharing = ShareCounter(obj.name); // 2 - is the user different from the other users-- already mapped into UserCollectionsMapping UserCollectionMapping mapping = new UserCollectionMapping(sharing.CollectionId, obj.User); if (sharing.count == 0 && mapping.CheckUser()) { // set the counter to +1 sharing.CountIncrament(); try { using (FinPlannerContext _context = new FinPlannerContext()) { _context.Entry(sharing).State = EntityState.Modified; _context.UserCollectionMapping.Add(mapping); _context.SaveChanges(); } return(true); } catch (Exception e) { return(false); } } else { return(false); } }
private CollectionSharing ShareCounter(string id) { using (FinPlannerContext _context = new FinPlannerContext()) { CollectionSharing sharing = _context.CollectionSharing.Find(id); return(sharing); } }
private void SavedCollection(CollectionSharing collectionSharing) { using (FinPlannerContext _context = new FinPlannerContext()) { _context.CollectionSharing.Add(collectionSharing); _context.SaveChanges(); } }
private void Save(ClickTracker tracker) { using (FinPlannerContext _context = new FinPlannerContext()) { _context.ClickTracker.Add(tracker); _context.SaveChanges(); } }
private void Save() { using (FinPlannerContext _context = new FinPlannerContext()) { _context.Add(this); _context.SaveChanges(); } }
/// <summary> /// Returns a collection object /// </summary> /// <param name="collectionsId">Collection Id of the object required</param> /// <returns>Returns a collation object</returns> public Collections GetCollections(string collectionsId) { using (FinPlannerContext _context = new FinPlannerContext()) { return(_context .Collections .Find(collectionsId)); } }
/// <summary> /// Looks to te database to source and find a particular Simulation via the Simulation Id /// </summary> /// <param name="SimulationId">Id of the simulatiion that is being requested</param> /// <returns>A Simulation for a given Id</returns> private Simulation GetSimulation(string SimulationId) { using (FinPlannerContext _context = new FinPlannerContext()) { return(_context .Simulation .Find(SimulationId)); } }
public int CollectionsCounter(string userId) { using (FinPlannerContext _context = new FinPlannerContext()) { AspNetUsers user = new AspNetUsers(); string id = user.getUserId(userId); return(_context.UserCollectionMapping.Where(x => x.Id == id).Count()); } }
public async Task <bool> UpdateAccounts(string collectionsId, List <Account> accounts) { YodleeAccountModel model = new YodleeAccountModel(); List <YodleeAccountLevel> yodleeAccounts = await model.GetYodleeAccounts(collectionsId); try { using (FinPlannerContext _context = new FinPlannerContext()) { foreach (Account item in accounts) { if (item.YodleeId == 0 && item.AccountIdentifier != null) { item.YodleeId = yodleeAccounts.Where(x => x.accountNumber == item.AccountIdentifier).Select(x => x.id).FirstOrDefault(); } else { YodleeAccountLevel accountLevel = yodleeAccounts.Where(x => x.accountNumber == item.AccountIdentifier).FirstOrDefault(); if (accountLevel != null) { if (accountLevel.availableBalance != null) { item.Available = accountLevel.availableBalance.amount; } else if (accountLevel.availableCredit != null) { item.Available = accountLevel.availableCredit.amount; } else { item.Available = accountLevel.balance.amount; } } } _context.Entry(item).State = EntityState.Modified; AccountBalance balance = new AccountBalance() { AccountBalanceId = Guid.NewGuid().ToString(), AccountId = item.Id, Amount = item.Available, Date = DateTime.Now.Date }; _context.Add(balance); } _context.SaveChanges(); } return(true); } catch (Exception e) { ExceptionCatcher catcher = new ExceptionCatcher(); catcher.Catch(e.Message); return(false); } }
/// <summary> /// Retirives a list of institutions from the database /// </summary> /// <param name="dummy">bool on whether dummy institutions are to be included</param> /// <returns>A generic list of instituions that are either of dummy type or not</returns> public List <Institution> GetInstitutions(bool dummy = false) { using (FinPlannerContext _context = new FinPlannerContext()) { return(_context .Institution .Where(x => x.isDummy == dummy) .ToList()); } }
/// <summary> /// Checks if the collection is linked to more than one user /// </summary> /// <param name="collectionsId">The unique ID of the collection</param> /// <returns>Returns a bool, with true if more than one user is linked to the collection provided</returns> public bool IsShared(string collectionsId) { using (FinPlannerContext _context = new FinPlannerContext()) { return(_context .UserCollectionMapping .Where(x => x.CollectionsId == collectionsId) .Count() > 1); } }
/// <summary> /// Returns a list of the most recent transactions on a specified account of a designated count /// </summary> /// <param name="AccId">The account with which the transactions are associated</param> /// <param name="count">The count of the transactions needed, defaulted to 10</param> /// <returns></returns> public List <AutomatedCashFlow> GetAutomatedCashFlows(string AccId, int count = 10) { using (FinPlannerContext _context = new FinPlannerContext()) { return(_context .AutomatedCashFlows .Where(x => x.AccountId == AccId) .OrderByDescending(x => x.DateBooked) .Take(count) .ToList()); } }
public List <Budget> GetBudgets(string collectionsId) { using (FinPlannerContext _context = new FinPlannerContext()) { return(_context .Budget .Where(x => x.CollectionId == collectionsId) .Where(x => x.Simulation == false) .ToList()); } }
/// <summary> /// New convention for retrieving Account data /// </summary> /// <param name="collectionsIds">The collection Id associated with the accounts</param> /// <param name="dummy">Are dummy accounts to be included</param> /// <returns>List of accounts associated with the collection Id</returns> private List <Account> GetAccountsEmpty(string collectionsIds, bool dummy = false) { using (FinPlannerContext _context = new FinPlannerContext()) { return(_context .Account .Where(x => x.CollectionsId == collectionsIds) .Where(x => x.isDummy == dummy) .ToList()); } }