Ejemplo n.º 1
0
 public static List <Meal> Load()
 {
     //Retrieve all the rows in a list
     try
     {
         List <Meal> rows = new List <Meal>();
         using (AmbrosiaEntities dc = new AmbrosiaEntities())
         {
             dc.tblMeals
             .ToList()
             .ForEach(g => rows.Add(new Meal
             {
                 Id          = g.Id,
                 UserId      = g.UserId,
                 Description = g.Description,
                 Time        = g.Time,
                 FoodItems   = FoodItemManager.Load(g.Id)
             }));
             return(rows);
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Ejemplo n.º 2
0
 public static Meal LoadById(Guid id)
 {
     try
     {
         using (AmbrosiaEntities dc = new AmbrosiaEntities())
         {
             tblMeal row = dc.tblMeals.FirstOrDefault(g => g.Id == id);
             if (row != null)
             {
                 Meal meal = new Meal
                 {
                     Id          = row.Id,
                     UserId      = row.UserId,
                     Description = row.Description,
                     Time        = row.Time,
                     FoodItems   = FoodItemManager.Load(row.Id)
                 };
                 return(meal);
             }
             else
             {
                 throw new Exception("Row was not found!");
             }
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Ejemplo n.º 3
0
 public static Food LoadById(int fdcid)
 {
     try
     {
         using (AmbrosiaEntities dc = new AmbrosiaEntities())
         {
             tblFoodItem row = dc.tblFoodItems.FirstOrDefault(g => g.FDCId == fdcid);
             if (row != null)
             {
                 FoodItem foodItem = new FoodItem
                 {
                     Id       = row.Id,
                     FDCId    = row.FDCId,
                     MealId   = row.MealId,
                     Quantity = row.Quantity
                 };
                 return(fdcFoodManager.Search(foodItem));
             }
             else
             {
                 throw new Exception("Row was not found!");
             }
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Ejemplo n.º 4
0
 public static List <Workout> Load(Guid userId)
 {
     //Retrieve all the rows in a list
     try
     {
         List <Workout> rows = new List <Workout>();
         using (AmbrosiaEntities dc = new AmbrosiaEntities())
         {
             dc.tblWorkouts
             .Where(w => w.UserId == userId)
             .ToList()
             .ForEach(g => rows.Add(new Workout
             {
                 Id          = g.Id,
                 WorkoutType = WorkoutTypeManager.LoadById(g.WorkoutTypeId),
                 StartTime   = g.StartTime,
                 EndTime     = g.EndTime,
                 UserId      = g.UserId
             }));
             return(rows);
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Ejemplo n.º 5
0
 public static User LoadById(Guid id)
 {
     try
     {
         using (AmbrosiaEntities dc = new AmbrosiaEntities())
         {
             tblUser row = dc.tblUsers.FirstOrDefault(g => g.Id == id);
             if (row != null)
             {
                 User user = new User
                 {
                     Id        = row.Id,
                     FirstName = row.FirstName,
                     LastName  = row.LastName,
                     Username  = row.Username,
                     Password  = row.Password,
                     Meals     = MealManager.Load(row.Id),
                     Workouts  = WorkoutManager.Load(row.Id)
                 };
                 return(user);
             }
             else
             {
                 throw new Exception("Row was not found!");
             }
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Ejemplo n.º 6
0
 //changed this method to return a List. Also renamed
 public static List <Meal> Load(Guid userId)
 {
     try
     {
         using (AmbrosiaEntities dc = new AmbrosiaEntities())
         {
             List <Meal> meals = new List <Meal>();
             dc.tblMeals
             .Where(r => r.UserId == userId)
             .ToList()
             .ForEach(g => meals.Add(new Meal {
                 Id          = g.Id,
                 UserId      = g.UserId,
                 Description = g.Description,
                 Time        = g.Time,
                 FoodItems   = FoodItemManager.Load(g.Id)
             }));
             return(meals);
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Ejemplo n.º 7
0
 public static List <Food> Load(Guid mealId)
 {
     //Retrieve all the rows in a list
     try
     {
         List <FoodItem> rows = new List <FoodItem>();
         using (AmbrosiaEntities dc = new AmbrosiaEntities())
         {
             dc.tblFoodItems
             .Where(g => g.MealId == mealId)
             .ToList()
             .ForEach(g => rows.Add(new FoodItem
             {
                 Id       = g.Id,
                 FDCId    = g.FDCId,
                 MealId   = g.MealId,
                 Quantity = g.Quantity
             }));
             List <Food> foods = new List <Food>();
             foreach (FoodItem foodItem in rows)
             {
                 foods.Add(fdcFoodManager.Search(foodItem));
             }
             return(foods);
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Ejemplo n.º 8
0
 public static Workout LoadById(Guid id)
 {
     try
     {
         using (AmbrosiaEntities dc = new AmbrosiaEntities())
         {
             tblWorkout row = dc.tblWorkouts.FirstOrDefault(g => g.Id == id);
             if (row != null)
             {
                 Workout workout = new Workout
                 {
                     Id          = row.Id,
                     WorkoutType = WorkoutTypeManager.LoadById(row.WorkoutTypeId),
                     StartTime   = row.StartTime,
                     EndTime     = row.EndTime,
                     UserId      = row.UserId
                 };
                 return(workout);
             }
             else
             {
                 throw new Exception("Row was not found!");
             }
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Ejemplo n.º 9
0
        public static List <User> Load()
        {
            //Retrieve all the rows in a list
            try
            {
                List <User> rows = new List <User>();
                using (AmbrosiaEntities dc = new AmbrosiaEntities())
                {
                    dc.tblUsers
                    .ToList()
                    .ForEach(g => rows.Add(new User
                    {
                        Id        = g.Id,
                        FirstName = g.FirstName,
                        LastName  = g.LastName,
                        Username  = g.Username,
                        Password  = g.Password,
                        Meals     = MealManager.Load(g.Id),
                        Workouts  = WorkoutManager.Load(g.Id)
                    }));

                    return(rows);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 10
0
 public static WorkoutType LoadById(Guid id)
 {
     try
     {
         using (AmbrosiaEntities dc = new AmbrosiaEntities())
         {
             tblWorkoutType row = dc.tblWorkoutTypes.FirstOrDefault(g => g.Id == id);
             if (row != null)
             {
                 WorkoutType workoutType = new WorkoutType
                 {
                     Id   = row.Id,
                     Name = row.Name,
                     CaloriesPerMinute = row.CaloriesPerMinute
                 };
                 return(workoutType);
             }
             else
             {
                 throw new Exception("Row was not found!");
             }
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Ejemplo n.º 11
0
        public void LoadTest()
        {
            using (AmbrosiaEntities dc = new AmbrosiaEntities())
            {
                DbContextTransaction transaction = null;
                tblUser row = dc.tblUsers.FirstOrDefault(u => u.FirstName == "Phillip");

                Assert.IsTrue(row != null);
                transaction.Rollback();
            }
        }
Ejemplo n.º 12
0
        public void LoadTest()
        {
            using (AmbrosiaEntities dc = new AmbrosiaEntities())
            {
                DbContextTransaction transaction = null;
                tblWorkout           row         = dc.tblWorkouts.FirstOrDefault();

                Assert.IsTrue(row != null);
                transaction.Rollback();
            }
        }
Ejemplo n.º 13
0
        public void LoadTest()
        {
            using (AmbrosiaEntities dc = new AmbrosiaEntities())
            {
                DbContextTransaction transaction = null;
                tblFoodItem          row         = dc.tblFoodItems.FirstOrDefault(fi => fi.FDCId == 1);

                Assert.IsTrue(row != null);
                transaction.Rollback();
            }
        }
Ejemplo n.º 14
0
        public void LoadTest()
        {
            using (AmbrosiaEntities dc = new AmbrosiaEntities())
            {
                DbContextTransaction transaction = null;
                tblMeal row = dc.tblMeals.FirstOrDefault(m => m.Description == "Ate 4 eggs");

                Assert.IsTrue(row != null);
                transaction.Rollback();
            }
        }
Ejemplo n.º 15
0
        public void LoadTest()
        {
            using (AmbrosiaEntities dc = new AmbrosiaEntities())
            {
                DbContextTransaction transaction = null;
                tblWorkoutType       row         = dc.tblWorkoutTypes.FirstOrDefault(w => w.Name == "Computer Programming");

                Assert.IsTrue(row != null);
                transaction.Rollback();
            }
        }
Ejemplo n.º 16
0
        public void DeleteTest()
        {
            using (AmbrosiaEntities dc = new AmbrosiaEntities())
            {
                DbContextTransaction transaction = null;
                tblWorkoutType       row         = dc.tblWorkoutTypes.FirstOrDefault(w => w.Name == "Computer Programming");

                dc.tblWorkoutTypes.Remove(row);
                Assert.IsTrue(dc.SaveChanges() == 1);
                transaction.Rollback();
            }
        }
Ejemplo n.º 17
0
        public void DeleteTest()
        {
            using (AmbrosiaEntities dc = new AmbrosiaEntities())
            {
                DbContextTransaction transaction = null;
                tblUser row = dc.tblUsers.FirstOrDefault(u => u.FirstName == "Phillip");

                dc.tblUsers.Remove(row);
                Assert.IsTrue(dc.SaveChanges() == 1);
                transaction.Rollback();
            }
        }
Ejemplo n.º 18
0
        public void UpdateTest()
        {
            using (AmbrosiaEntities dc = new AmbrosiaEntities())
            {
                DbContextTransaction transaction = null;
                tblUser row = dc.tblUsers.FirstOrDefault(u => u.FirstName == "Phillip");
                row.Username = "******";

                Assert.IsTrue(dc.SaveChanges() == 1);
                transaction.Rollback();
            }
        }
Ejemplo n.º 19
0
        public void DeleteTest()
        {
            using (AmbrosiaEntities dc = new AmbrosiaEntities())
            {
                DbContextTransaction transaction = null;
                tblFoodItem          row         = dc.tblFoodItems.FirstOrDefault(fi => fi.FDCId == 1);

                dc.tblFoodItems.Remove(row);
                Assert.IsTrue(dc.SaveChanges() == 1);
                transaction.Rollback();
            }
        }
Ejemplo n.º 20
0
        public void DeleteTest()
        {
            using (AmbrosiaEntities dc = new AmbrosiaEntities())
            {
                DbContextTransaction transaction = null;
                tblMeal row = dc.tblMeals.FirstOrDefault(m => m.Description == "Ate 4 eggs");

                dc.tblMeals.Remove(row);
                Assert.IsTrue(dc.SaveChanges() == 1);
                transaction.Rollback();
            }
        }
Ejemplo n.º 21
0
        public void UpdateTest()
        {
            using (AmbrosiaEntities dc = new AmbrosiaEntities())
            {
                DbContextTransaction transaction = null;
                tblWorkout           row         = dc.tblWorkouts
                                                   .FirstOrDefault(w => w.UserId == dc.tblUsers.FirstOrDefault(u => u.FirstName == "Phillip").Id);
                row.EndTime = DateTime.Now;

                Assert.IsTrue(dc.SaveChanges() == 1);
                transaction.Rollback();
            }
        }
Ejemplo n.º 22
0
        public static bool Login(User user)
        {
            try
            {
                if (!string.IsNullOrEmpty(user.Username.ToString()))
                {
                    if (!string.IsNullOrEmpty(user.Password))
                    {
                        using (AmbrosiaEntities dc = new AmbrosiaEntities())
                        {
                            tblUser tblUser = dc.tblUsers.FirstOrDefault(u => u.Username == user.Username);
                            if (tblUser != null)
                            {
                                //Check password
                                if (tblUser.Password == GetHash(user.Password))
                                {
                                    //User could login
                                    user.FirstName = tblUser.FirstName;
                                    user.LastName  = tblUser.LastName;
                                    user.Id        = tblUser.Id;
                                    user.Meals     = MealManager.Load(user.Id);
                                    user.Workouts  = WorkoutManager.Load(user.Id);

                                    return(true);
                                }
                                else
                                {
                                    throw new Exception("Could not login with these credentials");
                                }
                            }
                            else
                            {
                                throw new Exception("UserId could not be found");
                            }
                        }
                    }
                    else
                    {
                        throw new Exception("Password was not set");
                    }
                }
                else
                {
                    throw new Exception("UserId was not set");
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 23
0
        public void InsertTest()
        {
            using (AmbrosiaEntities dc = new AmbrosiaEntities())
            {
                DbContextTransaction transaction = null;
                tblWorkoutType       row         = new tblWorkoutType
                {
                    Id   = Guid.NewGuid(),
                    Name = "Computer Programming",
                    CaloriesPerMinute = 0
                };
                dc.tblWorkoutTypes.Add(row);

                Assert.IsTrue(dc.SaveChanges() == 1);
                transaction.Rollback();
            }
        }
Ejemplo n.º 24
0
        public static int Insert(Meal meal, bool rollback = false)
        {
            try
            {
                int results;

                using (AmbrosiaEntities dc = new AmbrosiaEntities())
                {
                    DbContextTransaction transaction = null;
                    if (rollback)
                    {
                        transaction = dc.Database.BeginTransaction();
                    }
                    // Make a new row
                    tblMeal row = new tblMeal();

                    // Set the properties
                    row.Id          = Guid.NewGuid();
                    row.UserId      = meal.UserId;
                    row.Description = meal.Description;
                    row.Time        = meal.Time;


                    // Back fill the Id on the  object (parameter)
                    meal.Id = row.Id;

                    // Insert the row
                    dc.tblMeals.Add(row);
                    results = dc.SaveChanges();

                    //insert the food items
                    FoodItemManager.InsertList(meal.FoodItems, meal.Id);

                    if (rollback)
                    {
                        transaction.Rollback();
                    }
                }
                return(results);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 25
0
        public void InsertTest()
        {
            using (AmbrosiaEntities dc = new AmbrosiaEntities())
            {
                DbContextTransaction transaction = null;
                tblMeal row = new tblMeal
                {
                    Id          = Guid.NewGuid(),
                    Description = "Ate 4 eggs",
                    Time        = DateTime.Now,
                    UserId      = dc.tblUsers.FirstOrDefault(m => m.FirstName == "Phillip").Id
                };
                dc.tblMeals.Add(row);

                Assert.IsTrue(dc.SaveChanges() == 1);
                transaction.Rollback();
            }
        }
Ejemplo n.º 26
0
        public void InsertTest()
        {
            using (AmbrosiaEntities dc = new AmbrosiaEntities())
            {
                DbContextTransaction transaction = null;
                tblFoodItem          row         = new tblFoodItem
                {
                    Id       = Guid.NewGuid(),
                    FDCId    = 1,
                    MealId   = dc.tblMeals.FirstOrDefault(m => m.Description == "Ate 4 eggs").Id,
                    Quantity = 1
                };
                dc.tblFoodItems.Add(row);

                Assert.IsTrue(dc.SaveChanges() == 1);
                transaction.Rollback();
            }
        }
Ejemplo n.º 27
0
        public static int Insert(User user, bool rollback = false)
        {
            try
            {
                int results;

                using (AmbrosiaEntities dc = new AmbrosiaEntities())
                {
                    DbContextTransaction transaction = null;
                    if (rollback)
                    {
                        transaction = dc.Database.BeginTransaction();
                    }
                    // Make a new row
                    tblUser row = new tblUser();

                    // Set the properties
                    row.Id        = Guid.NewGuid();
                    row.FirstName = user.FirstName;
                    row.LastName  = user.LastName;
                    row.Username  = user.Username;
                    row.Password  = GetHash(user.Password);


                    // Back fill the Id on the  object (parameter)
                    user.Id = row.Id;


                    // Insert the row
                    dc.tblUsers.Add(row);

                    results = dc.SaveChanges();
                    if (rollback)
                    {
                        transaction.Rollback();
                    }
                }
                return(results);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 28
0
        public static int Insert(Workout workout, bool rollback = false)
        {
            try
            {
                int results;

                using (AmbrosiaEntities dc = new AmbrosiaEntities())
                {
                    DbContextTransaction transaction = null;
                    if (rollback)
                    {
                        transaction = dc.Database.BeginTransaction();
                    }
                    // Make a new row
                    tblWorkout row = new tblWorkout();

                    // Set the properties
                    row.Id            = Guid.NewGuid();
                    row.WorkoutTypeId = workout.WorkoutType.Id;
                    row.StartTime     = workout.StartTime;
                    row.EndTime       = workout.EndTime;
                    row.UserId        = workout.UserId;


                    // Back fill the Id on the  object (parameter)
                    workout.Id = row.Id;

                    // Insert the row
                    dc.tblWorkouts.Add(row);

                    results = dc.SaveChanges();
                    if (rollback)
                    {
                        transaction.Rollback();
                    }
                }
                return(results);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 29
0
        public void InsertTest()
        {
            using (AmbrosiaEntities dc = new AmbrosiaEntities())
            {
                DbContextTransaction transaction = null;
                tblWorkout           row         = new tblWorkout
                {
                    Id            = Guid.NewGuid(),
                    StartTime     = DateTime.Now,
                    EndTime       = DateTime.Now,
                    UserId        = dc.tblUsers.FirstOrDefault(u => u.FirstName == "Phillip").Id,
                    WorkoutTypeId = dc.tblWorkoutTypes.FirstOrDefault(w => w.Name == "Computer Programming").Id
                };
                dc.tblWorkouts.Add(row);

                Assert.IsTrue(dc.SaveChanges() == 1);
                transaction.Rollback();
            }
        }
Ejemplo n.º 30
0
        public void InsertTest()
        {
            using (AmbrosiaEntities dc = new AmbrosiaEntities())
            {
                DbContextTransaction transaction = null;
                tblUser row = new tblUser
                {
                    Id        = Guid.NewGuid(),
                    FirstName = "Phillip",
                    LastName  = "Fry",
                    Username  = "******",
                    Password  = "******"
                };
                dc.tblUsers.Add(row);

                Assert.IsTrue(dc.SaveChanges() == 1);
                transaction.Rollback();
            }
        }