Exemple #1
0
        public ResponseVM Unfollow(int followerID, int followingID)
        {
            UsersFollowing obj = db.UsersFollowing.Where(x => x.FollowerID == followerID &&
                                                         x.FollowingID == followingID).SingleOrDefault();

            if (obj == null)
            {
                return new ResponseVM
                       {
                           responseCode    = 400,
                           responseMessage = "An error occured."
                       }
            }
            ;

            db.UsersFollowing.Remove(obj);
            db.SaveChanges();

            return(new ResponseVM
            {
                responseCode = 200,
                responseMessage = "Ok."
            });
        }
    }
Exemple #2
0
        public ResponseVM Follow(int followerID, int followingID)
        {
            UsersFollowing obj = new UsersFollowing()
            {
                DateModified = DateTime.Now,
                FollowerID   = followerID,
                FollowingID  = followingID
            };

            if (obj == null)
            {
                return new ResponseVM
                       {
                           responseCode    = 400,
                           responseMessage = "An error occured."
                       }
            }
            ;

            db.UsersFollowing.Add(obj);
            db.SaveChanges();

            return(new ResponseVM
            {
                responseCode = 200,
                responseMessage = "Ok."
            });
        }
Exemple #3
0
        public List <SearchUsersVM> SearchUsers(string word, int userID)
        {
            List <SearchUsersVM> lista = db.Users
                                         .Where(x => x.Username.Contains(word) || x.Nickname.Contains(word))
                                         .Select(x => new SearchUsersVM
            {
                userID     = x.UserID,
                nickname   = x.Nickname,
                username   = x.Username,
                following  = false,
                profileImg = x.ProfileImage
            }).ToList();

            SearchUsersVM myProfile = null;

            foreach (var item in lista)
            {
                UsersFollowing temp = db.UsersFollowing
                                      .Where(x => x.FollowingID == item.userID && x.FollowerID == userID).FirstOrDefault();
                if (temp != null)
                {
                    item.following = true;
                }
                if (item.userID == userID)
                {
                    myProfile = item;
                }
            }
            if (myProfile != null)
            {
                lista.Remove(myProfile);
            }
            return(lista);
        }
Exemple #4
0
        public IHttpActionResult PostUser(RegistrationVM obj)
        {
            Users newUser = new Users()
            {
                Active    = true,
                BirthDate = obj.birthDate,
                CountryID = obj.countryID,
                Email     = obj.email,
                Password  = obj.password,
                Nickname  = obj.nickname,
                Username  = obj.username
            };

            db.Users.Add(newUser);
            db.SaveChanges();

            UsersFollowing firstFollowing = new UsersFollowing()
            {
                DateModified = DateTime.Now,
                FollowerID   = newUser.UserID,
                FollowingID  = newUser.UserID
            };

            db.UsersFollowing.Add(firstFollowing);
            db.SaveChanges();

            return(Ok());
        }
Exemple #5
0
            public async Task <Unit> Handle(Command request, CancellationToken cancellationToken)
            {
                var observer = await _context.Users.SingleOrDefaultAsync(x => x.UserName == _userAccessor.GetCurrentUsername());

                var target = await _context.Users.SingleOrDefaultAsync(x => x.UserName == request.Username);

                if (target == null)
                {
                    throw new RestException(HttpStatusCode.NotFound, new { User = "******" });
                }

                var following = await _context.Followings.SingleOrDefaultAsync(x => x.ObserverId == observer.Id && x.TargetId == target.Id);

                if (following != null)
                {
                    throw new RestException(HttpStatusCode.BadRequest, new { User = "******" });
                }

                if (following == null)
                {
                    following = new UsersFollowing
                    {
                        Observer = observer,
                        Target   = target
                    };

                    _context.Followings.Add(following);
                }

                var success = await _context.SaveChangesAsync() > 0;

                if (success)
                {
                    return(Unit.Value);
                }

                throw new Exception("Problem saving changes");
            }
Exemple #6
0
        public bool IsFollowing(int followerID, int followingID)
        {
            UsersFollowing obj = db.UsersFollowing.Where(x => x.FollowerID == followerID && x.FollowingID == followingID).SingleOrDefault();

            return(obj != null);
        }