Esempio n. 1
0
        public static Mutual ToggleMutual(int user1Id, int user2Id)
        {
            Mutual newMutual = null;

            using (var db = new MyCirclesEntityModel())
            {
                Mutual existingMutual = db.Mutuals.Where(em =>
                                                         (em.User1Id == user1Id && em.User2Id == user2Id) ||
                                                         (em.User1Id == user2Id && em.User2Id == user1Id))
                                        .FirstOrDefault();

                if (existingMutual == null)
                {
                    newMutual         = new Mutual();
                    newMutual.User1Id = user1Id;
                    newMutual.User2Id = user2Id;
                    db.Mutuals.Add(newMutual);
                }
                else
                {
                    db.Mutuals.Remove(existingMutual);
                }

                db.SaveChanges();
            }

            return(newMutual);
        }
Esempio n. 2
0
        public static void Create(MutualBE pMutualBE)
        {
            using (Health.Back.BE.HealthEntities dc = new Health.Back.BE.HealthEntities(Common.CnnString_Entities))
            {
                Mutual wMutual = new Mutual();
                wMutual.Nombre        = pMutualBE.Nombre;
                wMutual.ExigeCoseguro = pMutualBE.ExigeCoseguro;

                dc.Mutuals.AddObject(wMutual);
                dc.SaveChanges();
                wMutual.IdMutual = wMutual.IdMutual;
            }
        }
Esempio n. 3
0
        public static Mutual SearchMutual(int user1Id, int user2Id)
        {
            Mutual newMutual = null;

            using (var db = new MyCirclesEntityModel())
            {
                Mutual existingMutual = db.Mutuals.Where(em =>
                                                         (em.User1Id == user1Id && em.User2Id == user2Id) ||
                                                         (em.User1Id == user2Id && em.User2Id == user1Id))
                                        .FirstOrDefault();
            }

            return(newMutual);
        }
Esempio n. 4
0
        public static Follow ToggleFollow(int followerId, int followingId)
        {
            Follow newFollow = null;
            Mutual newMutual = null;

            using (var db = new MyCirclesEntityModel())
            {
                Follow existingFollow = db.Follows.Where(ef => ef.FollowerId == followerId && ef.FollowingId == followingId).FirstOrDefault();

                if (existingFollow == null)
                {
                    newFollow             = new Follow();
                    newFollow.FollowerId  = followerId;
                    newFollow.FollowingId = followingId;
                    newFollow.CreatedAt   = DateTime.Now;
                    newFollow.IsDeleted   = false;
                    db.Follows.Add(newFollow);

                    Follow existingReverseFollow = db.Follows.Where(ef => ef.FollowerId == followingId && ef.FollowingId == followerId).FirstOrDefault();

                    if (existingReverseFollow != null)
                    {
                        newMutual = MutualDAO.ToggleMutual(followerId, followingId);
                    }
                }
                else
                {
                    db.Follows.Remove(existingFollow);
                    MutualDAO.ToggleMutual(followerId, followingId);
                }

                db.SaveChanges();
            }

            return(newFollow);
        }
Esempio n. 5
0
        private void explore_Click(object sender, EventArgs e)
        {
            Mutual graphMutual = new Mutual(8);

            foreach (Pair P in edges)
            {
                graphMutual.graph.addEdge(P.vertex1, P.vertex2);
            }

            Social socialNetwork = new Social(nodes.Count);

            foreach (Pair P in edges)
            {
                socialNetwork.network.addEdge(P.vertex1, P.vertex2);
            }

            if (DFS.Checked)
            {
                List <string> stack = new List <string>();
                bool          found = false;

                socialNetwork.exploreFriends(ref stack, this.vertex1, this.vertex2, ref found);
                if (found)
                {
                    ClearEdgeColor();
                    for (int i = 0; i < stack.Count - 1; i++)
                    {
                        string v1 = stack[i];
                        string v2 = stack[i + 1];
                        colorEdge(v1, v2);
                    }

                    gViewer1.Graph = graphLayout;
                    string answers = "";
                    answers += "Nama Akun: " + this.vertex1 + " " + this.vertex2 + "\n";
                    answers += (stack.Count - 2) + "-degree connection\n";
                    for (int i = 0; i < stack.Count; i++)
                    {
                        answers += stack[i];
                        if (i != stack.Count - 1)
                        {
                            answers += "-->";
                        }
                    }
                    MessageBox.Show(answers);
                }
                else
                {
                    MessageBox.Show("Nama akun: " + this.vertex1 + " " + this.vertex2 + "\n" + "Tidak ada jalur koneksi yang tersedia\nAnda harus memulai koneksi baru itu sendiri.");
                }
            }
            else if (BFS.Checked)
            {
                List <string> path  = new List <string>();
                bool          found = false;
                MessageBox.Show(socialNetwork.pathBFS(ref path, this.vertex1, this.vertex2, ref found));
                if (found)
                {
                    ClearEdgeColor();
                    for (int i = 0; i < path.Count - 1; i++)
                    {
                        string v1 = path[i];
                        string v2 = path[i + 1];
                        colorEdge(v1, v2);
                    }

                    gViewer1.Graph = graphLayout;
                }
                else
                {
                }
            }

            displayFriendRec.Text = graphMutual.mutualSearch(this.vertex1);
        }