Ejemplo n.º 1
0
        public bool Follow(FollowDTO followdto)
        {
            Follow follow1 = DBContext.Follow.Where(ds => ds.Followed_UserID == followdto.UserToFollowID).FirstOrDefault();

            if (follow1 != null && follow1.Follower_UserID == followdto.UserID)
            {
                return(false);
            }

            else
            {
                try
                {
                    Follow follow = new Follow();
                    follow.ID = System.Guid.NewGuid();
                    follow.Follower_UserID = followdto.UserID;
                    follow.Followed_UserID = followdto.UserToFollowID;
                    DBContext.Follow.Add(follow);
                    DBContext.SaveChanges();
                    return(true);
                }
                catch (Exception)
                {
                    return(false);
                }
            }
        }
Ejemplo n.º 2
0
 public void DeleteFollowing(FollowDTO follower)
 {
     if (objDb.DeleteFollowing(follower))
     {
         DecreaseFollower(follower.FollowerId, follower.FollowingId);
     }
 }
Ejemplo n.º 3
0
        public async Task <IActionResult> Follow(FollowDTO model)
        {
            if (!model.isExsist)//modelde veri yoksa
            {
                if (model.FollowerId == User.GetUserId())
                {
                    await _followService.Follow(model);

                    return(Json("Success"));
                }
                else
                {
                    return(Json("Faild"));
                }
            }
            else
            {
                if (model.FollowerId == User.GetUserId())
                {
                    await _followService.UnFollow(model);

                    return(Json("Success"));
                }
                else
                {
                    return(Json("Faild"));
                }
            }
        }
        public async Task <bool> IsFollowing(FollowDTO followDTO)
        {
            bool isFollowExsist = await _unitOfWork.FollowRepository.Any(x => x.FollowerId == followDTO.FollowerId &&
                                                                         x.FollowingId == followDTO.FollowingId);

            return(isFollowExsist);
        }
        public async Task UnFollow(FollowDTO followDTO)
        {
            var isFollowExsist = await _unitOfWork.FollowRepository.FirstOrDefault(x => x.FollowerId == followDTO.FollowerId && x.FollowingId == followDTO.FollowingId);

            _unitOfWork.FollowRepository.Delete(isFollowExsist);
            await _unitOfWork.Commit();
        }
Ejemplo n.º 6
0
 public void AddFollowing(FollowDTO follower)
 {
     if (objDb.AddFollowing(follower))
     {
         IncreaseFollowing(follower.FollowerId, follower.FollowingId);
     }
 }
Ejemplo n.º 7
0
        public async Task UnFollow(FollowDTO model)
        {
            var isExsistFollow = await _unitOfWork.Follow.FirstOrDefault(x => x.FollowerId == model.FollowerId && x.FollowingId == model.FollowingId);

            _unitOfWork.Follow.Delete(isExsistFollow);
            await _unitOfWork.Commit();
        }
Ejemplo n.º 8
0
        public bool UnFollow(FollowDTO followdto)
        {
            Follow unfollow = DBContext.Follow.Where(ds => ds.Followed_UserID == followdto.UserToFollowID).FirstOrDefault();

            DBContext.Follow.Remove(unfollow);
            DBContext.SaveChanges();
            return(true);
        }
        public bool Unfollow(FollowModel followModel)
        {
            FollowDTO followdto = new FollowDTO();

            followdto.UserID         = Guid.Parse(followModel.UserID);
            followdto.UserToFollowID = Guid.Parse(followModel.UserToFollowID);
            UserBusinessContext.UnFollow(followdto);
            return(true);
        }
Ejemplo n.º 10
0
 public IHttpActionResult Unfollow(FollowDTO followDTO)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest(ModelState));
     }
     followBs.DeleteFollowing(followDTO);
     return(Ok(followDTO));
 }
Ejemplo n.º 11
0
        public bool Post(FollowModel followModel)
        {
            FollowDTO followdto = new FollowDTO();

            followdto.UserID         = Guid.Parse(followModel.UserID);
            followdto.UserToFollowID = Guid.Parse(followModel.UserToFollowID);
            bool result = UserBusinessContext.Follow(followdto);

            return(result);
        }
Ejemplo n.º 12
0
        public async Task UnFollow(FollowDTO followDTO)
        {
            var isFollowExsist = await _unitOfWork.FollowRepository.FirstOrDefault(x => x.FollowingId == followDTO.FollowingId);

            if (isFollowExsist == null)
            {
                var follow = _mapper.Map <FollowDTO, Follow>(followDTO);
                _unitOfWork.FollowRepository.Delete(follow);
                await _unitOfWork.Commit();
            }
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Takibe almak için yapıyorum. öncelikle üzerine tıkladığım kişi ıd sinden kontrol edilip following lerimin arasındamı var mı yokmu eğer yoksa onu ekliyorum.
        /// </summary>
        /// <param name="Follow"></param>
        /// <returns> Geri dönüş tipi yok sadece folowerkaydediyor.</returns>
        public async Task Follow(FollowDTO followDTO)
        {
            var isFollowExist = await _unitOfwork.FollowRepository.FirstOrDefault(x => x.FollowerId == followDTO.FollowerId && x.FollowingId == followDTO.FollowingId);

            if (isFollowExist == null)
            {
                var follow = _mapper.Map <FollowDTO, Follow>(followDTO);
                await _unitOfwork.FollowRepository.Add(follow);

                await _unitOfwork.Commit();
            }
        }
Ejemplo n.º 14
0
        public async Task Follow(FollowDTO model)
        {
            var isExsistFollow = await _unitOfWork.Follow.FirstOrDefault(x => x.FollowerId == model.FollowerId && x.FollowingId == model.FollowingId);

            if (isExsistFollow == null)
            {
                var follow = _mapper.Map <FollowDTO, Follow>(model);
                await _unitOfWork.Follow.Add(follow);

                await _unitOfWork.Commit();
            }
        }
        public bool Post(FollowModel followModel)
        {
            //fetch user to follow's userid from url and fetch  loggedin user id from session
            // string ass  = HttpContext.Current.Session["UserID"].ToString();

            FollowDTO followdto = new FollowDTO();

            followdto.UserID         = Guid.Parse(followModel.UserID);
            followdto.UserToFollowID = Guid.Parse(followModel.UserToFollowID);
            bool result = UserBusinessContext.Follow(followdto);

            return(result);
        }
Ejemplo n.º 16
0
        public async Task <ActionResult <FollowDTO> > Add(FollowDTO follow)
        {
            var user = await userFinder.FindByClaimsPrincipal(User);

            follow.ObserverId = user.Id;
            var added = await followDTOManager.Add(follow);

            if (added == null)
            {
                return(NoContent());
            }
            return(Ok(added));
        }
Ejemplo n.º 17
0
 public HttpResponseMessage UnFollow(FollowDTO postData)
 {
     try
     {
         var follow = UserController.GetUserById(PortalSettings.PortalId, postData.FollowId);
         FollowersController.Instance.UnFollowUser(follow);
         return(Request.CreateResponse(HttpStatusCode.OK, new { Result = "success" }));
     }
     catch (Exception exc)
     {
         Logger.Error(exc);
         return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, exc));
     }
 }
Ejemplo n.º 18
0
        public async Task <FollowDTO> Add(FollowDTO newFollow)
        {
            if (string.IsNullOrEmpty(newFollow.AuthorId) || string.IsNullOrEmpty(newFollow.ObserverId))
            {
                return(null);
            }
            var follow = mapper.Map <Follow>(newFollow);
            var added  = await followManager.Add(follow);

            if (added == null)
            {
                return(null);
            }
            return(mapper.Map <FollowDTO>(added));
        }
Ejemplo n.º 19
0
        public async Task <IViewComponentResult> InvokeAsync(string userName)
        {
            int userId = await _userService.GetUserIdFromName(userName);

            var claimsIdentity = (ClaimsIdentity)User.Identity;
            var claim          = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier);
            int followerId     = Convert.ToInt32(claim.Value);

            var followModel = new FollowDTO {
                FollowerId = followerId, FollowingId = userId
            };

            followModel.isExsist = await _followService.IsFollowing(followModel);

            return(View(followModel));
        }
Ejemplo n.º 20
0
        public IHttpActionResult Delete(FollowDTO dto)
        {
            var userId    = User.Identity.GetUserId();
            var following = _context.Followings.SingleOrDefault(f => f.FolloweeId == dto.FolloweeId &&
                                                                f.FollowerId == userId);

            if (following == null)
            {
                return(BadRequest("Not follwoing"));
            }

            _context.Followings.Remove(following);
            _context.SaveChanges();

            return(Ok(200));
        }
Ejemplo n.º 21
0
        public Boolean DeleteFollowing(FollowDTO follower)
        {
            Boolean result = true;

            try
            {
                int userId = db.Users.Where(x => x.Email == follower.Email).Select(x => x.UserId).FirstOrDefault();
                follower.FollowerId = userId;
                var followObj = db.Follows.Where(x => x.FollowerId == follower.FollowerId && x.FollowingId == follower.FollowingId).FirstOrDefault();
                if (followObj == null)
                {
                }
                db.Follows.Remove(followObj);
                Save();
            }
            catch (Exception) {
                result = false;
            }
            return(result);
        }
Ejemplo n.º 22
0
        public Boolean AddFollowing(FollowDTO follower)
        {
            Boolean result;

            try
            {
                int userId = db.Users.Where(x => x.Email == follower.Email)
                             .Select(x => x.UserId).FirstOrDefault();
                follower.FollowerId = userId;
                Follow follow = new Follow();
                follow.FollowerId  = userId;
                follow.FollowingId = follower.FollowingId;
                db.Follows.Add(follow);
                Save();
                result = true;
            }
            catch (Exception) {
                result = false;
            }
            return(result);
        }
Ejemplo n.º 23
0
        public IHttpActionResult Follow(FollowDTO dto)
        {
            var userId           = User.Identity.GetUserId();
            var alreadyFollowing = _context.Followings.Any(f => f.FolloweeId == dto.FolloweeId &&
                                                           f.FollowerId == userId);

            if (alreadyFollowing)
            {
                return(BadRequest("Already following"));
            }

            var following = new Following
            {
                FolloweeId = dto.FolloweeId,
                FollowerId = userId
            };

            _context.Followings.Add(following);
            _context.SaveChanges();

            return(Ok(200));
        }
Ejemplo n.º 24
0
        public async Task <ActionResult> FollowUser([FromBody] FollowDTO request, string username, int latest = 0)
        {
            _memoryCache.Set(CacheFields.Latest, latest);
            var response = HttpStatusCode.InternalServerError;

            if (request.follow != null)
            {
                response = await _userRepository.FollowUser(username, request.follow);

                //TotalFollowers.Inc();
            }
            else if (request.unfollow != null)
            {
                response = await _userRepository.UnfollowUser(username, request.unfollow);

                //TotalFollowers.Inc(-1);
            }

            //AverageFollows.IncTo(_userRepository.AverageFollowsByUser());

            return(new StatusCodeResult((int)response));
        }
 public HttpResponseMessage UnFollow(FollowDTO postData)
 {
     try
     {
         var follow = UserController.GetUserById(PortalSettings.PortalId, postData.FollowId);
         FollowersController.Instance.UnFollowUser(follow);
         return Request.CreateResponse(HttpStatusCode.OK, new {Result = "success"});
     }
     catch (Exception exc)
     {
         Logger.Error(exc);
         return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, exc);
     }
 }
Ejemplo n.º 26
0
        public async Task <bool> isFollowing(FollowDTO model)
        {
            var isExistFollow = await _unitOfWork.Follow.Any(x => x.FollowerId == model.FollowerId && x.FollowingId == model.FollowingId);

            return(isExistFollow);
        }
Ejemplo n.º 27
0
        public bool Follow(FollowDTO followdto)
        {
            bool result = UserDBContext.Follow(followdto);

            return(result);
        }
 public void UnFollowUser([FromBody] FollowDTO followDTO)
 {
     //int userId = 1;
     this._followBDC.UnFollowUser(followDTO.UserId, followDTO.FollowingId);
     //return false;
 }
Ejemplo n.º 29
0
 public bool UnFollow(FollowDTO followdto)
 {
     UserDBContext.UnFollow(followdto);
     return(true);
 }
Ejemplo n.º 30
0
        public async Task <IHttpActionResult> PostFollow(Follow follow)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var existingFollow = await db.Follows.Where(f => f.FollowerId == follow.FollowerId && f.FollowingId == follow.FollowingId).FirstOrDefaultAsync();

            var followingUser = await db.Users.Where(u => u.Id == follow.FollowingId).FirstOrDefaultAsync();

            var followerUser = await db.Users.Where(u => u.Id == follow.FollowerId).FirstOrDefaultAsync();

            var followDto = new FollowDTO();

            if (existingFollow == null)
            {
                follow.CreatedAt = DateTime.Now;
                follow.IsDeleted = false;
                db.Follows.Add(follow);

                followDto.FollowerId  = follow.FollowerId;
                followDto.FollowingId = follow.FollowingId;

                Notification followingNotification = new Notification();
                followingNotification.Type      = "positive";
                followingNotification.Action    = "Gained a follower";
                followingNotification.Source    = $"a user named {followerUser.Name} following you";
                followingNotification.UserId    = followingUser.Id;
                followingNotification.CreatedAt = DateTime.Now;
                db.Notifications.Add(followingNotification);

                Notification followerNotification = new Notification();
                followerNotification.Type      = "positive";
                followerNotification.Action    = $"Followed {followingUser.Name}";
                followerNotification.Source    = "following them";
                followerNotification.UserId    = followerUser.Id;
                followerNotification.CreatedAt = DateTime.Now;
                db.Notifications.Add(followerNotification);
            }
            else
            {
                db.Follows.Remove(existingFollow);

                Notification followingNotification = new Notification();
                followingNotification.Type      = "negative";
                followingNotification.Action    = "Lost a follower";
                followingNotification.Source    = $"a user named {followerUser.Name} unfollowing you";
                followingNotification.UserId    = followingUser.Id;
                followingNotification.CreatedAt = DateTime.Now;
                db.Notifications.Add(followingNotification);

                Notification followerNotification = new Notification();
                followerNotification.Type      = "negative";
                followerNotification.Action    = $"Unfollowed {followingUser.Name}";
                followerNotification.Source    = "unfollowing them";
                followerNotification.UserId    = followerUser.Id;
                followerNotification.CreatedAt = DateTime.Now;
                db.Notifications.Add(followerNotification);
            }

            await db.SaveChangesAsync();

            return(Ok(followDto));
        }
 public void FollowUser([FromBody] FollowDTO followDTO)
 {
     this._followBDC.FollowUser(followDTO.UserId, followDTO.FollowingId);
 }