public void AddFriend(string my_login, string friend_login) { Trainee me = db.Trainees.Get(my_login); Trainee friend = db.Trainees.Get(friend_login); Friend friend0 = db.Friends .Find(x => (x.TraineeOne_Login == my_login && x.TraineeTwo_Login == friend_login) || (x.TraineeTwo_Login == my_login && x.TraineeOne_Login == friend_login)) .FirstOrDefault(); if (me != null && friend != null && friend0 == null) { NotificationsService service = new NotificationsService(sm); service.AddNotification($"User {me.Login} want to be friends", friend_login); Friend new_friend = new Friend() { Trainee1 = me, Trainee2 = friend, Accepted = false }; db.Friends.Create(new_friend); db.Save(); } }
public void AddSubscribe(string my_login, string coach_login) { Trainee me = db.Trainees.Get(my_login); Coach coach = db.Coaches.Get(coach_login); Subscribe subscribe = db.Subscribes .Find(x => x.Coach_Login == coach_login && x.Trainee_Login == my_login) .FirstOrDefault(); if (me != null && coach != null && subscribe == null) { NotificationsService service = new NotificationsService(sm); service.AddNotification($"User {me.Login} followed you", coach_login); Subscribe new_subscribe = new Subscribe() { Trainee = me, Coach = coach }; db.Subscribes.Create(new_subscribe); db.Save(); } }