Ejemplo n.º 1
0
        public void Save <T>(List <T> obj) where T : class
        {
            using (var db = new FitnessContext())
            {
                db.Set <T>().AddRange(obj);

                #region if-else
                //var type = typeof(T);
                //if (type == typeof(User))
                //{
                //    db.Users.Add(obj as User);
                //}
                //else if (type == typeof(Activity))
                //{
                //    db.Activities.Add(obj as Activity);
                //}
                //else if (type == typeof(Exercise))
                //{
                //    db.Exercisies.Add(obj as Exercise);
                //}
                //else if (type == typeof(Eating))
                //{
                //    db.Eating.Add(obj as Eating);
                //}
                //else if (type == typeof(Food))
                //{
                //    db.Foods.Add(obj as Food);
                //}
                //else if (type == typeof(Gender))
                //{
                //    db.Gender.Add(obj as Gender);
                //}
                #endregion

                db.SaveChanges();
            }
        }