コード例 #1
0
        public static void AddNewPhoto(string nameImg, string path, int idAlbum)
        {
            Lab_7Entities13 context = new Lab_7Entities13();
            Images          image   = new Images();

            image.Path = path;
            context.Images.Add(image);
            context.SaveChanges();
            int idPage = (from u in context.Images
                          where u.Path == path
                          select u.Id).FirstOrDefault();
            int         idUser = WorkWithDb.getInformationActiveUser().Id;
            UsersImages users  = new UsersImages();

            users.IdUser  = idUser;
            users.IdImage = idPage;
            users.Name    = nameImg;
            context.UsersImages.Add(users);
            context.SaveChanges();
            int idPost = (from posts in context.UsersImages
                          select posts.Id).ToList().Last();
            UserAlbumPosts userAlbumPosts = new UserAlbumPosts();

            userAlbumPosts.IdUsersAlbum = idAlbum;
            userAlbumPosts.IdPost       = idPost;
            context.UserAlbumPosts.Add(userAlbumPosts);
            context.SaveChanges();
        }
コード例 #2
0
        public static void AddComment(int idPost, string text)
        {
            Lab_7Entities13     context      = new Lab_7Entities13();
            int                 activeUserId = WorkWithDb.getInformationActiveUser().Id;
            UsersImagesComments comment      = new UsersImagesComments();

            comment.IdPost  = idPost;
            comment.IdUser  = activeUserId;
            comment.Comment = text;
            context.UsersImagesComments.Add(comment);
            context.SaveChanges();
        }
コード例 #3
0
        public static void DeletePhoto(string nameOfPhoto, int idAlbum)
        {
            Lab_7Entities13 context = new Lab_7Entities13();
            int             idUser  = WorkWithDb.getInformationActiveUser().Id;
            UsersImages     user    = (from image in context.UsersImages
                                       join albums in context.UserAlbumPosts on image.Id equals albums.IdPost
                                       where image.Name == nameOfPhoto && image.IdUser == Users.ActiveUser && albums.IdUsersAlbum == idAlbum
                                       select image).FirstOrDefault();

            context.UsersImages.Attach(user);
            context.UsersImages.Remove(user);
            context.SaveChanges();
        }