Esempio n. 1
0
        public virtual void DeleteFriend(long userId, long fid, String ip)
        {
            FollowerService followService = new FollowerService();

            String     condition = "User.Id=" + userId + " and Friend.Id=" + fid + " and Status=" + FriendStatus.Approved;
            FriendShip ship      = db.find <FriendShip>(condition).first();

            if (ship != null)
            {
                db.delete(ship);
                if (followService.IsFollowing(userId, fid) == false)
                {
                    followService.Follow(userId, fid, ip);
                }
                recountFriends(userId);
                recountFriends(fid);

                return;
            }

            condition = "User.Id=" + fid + " and Friend.Id=" + userId + " and Status=" + FriendStatus.Approved;
            ship      = db.find <FriendShip>(condition).first();
            if (ship != null)
            {
                db.delete(ship);
                if (followService.IsFollowing(fid, userId) == false)
                {
                    followService.Follow(fid, userId, ip);
                }
                recountFriends(userId);
                recountFriends(fid);
            }
        }
        public async Task <IActionResult> DeleteFriend(string friendId)
        {
            var user = await _context.Users.Include(z => z.FriendsOne).Include(z => z.FriendsTwo).FirstOrDefaultAsync(f => f.Id == GetUserId().Result);

            FriendShip friendship = null;

            foreach (FriendShip fs in user.Friends)
            {
                if (fs.FriendTwoId == friendId || fs.FriendOneId == friendId)
                {
                    friendship = fs;
                    break;
                }
            }

            if (friendship == null)
            {
                return(BadRequest("Can't unfriended someone who isn't a friend"));
            }

            if (!friendship.IsFriends)
            {
                return(BadRequest("Buhu, this friend has already been unfriended"));
            }

            friendship.IsFriends = false;

            await _context.SaveChangesAsync();

            return(Ok());
        }
Esempio n. 3
0
        public virtual void Approve(long userId, long friendId)
        {
            // friendId 是邀请方

            String     condition = "User.Id=" + friendId + " and Friend.Id=" + userId;
            FriendShip ship      = db.find <FriendShip>(condition).first();

            if (ship == null)
            {
                throw new Exception("user(id:" + friendId + ") have not request you friend(id:" + userId + ")");
            }
            ship.Status = FriendStatus.Approved;
            db.update(ship, "Status");

            recountFriends(userId);
            recountFriends(friendId);

            new FollowerService().DeleteFollow(userId, friendId);
            new FollowerService().DeleteFollow(friendId, userId);

            addFeedInfo(ship, ship.Ip);

            User user = userService.GetById(userId);

            addNotificationWhenApproved(user, friendId);
        }
Esempio n. 4
0
        public HttpResponseMessage RemoveFriend(FriendShip friendEmail)
        {
            if (friendEmail.Friend == "" || friendEmail.User == "")
            {
                return(new HttpResponseMessage(HttpStatusCode.PaymentRequired));
            }
            SQLBlock block = new SQLBlock();

            using (SqlConnection connection = new SqlConnection(block.connectionString))
                using (SqlCommand command = new SqlCommand($"DELETE FROM [dbo].[friends] WHERE email ='{friendEmail.User}' AND friendEmail = '{friendEmail.Friend}';", connection))
                {
                    try
                    {
                        connection.Open();
                        command.BeginExecuteNonQuery();
                    }
                    catch (Exception e)
                    {
                        Console.Write(e.Message);
                        connection.Close();
                        return(new HttpResponseMessage(HttpStatusCode.Conflict));
                    }
                    connection.Close();
                }
            return(new HttpResponseMessage(HttpStatusCode.OK));
        }
Esempio n. 5
0
        public void Update(FriendShip friendShip)
        {
            try
            {
                const int ACTION = 2;

                _sqlConn.Open();

                var sqlCommUpdate = new SqlCommand("uspManagerNonQueryFriendShip", _sqlConn)
                {
                    CommandType = System.Data.CommandType.StoredProcedure
                };
                sqlCommUpdate.Parameters.AddWithValue("Action", ACTION.ToString());
                sqlCommUpdate.Parameters.AddWithValue("Id", friendShip.Id);
                sqlCommUpdate.Parameters.AddWithValue("RequestedById", friendShip.RequestedById);
                sqlCommUpdate.Parameters.AddWithValue("RequestedToId", friendShip.RequestedToId);
                sqlCommUpdate.Parameters.AddWithValue("RequestTime", friendShip.RequestTime);
                sqlCommUpdate.Parameters.AddWithValue("Status", friendShip.Status);
                //sqlCommUpdate.Parameters.AddWithValue("Profile_Id", friendShip.RequestedBy);
                //sqlCommUpdate.Parameters.AddWithValue("Profile_Id1", friendShip.RequestedTo);

                sqlCommUpdate.ExecuteNonQuery();

                _sqlConn.Close();
            }
            catch (Exception ex)
            {
                var result = ex.Message;
            }
        }
Esempio n. 6
0
        public virtual Result AddFriend( int userId, int friendId, String msg )
        {
            Result result = CanAddFriend( userId, friendId );
            if (result.HasErrors) return result;

            FriendShip fs = new FriendShip();

            User user = userService.GetById( userId );
            User friend = userService.GetById( friendId );

            fs.User = user;
            fs.Friend = friend;
            fs.Msg = msg;

            fs.Status = FriendStatus.Waiting;

            result = db.insert( fs );
            if (result.IsValid) {
                string userLink = Link.ToMember( user );
                String note = string.Format( "<a href=\"{0}\" target=\"_blank\" class=\"requestUser\">{1}</a> " + lang.get( "requestFriend" ), userLink, user.Name );
                if (strUtil.HasText( msg )) {
                    note += "<br/><span class=\"quote\">" + msg + "</span>";
                }
                notificationService.sendFriendRequest( userId, friendId, note );

                // 顺带添加关注
                FollowerService followService = new FollowerService();
                if (followService.IsFollowing( userId, friendId ) == false)
                    followService.Follow( userId, friendId );
            }
            return result;
        }
Esempio n. 7
0
        public HttpResponseMessage POST(FriendShip friendEmail)
        {
            if (friendEmail.Friend == "" || friendEmail.User == "")
            {
                return(new HttpResponseMessage(HttpStatusCode.PaymentRequired));
            }
            SQLBlock block = new SQLBlock();

            using (SqlConnection connection = new SqlConnection(block.connectionString))
                using (SqlCommand command = new SqlCommand($"INSERT INTO [dbo].[friends] (email, friendEmail) VALUES ('{friendEmail.User}', '{friendEmail.Friend}');", connection))
                {
                    try
                    {
                        connection.Open();
                        command.BeginExecuteNonQuery();
                    }
                    catch (Exception e)
                    {
                        Console.Write(e.Message);
                        connection.Close();
                        return(new HttpResponseMessage(HttpStatusCode.Conflict));
                    }
                    connection.Close();
                }
            return(new HttpResponseMessage(HttpStatusCode.OK));
        }
Esempio n. 8
0
        /// <summary>
        /// 读取所有
        /// </summary>
        /// <returns></returns>
        public List <FriendShip> GetLinksList(Pages pg)
        {
            List <FriendShip> list = new List <FriendShip>();
            string            sql  = "proc_FriendShipList_fenye";

            SqlParameter[] para =
            {
                new SqlParameter("@pageIndex", pg.PageIndex),
                new SqlParameter("@pageSize",  pg.PagesSize),
                new SqlParameter("@ListName",  pg.types),
                new SqlParameter("@require",   pg.Tiaojian)
            };
            DataSet ds = DbHelper.GetDataSetByProc(sql, para);

            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                FriendShip fri = new FriendShip();
                fri.Fword   = dr["Fword"].ToString();
                fri.FUrl    = dr["FUrl"].ToString();
                fri.ID      = Convert.ToInt32(dr["ID"]);
                fri.AddTime = Convert.ToDateTime(dr["AddTime"]);
                list.Add(fri);
            }
            return(list);
        }
Esempio n. 9
0
        public void UnFollow(int id)
        {
            FriendShip unf = _db.FriendShips.Where(k => k.ID == id).FirstOrDefault();

            _db.FriendShips.Remove(unf);
            _db.SaveChanges();
        }
        public async Task <IActionResult> AcceptFriend(string requestId)
        {
            var  userId = HttpContext.User.Claims.FirstOrDefault(x => x.Type == "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier").Value;
            User me     = await _context.Users
                          .Include(t => t.FriendsTwo)
                          .Include(t => t.FriendsOne)
                          .Include(r => r.OthersRequests)
                          .ThenInclude(g => g.Sender)
                          .FirstOrDefaultAsync(z => z.Id == userId);

            FriendRequest request = me.OthersRequests.FirstOrDefault(l => l.Id == requestId);

            if (request == null)
            {
                return(BadRequest("No such request"));
            }
            if (!request.IsActive)
            {
                return(BadRequest("Not active request"));
            }

            User friend = request.Sender;

            if (friend == null)
            {
                return(BadRequest("No such user"));
            }

            foreach (FriendShip f in me.Friends)
            {
                if (f.FriendTwoId == friend.Id || f.FriendOneId == friend.Id)
                {
                    f.IsFriends      = true;
                    request.IsActive = false;
                    f.FriendsSince   = DateTime.Now;
                    await _context.SaveChangesAsync();

                    return(Ok());
                }
            }

            FriendShip fs = new FriendShip()
            {
                FriendOne    = friend,
                FriendOneId  = friend.Id,
                FriendTwo    = me,
                FriendTwoId  = me.Id,
                IsFriends    = true,
                FriendsSince = DateTime.Now
            };

            friend.FriendsOne.Add(fs);
            me.FriendsTwo.Add(fs);
            request.IsActive = false;
            await _context.SaveChangesAsync();


            return(Ok());
        }
Esempio n. 11
0
    private void OnEnable()
    {
        friendShip = (FriendShip)target;

        friendlyProperty            = serializedObject.FindProperty(friendlyPropertyName);
        friendShipConditionProperty = serializedObject.FindProperty(friendShipConditionPropertyName);

        CheckAndCreateSubEditors(friendShip.friendShipCondition);
    }
Esempio n. 12
0
        public FriendShip MakeFriendship(string userId, string friendId)
        {
            FriendShip fs = new FriendShip()
            {
                Id          = userId + ":" + friendId,
                IsFriends   = true,
                FriendsFrom = DateTime.Now
            };

            return(fs);
        }
Esempio n. 13
0
        public virtual void Refuse(long userId, long friendId)
        {
            String     condition = "User.Id=" + friendId + " and Friend.Id=" + userId;
            FriendShip ship      = db.find <FriendShip>(condition).first() as FriendShip;

            if (ship == null)
            {
                throw new Exception("user(id:" + friendId + ") have not request you friend(id:" + userId + ")");
            }
            db.delete(ship);
        }
Esempio n. 14
0
        /// <summary>
        /// 加载信息
        /// </summary>
        private void LoadInfo(int d)
        {
            FriendShip fir = firMang.GetLinks(d);

            if (fir != null)
            {
                ViewState["isNUlls"] = sendId;
                this.txLinkName.Text = fir.Fword;
                this.txUrl.Text      = fir.FUrl;
                this.txAddTime.Text  = fir.AddTime.ToString("yyyy-MM-dd");
            }
        }
Esempio n. 15
0
        public ActionResult UnFollow(int id)
        {
            var friend = _db.FriendShips.FirstOrDefault(k => k.FriendID == id);

            if (friend != null)
            {
                FriendShip model = _db.FriendShips.Where(k => k.FriendID == id).FirstOrDefault();
                _db.FriendShips.Remove(model);
                _db.SaveChanges();
            }
            return(RedirectToAction("Home", "Home"));
        }
Esempio n. 16
0
        private Boolean cancelFriendSingle(long userId, long fid, String condition)
        {
            FriendShip ship = db.find <FriendShip>(condition).first();

            if (ship == null)
            {
                return(false);
            }
            db.delete(ship);

            notificationService.cancelFriendRequest(userId, fid);
            return(true);
        }
Esempio n. 17
0
        public bool CheckIfFriends(string userId, string receiverId)
        {
            FriendShip friend = _context.Friends.Where(z => z.Id.Contains(userId) && z.Id.Contains(receiverId)).FirstOrDefault();

            if (friend != null)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Esempio n. 18
0
        public void CreateFriendship(Guid requestedById, Guid requestedToId)
        {
            var friendShip = new FriendShip
            {
                Id = Guid.NewGuid(),

                RequestedById = requestedById,
                RequestedToId = requestedToId,
                RequestTime   = DateTime.Now,
                Status        = StatusEnum.Pendent
            };

            _friendShipRepository.Save(friendShip);
        }
Esempio n. 19
0
        public override int Delete <T>(T obj)
        {
            if (typeof(T) != typeof(FriendShip))
            {
                throw new Exception("invalid FriendShip type");
            }
            FriendShip friendShip = obj as FriendShip;
            string     sql        = string.Format("Delete from {0} where (UserName1=@UserName1 and UserName2=@UserName2) or(UserName2=@UserName1 and @UserName1=@UserName2)", tableName);

            using (var conn = ConnectionFactory.GetConnection())
            {
                return(conn.Execute(sql, obj));
            }
        }
Esempio n. 20
0
        public virtual void AddInviteFriend(User newRegUser, int friendId)
        {
            FriendShip ship = new FriendShip();

            ship.User   = newRegUser;
            ship.Friend = userService.GetById(friendId);
            ship.Status = FriendStatus.Approved;

            ship.insert();

            recountFriends(newRegUser.Id);
            recountFriends(friendId);

            addNotificationWhenApproved(newRegUser, friendId);
        }
Esempio n. 21
0
        /// <summary>
        /// 添加
        /// </summary>
        /// <returns></returns>
        public bool AddFriendShip(FriendShip fir)
        {
            string sql = "proc_Add_FriendShip";

            SqlParameter[] para =
            {
                new SqlParameter("@word", fir.Fword),
                new SqlParameter("@url",  fir.FUrl),
            };
            if (DbHelper.ExecuteCommandByProc(sql, para) > 0)
            {
                return(true);
            }
            return(false);
        }
Esempio n. 22
0
        /// <summary>
        /// 获取所有链接
        /// </summary>
        /// <param name="txts"></param>
        /// <returns></returns>
        public List <FriendShip> GetLinkList_all()
        {
            List <FriendShip> list = new List <FriendShip>();
            string            sql  = "select ID,Fword,FUrl from FriendShip";
            DataSet           ds   = DbHelper.GetDataSetBySql(sql);

            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                FriendShip fri = new FriendShip();
                fri.Fword = dr["Fword"].ToString();
                fri.FUrl  = "http://" + dr["FUrl"].ToString();
                fri.ID    = Convert.ToInt32(dr["ID"]);
                list.Add(fri);
            }
            return(list);
        }
Esempio n. 23
0
        /// <summary>
        /// 读取一条
        /// </summary>
        /// <returns></returns>
        public FriendShip GetLinks(int d)
        {
            FriendShip fir = new FriendShip();
            string     sql = "proc_get_FriendShip";

            SqlParameter[] para =
            {
                new SqlParameter("@id", d)
            };
            DataSet ds = DbHelper.GetDataSetByProc(sql, para);
            DataRow dr = ds.Tables[0].Rows[0];

            fir.Fword   = dr["Fword"].ToString();
            fir.FUrl    = dr["FUrl"].ToString();
            fir.AddTime = Convert.ToDateTime(dr["AddTime"]);
            return(fir);
        }
Esempio n. 24
0
        public ActionResult Follow()
        {
            FriendShip friend   = new FriendShip();
            var        FriendId = RouteData.Values["id"];
            var        user     = SessionSet <User> .Get("Login");

            friend.UserID   = user.ID;
            friend.FriendID = Convert.ToInt32(FriendId);

            var result = _br.Query <FriendShip>().Where(k => (k.UserID.Equals(friend.UserID)) && (k.FriendID.Equals(friend.FriendID))).FirstOrDefault();

            if (result == null)
            {
                _db.FriendShips.Add(friend);
                _db.SaveChanges();
            }
            return(RedirectToAction("Home", "Home"));
        }
Esempio n. 25
0
 public void Answer(string friendName, int reqId, bool answer)
 {
     if (answer)
     {
         FriendShip friendShip = new FriendShip
         {
             User   = Context.User.Identity.Name,
             Friend = friendName
         };
         unitOfWork.FriendsRepo.Insert(friendShip);
         unitOfWork.Save();
     }
     else
     {
         var delreq = unitOfWork.RequestsRepo.GetById(reqId);
         unitOfWork.RequestsRepo.Delete(delreq);
         unitOfWork.Save();
     }
 }
Esempio n. 26
0
        public virtual Result AddFriend(long userId, long friendId, String msg, String ip)
        {
            Result result = CanAddFriend(userId, friendId);

            if (result.HasErrors)
            {
                return(result);
            }

            FriendShip fs = new FriendShip();

            User user   = userService.GetById(userId);
            User friend = userService.GetById(friendId);

            fs.User   = user;
            fs.Friend = friend;
            fs.Msg    = msg;

            fs.Status = FriendStatus.Waiting;
            fs.Ip     = ip;

            result = db.insert(fs);
            if (result.IsValid)
            {
                string userLink = Link.ToMember(user);
                String note     = string.Format("<a href=\"{0}\" target=\"_blank\" class=\"requestUser\">{1}</a> " + lang.get("requestFriend"), userLink, user.Name);
                if (strUtil.HasText(msg))
                {
                    note += "<br/><span class=\"quote\">" + msg + "</span>";
                }
                notificationService.sendFriendRequest(userId, friendId, note);

                // 顺带添加关注
                FollowerService followService = new FollowerService();
                if (followService.IsFollowing(userId, friendId) == false)
                {
                    followService.Follow(userId, friendId, ip);
                }
            }
            return(result);
        }
        public async Task <IActionResult> PostFriendShip([FromBody] AppUser friend)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }


            var userId = (await _userManager.GetUserAsync(User)).Id;
            var user   = await _context.Users.AsNoTracking().SingleOrDefaultAsync(m => m.ApplicationUserID == userId);

            if (user == null)
            {
                return(BadRequest());
            }

            var thisfriend = await _context.Users.SingleOrDefaultAsync(m => m.UserName == friend.UserName);

            if (thisfriend == null)
            {
                return(BadRequest());
            }

            var thisFriendShip = await _context.FriendShips.SingleOrDefaultAsync(m => m.UserID == user.ID && m.FriendID == thisfriend.ID);

            if (thisFriendShip == null)
            {
                var newFriendShip = new FriendShip {
                    UserID = user.ID, FriendID = thisfriend.ID
                };
                await _context.FriendShips.AddAsync(newFriendShip);

                await _context.SaveChangesAsync();

                return(Ok());
            }
            else
            {
                return(Ok(null));
            }
        }
Esempio n. 28
0
        public IEnumerable <FriendShip> GetFriendsOf(Guid id)
        {
            try
            {
                const int ACTION = 1;

                _sqlConn.Open();

                var sqlCommandGetFriendsOf = new SqlCommand("uspManagerQueryFriendShip", _sqlConn)
                {
                    CommandType = System.Data.CommandType.StoredProcedure
                };
                sqlCommandGetFriendsOf.Parameters.AddWithValue("Action", ACTION.ToString());
                sqlCommandGetFriendsOf.Parameters.AddWithValue("Id", id.ToString());
                var reader = sqlCommandGetFriendsOf.ExecuteReader();

                while (reader.Read())
                {
                    var _friendShip = new FriendShip
                    {
                        Id            = Guid.Parse(reader["Id"].ToString()),
                        RequestedById = Guid.Parse(reader["RequestedById"].ToString()),
                        RequestedToId = Guid.Parse(reader["RequestedToId"].ToString()),
                        RequestTime   = DateTime.Parse(reader["RequestTime"].ToString()),
                        Status        = (StatusEnum)int.Parse(reader["Status"].ToString())
                                        //RequestedBy = (Profile)reader["RequestedBy"],
                                        //RequestedTo = (Profile)reader["RequestedTo"]
                    };

                    _friendShips.Add(_friendShip);
                }
                _sqlConn.Close();

                return(_friendShips);
            }
            catch (Exception ex)
            {
                var result = ex.Message;
            }
            return(new List <FriendShip>());
        }
Esempio n. 29
0
        public FriendShip GetById(Guid id)
        {
            try
            {
                const int ACTION = 2;

                _sqlConn.Open();

                var sqlCommandGetById = new SqlCommand("uspManagerQueryFriendShip", _sqlConn)
                {
                    CommandType = System.Data.CommandType.StoredProcedure
                };
                sqlCommandGetById.Parameters.AddWithValue("Action", ACTION.ToString());
                sqlCommandGetById.Parameters.AddWithValue("Id", id.ToString());
                var reader = sqlCommandGetById.ExecuteReader();

                var _friendShip = new FriendShip();

                while (reader.Read())
                {
                    _friendShip.Id            = Guid.Parse(reader["Id"].ToString());
                    _friendShip.RequestedById = Guid.Parse(reader["RequestedById"].ToString());
                    _friendShip.RequestedToId = Guid.Parse(reader["RequestedToId"].ToString());
                    _friendShip.RequestTime   = DateTime.Parse(reader["RequestTime"].ToString());
                    _friendShip.Status        = (StatusEnum)int.Parse(reader["Status"].ToString());
                    //_friendShip.RequestedBy = (Profile)reader["RequestedBy"];
                    //_friendShip.RequestedTo = (Profile)reader["RequestedTo"];
                }

                _sqlConn.Close();

                return(_friendShip);
            }
            catch (Exception ex)
            {
                var result = ex.Message;
            }
            return(null);
        }
Esempio n. 30
0
        public void RemoveFriendship(Guid requestedById, Guid requestedToId)
        {
            var friendships = _friendShipRepository.GetAll();

            var friendshipToBeRemoved = new FriendShip();

            foreach (var friendship in friendships)
            {
                if (
                    (friendship.RequestedById == requestedById &&
                     friendship.RequestedToId == requestedToId)
                    ||
                    (friendship.RequestedById == requestedById &&
                     friendship.RequestedToId == requestedById)
                    )
                {
                    friendshipToBeRemoved = friendship;
                    _friendShipRepository.Delete(friendshipToBeRemoved.Id);
                    return;
                }
            }
        }
Esempio n. 31
0
        public IActionResult CreateFriendShip(int id, int friendId)
        {
            if (id == friendId)
            {
                return(BadRequest("UserIds cannot be the Same"));
            }

            var self = db.Users.Find(id);

            if (self == null)
            {
                return(NotFound($"User with Id {id} Not Found"));
            }

            var friend = db.Users.Find(friendId);

            if (friend == null)
            {
                return(NotFound($"User with Id {friendId} Not Found"));
            }

            if (new UserManager(db).hasFriendshipBetween(id, friendId))
            {
                return(StatusCode(409, $"User {id} and User {friendId} are friends already"));
            }

            var friendship = new FriendShip()
            {
                Self   = self,
                Friend = friend,
            };

            db.FriendShips.Add(friendship);

            db.SaveChanges();

            return(CreatedAtRoute("GetFriendships", new { id = id }, $"User {id} and User {friendId} now are friends"));
        }
Esempio n. 32
0
        public virtual void AddInviteFriend( User newRegUser, int friendId )
        {
            FriendShip ship = new FriendShip();
            ship.User = newRegUser;
            ship.Friend = userService.GetById( friendId );
            ship.Status = FriendStatus.Approved;

            ship.insert();

            recountFriends( newRegUser.Id );
            recountFriends( friendId );

            addFeedInfo( ship );

            addNotificationWhenApproved( newRegUser, friendId );
        }
Esempio n. 33
0
 private void addFeedInfo( FriendShip ship )
 {
     addFrinedFeedInfo( ship.User, ship.Friend );
     addFrinedFeedInfo( ship.Friend, ship.User );
 }
Esempio n. 34
0
 private void addFeedInfo( FriendShip ship, String ip )
 {
     addFrinedFeedInfo( ship.User, ship.Friend, ip );
     addFrinedFeedInfo( ship.Friend, ship.User, ip );
 }