コード例 #1
0
 // gets user by email
 public User GetUserByEmail(string Email)
 {
     using (ContextDBDataContext context = new ContextDBDataContext(_connectionString))
     {
         return(context.Users.FirstOrDefault(User => User.Email == Email));
     }
 }
コード例 #2
0
 //returns a context, so that a new context does not have to be written in each function.
 private ContextDBDataContext ReturnContext()
 {
     using (ContextDBDataContext context = new ContextDBDataContext(_connectionString))
     {
         return(context);
     }
 }
コード例 #3
0
 public List <Category> GetAllCategories()
 {
     using (ContextDBDataContext context = new ContextDBDataContext(_connectionString))
     {
         return(context.Categories.ToList());
     }
 }
コード例 #4
0
 // returns all user objects in DB.
 public List <User> GetAllUsers()
 {
     using (ContextDBDataContext context = new ContextDBDataContext(_connectionString))
     {
         return(context.Users.ToList());
     }
 }
コード例 #5
0
 //get credits for month
 public List <Credit> GetCreditsByMonthId(int UserId, int MonthId)
 {
     using (ContextDBDataContext context = new ContextDBDataContext(_connectionString))
     {
         return(context.Credits.Where(C => C.UserId == UserId && C.MonthId == MonthId).OrderBy(C => C.Date).ToList());
     }
 }
コード例 #6
0
 public Month_Year GetMonthInfo(int MonthId)
 {
     using (ContextDBDataContext context = new ContextDBDataContext(_connectionString))
     {
         return(context.Month_Years.First(M => M.Id == MonthId));
     }
 }
コード例 #7
0
 public void AddUser(User user)
 {
     using (ContextDBDataContext context = new ContextDBDataContext(_connectionString))
     {
         context.Users.InsertOnSubmit(user);
         context.SubmitChanges();
     }
 }
コード例 #8
0
 public void AddCredit(Credit credit)
 {
     using (ContextDBDataContext context = new ContextDBDataContext(_connectionString))
     {
         context.Credits.InsertOnSubmit(credit);
         context.SubmitChanges();
     }
 }
コード例 #9
0
 public List <Debit> CategoryListWithAmounts(int MonthId)
 {
     using (ContextDBDataContext context = new ContextDBDataContext(_connectionString))
     {
         var LoadOptions = new DataLoadOptions();
         LoadOptions.LoadWith <Debit>(D => D.Category);
         context.LoadOptions = LoadOptions;
         return(context.Debits.Where(D => D.MonthId == MonthId).ToList());
     }
 }
コード例 #10
0
        public List <Debit> AddDebit(Debit debit)
        {
            using (ContextDBDataContext context = new ContextDBDataContext(_connectionString))
            {
                context.Debits.InsertOnSubmit(debit);
                context.SubmitChanges();

                return(GetDebitsByMonthId(debit.UserId, debit.MonthId));
            }
        }
コード例 #11
0
 public List <Debit> GetDebitsByMonthId(int UserId, int MonthId)
 {
     using (ContextDBDataContext context = new ContextDBDataContext(_connectionString))
     {
         var LoadOptions = new DataLoadOptions();
         LoadOptions.LoadWith <Debit>(D => D.Category);
         context.LoadOptions = LoadOptions;
         return(context.Debits.Where(D => D.UserId == UserId && D.MonthId == MonthId).OrderBy(D => D.Date).ToList());
     }
 }
コード例 #12
0
 public bool DoesMonthIdExistForUser(int UserId, int MonthId)
 {
     using (ContextDBDataContext context = new ContextDBDataContext(_connectionString))
     {
         if (context.Month_Years.Any(M => M.UserId == UserId && M.Id == MonthId))
         {
             return(true);
         }
         return(false);
     }
 }
コード例 #13
0
        public User UserWithHistory(int Id)
        {
            using (ContextDBDataContext context = new ContextDBDataContext(_connectionString))
            {
                var LoadOptions = new DataLoadOptions();
                LoadOptions.LoadWith <User>(U => U.Month_Years);
                LoadOptions.LoadWith <User>(U => U.Debits);
                LoadOptions.LoadWith <User>(U => U.Credits);
                context.LoadOptions = LoadOptions;

                return(context.Users.First(U => U.Id == Id));
            }
        }
コード例 #14
0
        // adds new month and returns false if month already exists
        public bool AddMonth(Month_Year NewMonth)
        {
            using (ContextDBDataContext context = new ContextDBDataContext(_connectionString))
            {
                if (DoesMonthExistForUser(context.Month_Years.Where(M => M.UserId == NewMonth.UserId).ToList(), NewMonth))
                {
                    return(true);
                }

                context.Month_Years.InsertOnSubmit(NewMonth);
                context.SubmitChanges();

                return(false);
            }
        }
コード例 #15
0
        // returns a list of months for user it correct date order
        public List <Month_Year> MonthYearForUser(int UserId)
        {
            using (ContextDBDataContext context = new ContextDBDataContext(_connectionString))
            {
                List <Month_Year> MonthsForUser = context.Month_Years.Where(MY => MY.UserId == UserId).OrderBy(My => My.Year).ToList();
                List <int>        DistinctYears = MonthsForUser.Select(MY => MY.Year).Distinct().ToList();
                List <Month_Year> OrderedList   = new List <Month_Year>();

                foreach (int year in DistinctYears)
                {
                    List <Month_Year> MonthsForDistincrYear = MonthsForUser.Where(MY => MY.Year == year).OrderBy(MY => MY.Month).ToList();

                    foreach (Month_Year MY in MonthsForDistincrYear)
                    {
                        OrderedList.Add(MY);
                    }
                }
                return(OrderedList);
            }
        }