Example #1
0
        public static IEnumerable <Training> GetTrainingsByUserId(decimal?Id)
        {
            var result = Enumerable.Empty <Training>();

            if (Id != null && Id != 0)
            {
                using (var db = new GymTrainingContext())
                {
                    result = db.Trainings
                             .Include(x => x.User)
                             .Include(x => x.Excersises)
                             .Where(x => x.User.Id == Id).ToList();
                }
            }
            else
            {
                using (var db = new GymTrainingContext())
                {
                    result = db.Trainings
                             .Include(x => x.User)
                             .Include(x => x.Excersises).ToList();
                }
            }

            return(result);
        }
Example #2
0
        public static void SaveOrUpdateTraining(Training val)
        {
            var context = new GymTrainingContext();

            context.Entry(val).State = System.Data.Entity.EntityState.Modified;
            context.SaveChanges();
        }
Example #3
0
        public static void DeleteTraining(decimal id)
        {
            var context = new GymTrainingContext();

            var remove = context.Trainings.Single(x => x.Id == id);

            context.Trainings.Remove(remove);
            context.SaveChanges();
        }
Example #4
0
 public static IEnumerable <Training> GetTrainings()
 {
     using (var db = new GymTrainingContext())
     {
         return(db.Trainings
                .Include(x => x.User)
                .ToList());
     }
 }
Example #5
0
 public static Training GetTrainingById(decimal Id)
 {
     using (var db = new GymTrainingContext())
     {
         return(db.Trainings
                .Include(x => x.User)
                .Include(x => x.Excersises)
                .FirstOrDefault(x => x.Id == Id));
     }
 }
Example #6
0
 public static IEnumerable <Excersise> GetExcersises()
 {
     using (var db = new GymTrainingContext())
     {
         return(db.Excersises
                .Include(x => x.ExcersiseType)
                .Include(x => x.RepeatSets.Select(y => y.WeightUnit))
                .ToList());
     }
 }
Example #7
0
        public static IEnumerable <User> GetUsers()
        {
            using (var db = new GymTrainingContext())
            {
                var t = db.Users
                        .Where(x => x.IsActive)
                        .ToList();

                return(t);
            }
        }
Example #8
0
        public static User GetUserWithTrainingsByUserId(decimal?Id)
        {
            User result = null;

            if (Id != null && Id != 0)
            {
                using (var db = new GymTrainingContext())
                {
                    result = db.Users
                             .Include(x => x.Trainings)
                             .FirstOrDefault(x => x.Id == Id);
                }
            }

            return(result);
        }