Пример #1
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;
     }
 }
Пример #2
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;
     }
 }
Пример #3
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;
     }
 }