Ejemplo n.º 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();
        }
Ejemplo n.º 2
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();
        }