Ejemplo n.º 1
0
        public List <Collections> GetCollections(string userId, string type)
        {
            List <Collections> collections = new List <Collections>();

            if (userId != "")
            {
                AspNetUsers user = new AspNetUsers();
                userId = user.getUserId(userId);
                if (type != "Index")
                {
                    using (FinPlannerContext _context = new FinPlannerContext())
                    {
                        List <string> collectionIds = _context.UserCollectionMapping
                                                      .Where(x => x.Id == userId)
                                                      .Select(x => x.CollectionsId)
                                                      .ToList();
                        foreach (string item in collectionIds)
                        {
                            switch (type)
                            {
                            case "Accounts":
                                collections.Add(new Collections(_context.Collections.Find(item), 0, type));
                                break;

                            case "TransactionList":
                                collections.Add(new Collections(_context.Collections.Find(item), 10, type));
                                break;

                            case "TransactionCount":
                                collections.Add(new Collections(_context.Collections.Find(item), 1000, type));
                                break;

                            default:
                                collections.Add(_context.Collections.Find(item));
                                break;
                            }
                        }
                    }
                    return(collections);
                }
                else
                {
                    using (FinPlannerContext _context = new FinPlannerContext())
                    {
                        List <string> collectionsIds = _context.UserCollectionMapping
                                                       .Where(x => x.Id == userId)
                                                       .Select(x => x.CollectionsId)
                                                       .ToList();
                        collections.AddRange(GetCollections(collectionsIds, 10));
                        return(collections);
                    }
                }
            }
            else
            {
                using (FinPlannerContext _context = new FinPlannerContext())
                {
                    collections = _context
                                  .Collections
                                  .ToList();
                }
                Account account = new Account();
                foreach (Collections item in collections)
                {
                    item.Accounts = account.GetAccounts(item.CollectionsId);
                }
                //what does this do? Who involes it?
                Budget budget = new Budget();
                foreach (Collections item in collections)
                {
                    item.Budgets = budget.GetBudgets(item.CollectionsId);
                }
                return(collections);
            }
        }