public static void SendMessage(Message message)
 {
     using(var database = new SuperAtletenEntities())
     {
         database.Messages.Add(message);
         database.SaveChanges();
     }
 }
 public static void changeProfilePic(int userid, string imageName)
 {
     using (var database = new SuperAtletenEntities())
     {
         var user = database.Users.Where(b => b.Id == userid).FirstOrDefault();
         user.Image = imageName;
         database.SaveChanges();
     }
 }
 public static void deleteMessage(int messageID)
 {
     using (var database = new SuperAtletenEntities())
     {
         var messageToRemove = database.Messages.FirstOrDefault(b => b.MessageID == messageID);
         database.Messages.Remove(messageToRemove);
         database.SaveChanges();
     }
 }
        public static void MarkTheMessageRead(int messageID)
        {
            using (var database = new SuperAtletenEntities())
            {
                var messageToUpdate = database.Messages.FirstOrDefault(b => b.MessageID == messageID);
                messageToUpdate.Status=true;

                database.SaveChanges();
            }
        }
        public static int addWorkout(Trainingsession workout, int currentUserId)
        {
            using (var database = new SuperAtletenEntities())
               {
               database.Trainingsessions.Create();
               database.Trainingsessions.Add(workout);
               database.SaveChanges();

               database.Entry(workout).GetDatabaseValues();
               int traingsID = workout.trainingSessionID;
               var HaveDone = database.HaveDone_trainingsession.Create();
               HaveDone.UserID = currentUserId;
               HaveDone.TrainingSessionID = traingsID;
               HaveDone.Date = DateTime.Now;
               database.HaveDone_trainingsession.Add(HaveDone);
               database.SaveChanges();

               return traingsID;
               }
        }
 public static void RegisterUser(User user)
 {
     using (var database = new SuperAtletenEntities())
     {
         database.Users.Create();
         user.Role = "U";
         user.Image = "empty.png";
         user.About = "Ej fyllt i ännu";
         database.Users.Add(user);
         database.SaveChanges();
     }
 }
        public static void AddFriendRequest(int currentUserId, int friendId)
        {
            var user = currentUserId;
               var friend = friendId;
               using (var database = new SuperAtletenEntities())
               {
               var newFriendRequest = new Friend_Request
               {
                   SenderID = user,
                   ReciverID = friend,
                   Status = null
               };

               database.Friend_Request.Add(newFriendRequest);
               database.SaveChanges();
               }
        }
        public static void AddFriend(int currentUserId, int friendId)
        {
            var user = currentUserId;
               var friend = friendId;

               using (var database = new SuperAtletenEntities())
               {
               var newFriend = new Friend
               {
                   Friend1 = user,
                   Friend2 = friend,
               };

               database.Friends.Add(newFriend);
               database.SaveChanges();
               }
        }
        public static void addWorkoutExercises(int workoutID,List<TrainingIncludes_StrengthExercise> listOfExercises)
        {
            using(var database = new SuperAtletenEntities())
               {
               foreach(var exercise in listOfExercises)
               {
                  var ex =  database.TrainingIncludes_StrengthExercise.Create();
                   ex.TrainingSessionID = workoutID;
                   ex.Repetitions = exercise.Repetitions;
                   ex.Weight = exercise.Weight; ;
                   ex.StrengthExerciseID = exercise.StrengthExerciseID;
                   ex.BodyWeight = exercise.BodyWeight;
                   database.TrainingIncludes_StrengthExercise.Add(ex);

               }
               database.SaveChanges();

               }
        }
        public static bool changePassword(int userid,string Newpassword,string passwordSalt,string Oldpassword)
        {
            using (var database = new SuperAtletenEntities())
            {
                var user = database.Users.Where(b => b.Id == userid).FirstOrDefault();

                if (user != null)
                {
                    var crypto = new SimpleCrypto.PBKDF2();
                    if(user.Password == crypto.Compute(Oldpassword, user.PasswordSalt))
                    {
                        user.Password = Newpassword;
                        user.PasswordSalt = passwordSalt;
                        database.SaveChanges();
                        return true;
                    }
                }
            }
            return false;
        }
        public static void RemoveFriendRequest(int currentUserId, int friendId)
        {
            using (var database = new SuperAtletenEntities())
               {
               var friendRequest = database.Friend_Request
                   .FirstOrDefault(x => x.ReciverID == currentUserId && x.SenderID == friendId);
               if (friendRequest == null) friendRequest = database.Friend_Request
                   .FirstOrDefault(x => x.ReciverID == friendId && x.SenderID == currentUserId);

               database.Friend_Request.Remove(friendRequest);
               database.SaveChanges();
               }
        }
        public static void RemoveFriend(int currentUserId, int friendId)
        {
            using (var database = new SuperAtletenEntities())
               {
               var friend = database.Friends.FirstOrDefault(x => x.Friend1 == currentUserId && x.Friend2 == friendId
                   || x.Friend2 == currentUserId && x.Friend1 == friendId);

               database.Friends.Remove(friend);
               database.SaveChanges();
               }
        }