Пример #1
0
 public List <ProfilePost> GetAll(long profileId)
 {
     using (var _ctx = new DatingContext())
     {
         var friends = _ctx.Set <ProfilePost>().Where(x => x.ProfileId == profileId).OrderByDescending(x => x.Date).Include(x => x.FriendUserProfile).Include(x => x.Profile);
         return(friends.ToList());
     }
 }
 public List <FriendProfile> GetAllFavourites(long profileId)
 {
     using (var _ctx = new DatingContext())
     {
         var friends = _ctx.Set <FriendProfile>().Where(x => x.ProfileId == profileId && x.FriendUserProfile.Active && x.IsFavourite).Include(x => x.FriendUserProfile).Include(x => x.Profile);
         return(friends.ToList());
     }
 }
Пример #3
0
 public Profile GetById(long profileId)
 {
     using (var _ctx = new DatingContext())
     {
         var profile = _ctx.Set <Profile>().Where(x => x.Id == profileId).Include(x => x.Hobbies);
         return(profile.FirstOrDefault());
     }
 }
 public FriendProfile GetById(long friendProfileId)
 {
     using (var _ctx = new DatingContext())
     {
         var profile = _ctx.Set <FriendProfile>().Where(x => x.Id == friendProfileId);
         return(profile.FirstOrDefault());
     }
 }
Пример #5
0
 public List <Profile> GetAll()
 {
     using (var _ctx = new DatingContext())
     {
         var profiles = _ctx.Set <Profile>().Where(x => x.Active).Include(x => x.Hobbies.Select(y => y.Hobbie));
         return(profiles.ToList());
     }
 }
Пример #6
0
 public List <Profile> GetFirstFiveProfiles()
 {
     using (var _ctx = new DatingContext())
     {
         var profile = _ctx.Set <Profile>().OrderBy(x => x.CreatedDate).Take(5);
         return(profile.ToList());
     }
 }
Пример #7
0
 public Profile GetByUserName(string userName)
 {
     using (var _ctx = new DatingContext())
     {
         var profile = _ctx.Set <Profile>().Where(x => x.UserName == userName);
         return(profile.FirstOrDefault());
     }
 }
Пример #8
0
 public List <Hobbie> GetAll()
 {
     using (var _ctx = new DatingContext())
     {
         var hobbies = _ctx.Set <Hobbie>();
         return(hobbies.ToList());
     }
 }
 public bool AreFriends(string userId, string friendUserId)
 {
     using (var _ctx = new DatingContext())
     {
         var friends = _ctx.Set <FriendRequest>().Where(x => (x.UserId == userId && x.FriendRequestUserId == friendUserId) || (x.UserId == friendUserId && x.FriendRequestUserId == userId));
         return(friends.FirstOrDefault() != null && friends.FirstOrDefault().IsFriend);
     }
 }
 public List <FriendRequest> GetFriendRequests(string userId)
 {
     using (var _ctx = new DatingContext())
     {
         var friends = _ctx.Set <FriendRequest>().Where(x => x.FriendRequestUserId == userId && !x.IsFriend).Include(x => x.Profile);
         return(friends.ToList());
     }
 }
 public List <Profile> GetLastFiveVisitors(long profileId)
 {
     using (var _ctx = new DatingContext())
     {
         var friends = _ctx.Set <VisitorProfile>().Where(x => x.ProfileId == profileId && x.FriendUserProfile.Active)
                       .OrderByDescending(x => x.Date).Take(5).Select(x => x.FriendUserProfile).GroupBy(p => p.Id).Select(g => g.FirstOrDefault());
         return(friends.ToList());
     }
 }
Пример #12
0
 public void Remove(long?profilePostId)
 {
     using (var _ctx = new DatingContext())
     {
         var profilePost = _ctx.Set <ProfilePost>().Where(x => x.Id == profilePostId).FirstOrDefault();
         _ctx.Entry <ProfilePost>(profilePost).State = System.Data.Entity.EntityState.Deleted;
         _ctx.SaveChanges();
     }
 }
        public FriendRequest GetById(long friendRequestId)
        {
            using (var _ctx = new DatingContext())
            {
                var friends = _ctx.Set <FriendRequest>().Where(x => x.Id == friendRequestId);

                return(friends.FirstOrDefault());
            }
        }
Пример #14
0
 public List <Profile> GetByFilters(string searchString, long?genderTarget)
 {
     using (var _ctx = new DatingContext())
     {
         var profile = _ctx.Set <Profile>().Where(x => x.Active && ((string.IsNullOrEmpty(searchString) || x.UserName.Contains(searchString)) ||
                                                                    (x.FirstName.Contains(searchString) || x.LastName.Contains(searchString))) &&
                                                  (genderTarget == null || x.GenderId == genderTarget)).Include(x => x.Hobbies);
         return(profile.ToList());
     }
 }
 public FriendProfile Add(FriendProfile friend)
 {
     using (var _ctx = new DatingContext())
     {
         var foundFriend = _ctx.Set <FriendProfile>().Any(x => x.FriendProfileId == friend.FriendProfileId && x.ProfileId == friend.ProfileId);
         if (!foundFriend)
         {
             _ctx.Entry <FriendProfile>(friend).State = System.Data.Entity.EntityState.Added;
             _ctx.SaveChanges();
         }
         return(friend);
     }
 }
        public FriendRequest AcceptFriendRequest(long friendRequestId)
        {
            using (var _ctx = new DatingContext())
            {
                var friends = _ctx.Set <FriendRequest>().Where(x => x.Id == friendRequestId);

                var friendRequest = friends.FirstOrDefault();

                friendRequest.IsFriend = true;

                _ctx.Entry(friendRequest).State = EntityState.Modified;

                _ctx.SaveChanges();

                return(friendRequest);
            }
        }