public void CreateUser(User data)
        {
            DatabaseDataContext context = new DatabaseDataContext();

            context.Users.InsertOnSubmit(data);
            context.SubmitChanges();
        }
        public void CreatePicture(Picture data)
        {
            DatabaseDataContext context = new DatabaseDataContext();

            context.Pictures.InsertOnSubmit(data);
            context.SubmitChanges();
        }
        public void CreateRelationship(Relationship data)
        {
            DatabaseDataContext context = new DatabaseDataContext();

            context.Relationships.InsertOnSubmit(data);
            context.SubmitChanges();
        }
        public void CreateUserConnectedAccount(UserConnectedAccount data)
        {
            DatabaseDataContext context = new DatabaseDataContext();

            context.UserConnectedAccounts.InsertOnSubmit(data);
            context.SubmitChanges();
        }
        public void DeleteRelationship(Guid userId, Guid followingUserId)
        {
            DatabaseDataContext context = new DatabaseDataContext();

            Relationship relationship = context.Relationships.Where(u => u.UserID == userId &&
                                                                    u.FollowingUserID == followingUserId).SingleOrDefault();

            context.Relationships.DeleteOnSubmit(relationship);
            context.SubmitChanges();
        }
        public void DeleteFlaggedPicture(Guid userId, Guid pictureId)
        {
            DatabaseDataContext context = new DatabaseDataContext();

            FlaggedPicture flaggedPicture = context.FlaggedPictures.Where(u => u.UserID == userId &&
                                                                          u.PictureID == pictureId).SingleOrDefault();

            context.FlaggedPictures.DeleteOnSubmit(flaggedPicture);
            context.SubmitChanges();
        }
        public void DeleteUserConnectedAccount(Guid userId, string accountName)
        {
            DatabaseDataContext context = new DatabaseDataContext();

            UserConnectedAccount userConnectedAccount = context.UserConnectedAccounts.Where(u => u.UserID == userId &&
                                                                                            u.AccountName == accountName).SingleOrDefault();

            context.UserConnectedAccounts.DeleteOnSubmit(userConnectedAccount);
            context.SubmitChanges();
        }
        public void DeleteFlaggedPicture(Guid userId, Guid pictureId)
        {
            DatabaseDataContext context = new DatabaseDataContext();

            FlaggedPicture flaggedPicture = context.FlaggedPictures.Where(u => u.UserID == userId &&
                                                                               u.PictureID == pictureId).SingleOrDefault();

            context.FlaggedPictures.DeleteOnSubmit(flaggedPicture);
            context.SubmitChanges();
        }
 public int get_IDNV(string username, string pass)//lấy id nhân viên khi đăng nhập
 {
     using (DatabaseDataContext data = new DatabaseDataContext())
     {
         return((from u in data.NhanViens
                 where u.Username.Equals(username)
                 where u.Password.Equals(pass)
                 select u.MaNV).Single());
     }
 }
 public int get_CountUser_PassNV(string username, string pass)// đếm số lượng username và pass NV để phân quyền
 {
     using (DatabaseDataContext data = new DatabaseDataContext())
     {
         return((from u in data.NhanViens
                 where u.Username.Equals(username)
                 where u.Password.Equals(pass)
                 select u.Username).Count());
     }
 }
        public List <Int32> get_MaHoatDong(int maQuyen) // lấy list hoạt động của nv
        {
            List <Int32> arr = null;

            using (DatabaseDataContext data = new DatabaseDataContext())
            {
                return((from u in data.Quyen_HoatDongs
                        where u.MaQuyen.Equals(maQuyen)
                        where u.TrangThai.Equals("True")
                        select u.MaHoatDong).ToList());
            }
        }
        public void UpdatePicture(Picture data)
        {
            DatabaseDataContext context = new DatabaseDataContext();

            Picture picture = context.Pictures.Where(u => u.PictureID == data.PictureID).SingleOrDefault();

            picture.Caption   = data.Caption;
            picture.LargeURL  = data.LargeURL;
            picture.Latitude  = data.Latitude;
            picture.Longitude = data.Longitude;
            picture.MediumURL = data.MediumURL;
            picture.SmallURL  = data.SmallURL;
            picture.ViewCount = data.ViewCount;

            context.SubmitChanges();
        }
        public void UpdateUser(User data)
        {
            DatabaseDataContext context = new DatabaseDataContext();

            User user = context.Users.Where(u => u.UserID == data.UserID).SingleOrDefault();

            user.Biography        = data.Biography;
            user.EmailAddress     = data.EmailAddress;
            user.Location         = data.Location;
            user.Name             = data.Name;
            user.Password         = data.Password;
            user.ProfilePictureID = data.ProfilePictureID;
            user.Username         = data.Username;

            context.SubmitChanges();
        }
        public List<FlaggedPicture> GetFlaggedPictures(Guid userId)
        {
            DatabaseDataContext context = new DatabaseDataContext();

            return context.FlaggedPictures.Where(u => u.UserID == userId).ToList();
        }
        public void DeletePicture(Guid id)
        {
            DatabaseDataContext context = new DatabaseDataContext();

            Picture picture = context.Pictures.Where(u => u.PictureID == id).SingleOrDefault();

            context.Pictures.DeleteOnSubmit(picture);
            context.SubmitChanges();
        }
        public User GetUser(Guid id)
        {
            DatabaseDataContext context = new DatabaseDataContext();

            return(context.Users.Where(u => u.UserID == id).SingleOrDefault());
        }
        public List <UserConnectedAccount> GetUserConnectedAccounts(Guid userId)
        {
            DatabaseDataContext context = new DatabaseDataContext();

            return(context.UserConnectedAccounts.Where(u => u.UserID == userId).ToList());
        }
        public List <FlaggedPicture> GetFlaggedPictures(Guid userId)
        {
            DatabaseDataContext context = new DatabaseDataContext();

            return(context.FlaggedPictures.Where(u => u.UserID == userId).ToList());
        }
        public Picture GetPicture(Guid id)
        {
            DatabaseDataContext context = new DatabaseDataContext();

            return(context.Pictures.Where(u => u.PictureID == id).SingleOrDefault());
        }
        public void UpdateUser(User data)
        {
            DatabaseDataContext context = new DatabaseDataContext();

            User user = context.Users.Where(u => u.UserID == data.UserID).SingleOrDefault();
            user.Biography = data.Biography;
            user.EmailAddress = data.EmailAddress;
            user.Location = data.Location;
            user.Name = data.Name;
            user.Password = data.Password;
            user.ProfilePictureID = data.ProfilePictureID;
            user.Username = data.Username;

            context.SubmitChanges();
        }
        public void UpdatePicture(Picture data)
        {
            DatabaseDataContext context = new DatabaseDataContext();

            Picture picture = context.Pictures.Where(u => u.PictureID == data.PictureID).SingleOrDefault();
            picture.Caption = data.Caption;
            picture.LargeURL = data.LargeURL;
            picture.Latitude = data.Latitude;
            picture.Longitude = data.Longitude;
            picture.MediumURL = data.MediumURL;
            picture.SmallURL = data.SmallURL;
            picture.ViewCount = data.ViewCount;

            context.SubmitChanges();
        }
        public List<UserConnectedAccount> GetUserConnectedAccounts(Guid userId)
        {
            DatabaseDataContext context = new DatabaseDataContext();

            return context.UserConnectedAccounts.Where(u => u.UserID == userId).ToList();
        }
        public User GetUser(Guid id)
        {
            DatabaseDataContext context = new DatabaseDataContext();

            return context.Users.Where(u => u.UserID == id).SingleOrDefault();
        }
        public List<Relationship> GetRelationships(Guid userId)
        {
            DatabaseDataContext context = new DatabaseDataContext();

            return context.Relationships.Where(u => u.UserID == userId).ToList();
        }
        public void DeleteRelationship(Guid userId, Guid followingUserId)
        {
            DatabaseDataContext context = new DatabaseDataContext();

            Relationship relationship = context.Relationships.Where(u => u.UserID == userId &&
                                                                         u.FollowingUserID == followingUserId).SingleOrDefault();

            context.Relationships.DeleteOnSubmit(relationship);
            context.SubmitChanges();
        }
        public void DeleteUserConnectedAccount(Guid userId, string accountName)
        {
            DatabaseDataContext context = new DatabaseDataContext();

            UserConnectedAccount userConnectedAccount = context.UserConnectedAccounts.Where(u => u.UserID == userId &&
                                                                                                 u.AccountName == accountName).SingleOrDefault();

            context.UserConnectedAccounts.DeleteOnSubmit(userConnectedAccount);
            context.SubmitChanges();
        }
        public void DeleteUser(Guid id)
        {
            DatabaseDataContext context = new DatabaseDataContext();

            User user = context.Users.Where(u => u.UserID == id).SingleOrDefault();

            context.Users.DeleteOnSubmit(user);
            context.SubmitChanges();
        }
        public Picture GetPicture(Guid id)
        {
            DatabaseDataContext context = new DatabaseDataContext();

            return context.Pictures.Where(u => u.PictureID == id).SingleOrDefault();
        }
        public List <Relationship> GetRelationships(Guid userId)
        {
            DatabaseDataContext context = new DatabaseDataContext();

            return(context.Relationships.Where(u => u.UserID == userId).ToList());
        }