Esempio n. 1
0
 /// <summary>
 /// single object add
 /// </summary>
 /// <param name="session">the session to be added</param>
 public void AddSession(Session session)
 {
     using (WorkoutPlannerContext context = new WorkoutPlannerContext())
     {
         context.Sessions.Add(session);
         context.SaveChanges();
     }
 }
Esempio n. 2
0
 /// <summary>
 /// single object add
 /// </summary>
 /// <param name="comment">comment to be added</param>
 public void AddComment(Comment comment)
 {
     using (WorkoutPlannerContext context = new WorkoutPlannerContext())
     {
         context.Comments.Add(comment);
         context.SaveChanges();
     }
 }
Esempio n. 3
0
 /// <summary>
 /// single object add
 /// </summary>
 /// <param name="achievement">the Achievement to be added</param>
 public void AddAchievement(Achievement achievement)
 {
     using (WorkoutPlannerContext context = new WorkoutPlannerContext())
     {
         context.Achievements.Add(achievement);
         context.SaveChanges();
     }
 }
Esempio n. 4
0
 /// <summary>
 /// single object add
 /// </summary>
 /// <param name="userAchievement">UserAchievement to be added</param>
 public void AddUserAchievement(UserAchievement userAchievement)
 {
     using (WorkoutPlannerContext context = new WorkoutPlannerContext())
     {
         context.UserAchievements.Add(userAchievement);
         context.SaveChanges();
     }
 }
Esempio n. 5
0
 /// <summary>
 /// multiple object add
 /// </summary>
 /// <param name="tracks">the track collection to be added to the databse</param>
 public void AddTracks(ICollection <Track> tracks)
 {
     using (WorkoutPlannerContext context = new WorkoutPlannerContext())
     {
         context.Tracks.AddRange(tracks);
         context.SaveChanges();
     }
 }
Esempio n. 6
0
 /// <summary>
 /// single object add
 /// </summary>
 /// <param name="workout">Workout to be added</param>
 public void AddWorkout(Workout workout)
 {
     using (WorkoutPlannerContext context = new WorkoutPlannerContext())
     {
         context.Workouts.Add(workout);
         context.SaveChanges();
     }
 }
Esempio n. 7
0
 /// <summary>
 /// Single object add
 /// </summary>
 /// <param name="track"> The track object to be added to database</param>
 public void AddTrack(Track track)
 {
     using (WorkoutPlannerContext context = new WorkoutPlannerContext())
     {
         context.Tracks.Add(track);
         context.SaveChanges();
     }
 }
Esempio n. 8
0
 /// <summary>
 /// single object add
 /// </summary>
 /// <param name="user">User to be added</param>
 public void AddUser(User user)
 {
     using (WorkoutPlannerContext context = new WorkoutPlannerContext())
     {
         context.Users.Add(user);
         context.SaveChanges();
     }
 }
Esempio n. 9
0
 /// <summary>
 /// single object delete
 /// </summary>
 /// <param name="sessionId">id of session to be deleted</param>
 public void RemoveSessionById(int sessionId)
 {
     using (WorkoutPlannerContext context = new WorkoutPlannerContext())
     {
         Session session = context.Sessions.Find(sessionId);
         context.Sessions.Remove(session);
         context.SaveChanges();
     }
 }
Esempio n. 10
0
 /// <summary>
 /// single object update
 /// </summary>
 /// <param name="workout"></param>
 public void UpdateWorkoutTime(Workout workout)
 {
     using (WorkoutPlannerContext context = new WorkoutPlannerContext())
     {
         var targetWorkout = context.Workouts.Find(workout.Id);
         targetWorkout.Minutes = workout.Minutes;
         context.Workouts.Update(targetWorkout);
         context.SaveChanges();
     }
 }
Esempio n. 11
0
 /// <summary>
 /// multiple object delete,
 /// deletes all sessions from a user
 /// </summary>
 /// <param name="userId">user id to be matched</param>
 public void RemoveSessionsByUserId(int userId)
 {
     using (WorkoutPlannerContext context = new WorkoutPlannerContext())
     {
         var sessions = context.Sessions
                        .Where(s => s.UserId == userId)
                        .ToList();
         context.Sessions.RemoveRange(sessions);
         context.SaveChanges();
     }
 }