Esempio n. 1
0
        public ActionResult AddFriend(int id)
        {
            var user = SessionSet <User> .Get("Login");

            RelationShip rs = new RelationShip()
            {
                User1ID      = user.ID,
                User2ID      = id,
                CreatedDate  = DateTime.Now,
                ActionUserID = user.ID,
                StatusID     = 1
            };

            _br.AddModel(rs);
            Notification notify = new Notification()
            {
                UserID      = user.ID,
                ActionID    = 1,
                PostUserID  = id,
                IsShow      = true,
                NotifyText  = user.Name + " wants to add you as a friend.",
                CreatedDate = DateTime.Now
            };

            _db.Notifications.Add(notify);
            _db.SaveChanges();

            return(RedirectToAction("Home", "Home"));
        }
Esempio n. 2
0
        public ActionResult PostDel(int id)
        {
            var resultCom = _br.Query <Comment>().Where(k => k.PostID == id).Any();

            if (resultCom)
            {
                var comList = _br.Query <Comment>().Where(k => k.PostID == id).ToList();
                foreach (var item in comList)
                {
                    _db.Entry(item).State = EntityState.Deleted;
                    _db.SaveChanges();
                }
            }

            var resultLike = _brLike.Query <Like>().Where(k => k.PostID == id).Any();

            if (resultLike)
            {
                var likeList = _brLike.Query <Like>().Where(k => k.PostID == id).ToList();
                foreach (var item in likeList)
                {
                    _db.Entry(item).State = EntityState.Deleted;
                    _db.SaveChanges();
                }
            }


            var delPost = _db.Posts.Where(k => k.ID == id).FirstOrDefault();

            _db.Entry(delPost).State = EntityState.Deleted;
            _db.SaveChanges();
            return(RedirectToAction("Home", "Home"));
        }
Esempio n. 3
0
        public virtual bool Add(T entity)
        {
            entity.CreateDate = DateTime.Now;
            Entity.Add(entity);

            return(context.SaveChanges() > 0);
        }
Esempio n. 4
0
        //profil resmi yüklerken
        public void LoadImage(string email, string path)
        {
            User user = context.Users.Where(x => x.Email == email).FirstOrDefault();

            user.ProfilePhoto = path;
            context.Users.Update(user);
            context.SaveChanges();
        }
Esempio n. 5
0
        public object ConnectUser(string userName)
        {
            try
            {
                using (var db = new FacebookDbContext())
                {
                    // Check if there if a connection for the specified user name have ever been made
                    var existingConnection = db.Connections.Where(x => x.UserName.ToLower() == userName.ToLower()).SingleOrDefault();

                    if (existingConnection != null)
                    {
                        // If there's an old connection only the connection id and the online status are changed.
                        existingConnection.ConnectionId = Context.ConnectionId;
                        existingConnection.IsOnline     = true;
                    }
                    else
                    {
                        // If not, then a new connection is created
                        db.Connections.Add(new Models.BaseEntity.Connection {
                            ConnectionId = Context.ConnectionId, UserName = userName, IsOnline = true
                        });
                    }

                    db.SaveChanges();
                }

                UsersOnline();

                return(new { Success = true });
            }
            catch (Exception ex)
            {
                return(new { Success = false, ErrorMessage = ex.Message });
            }
        }
Esempio n. 6
0
        public bool Post(PostDto postdto)
        {
            Post post = new Post();

            post.Text        = postdto.Text;
            post.UserId      = postdto.UserId;
            post.LikeCount   = 0;
            post.IsDeleted   = false;
            post.Image       = postdto.Image;
            post.LikeCount   = 0;
            post.CreatedDate = DateTime.Now;
            _context.Posts.Add(post);
            var result = _context.SaveChanges();

            if (result > default(int))
            {
                return(true);
            }
            return(false);
        }
        public ActionResult AddComment(Comment comm, int id)
        {
            var user = SessionSet <User> .Get("Login");

            comm.PostID        = id;
            comm.CreatedDate   = DateTime.Now;
            comm.CommentUserID = user.ID;
            _br.AddModel(comm);
            var          postUserID = _br.Query <Post>().Where(k => k.ID == id).FirstOrDefault().UserID;
            Notification notify     = new Notification()
            {
                UserID      = user.ID,
                ActionID    = 2,
                PostUserID  = postUserID,
                IsShow      = true,
                NotifyText  = user.Name + " commented on a post.",
                CreatedDate = DateTime.Now
            };

            _db.Notifications.Add(notify);
            _db.SaveChanges();
            return(RedirectToAction("Home", "Home"));
        }
Esempio n. 8
0
        public bool Add(string user_account, string user_pass)
        {
            try
            {
                account acc = new account();
                acc.user_account = user_account;
                acc.user_pass    = user_pass;
                db.accounts.Add(acc);
                db.SaveChanges();
                return(true);
            }

            catch
            {
                return(false);
            }
        }
Esempio n. 9
0
        public override Task OnReconnected()
        {
            using (var db = new FacebookDbContext())
            {
                var connection = db.Connections.Where(x => x.ConnectionId == Context.ConnectionId).SingleOrDefault();

                if (connection == null)
                {
                    throw new Exception("An attempt to reconnect a non tracked connection id have been made.");
                }

                connection.IsOnline = true;
                db.SaveChanges();
            }

            UsersOnline();

            return(base.OnReconnected());
        }
Esempio n. 10
0
        public ActionResult Follow()
        {
            var _user = SessionSet <User> .Get("login");

            int        FriendId = Convert.ToInt32(RouteData.Values["id"]);
            int        myId     = _user.Id;
            UserFriend uf       = new UserFriend();

            uf.UserId     = myId;
            uf.FriendId   = FriendId;
            uf.CreateDate = DateTime.Now;

            var result = loginRepo.Query <UserFriend>().Where(k => (k.UserId == uf.UserId) && (k.FriendId == uf.FriendId)).FirstOrDefault();

            if (result == null)
            {
                db.UserFriends.Add(uf);

                db.SaveChanges();
            }
            return(RedirectToAction("Index", "Home"));
        }
Esempio n. 11
0
 public void AddModel(T model)
 {
     Entity.Add(model);
     _db.SaveChanges();
 }