예제 #1
0
 public static List <Album> GetAlbums()
 {
     using (var ctx = new MVC_GalleryDbEntities1())
     {
         return(ctx.Albums.ToList());
     }
 }
예제 #2
0
 public static List <Comment> GetCommentsFromPicture(Guid id)
 {
     using (var ctx = new MVC_GalleryDbEntities1())
     {
         return(ctx.Comments.Where(x => x.PictureRefID == id).ToList());
     }
 }
예제 #3
0
 public static List <Album> AccGetAlbums(Guid id)
 {
     using (var ctx = new MVC_GalleryDbEntities1())
     {
         return(ctx.Albums.Where(x => x.AccountRefID == id).ToList());
     }
 }
예제 #4
0
 public static Comment GetComment(Guid id)
 {
     using (var ctx = new MVC_GalleryDbEntities1())
     {
         return(ctx.Comments.Find(id));
     }
 }
예제 #5
0
 public static Account GetAccount(string accUserName)
 {
     using (var ctx = new MVC_GalleryDbEntities1())
     {
         return(ctx.Accounts.Single(x => x.UserName == accUserName));
     }
 }
예제 #6
0
 public static Album GetAlbum(Guid id)
 {
     using (var ctx = new MVC_GalleryDbEntities1())
     {
         return(ctx.Albums.Find(id));
     }
 }
예제 #7
0
 public static List <Picture> GetPictures()
 {
     using (var ctx = new MVC_GalleryDbEntities1())
     {
         return(ctx.Pictures.ToList());
     }
 }
예제 #8
0
 public static List <Picture> GetPictureToAlbum(Guid Album_id)
 {
     using (var ctx = new MVC_GalleryDbEntities1())
     {
         return(ctx.Pictures.Where(x => x.AlbumRefID == Album_id).ToList <Picture>());
     }
 }
예제 #9
0
 public static Account GetAccount(Guid CommentId)
 {
     using (var ctx = new MVC_GalleryDbEntities1())
     {
         var comment = ctx.Comments.Find(CommentId);
         return(ctx.Accounts.SingleOrDefault(x => x.Id == comment.AccountRefID));
     }
 }
예제 #10
0
 public static void CreatePicture(Picture picture)
 {
     using (var ctx = new MVC_GalleryDbEntities1())
     {
         ctx.Pictures.Add(picture);
         ctx.SaveChanges();
     }
 }
예제 #11
0
 public static void DeleteComment(Guid id)
 {
     using (var ctx = new MVC_GalleryDbEntities1())
     {
         var Entity = ctx.Comments.Find(id);
         ctx.Comments.Remove(Entity);
         ctx.SaveChanges();
     }
 }
예제 #12
0
 public static void CreateAccount(Account account)
 {
     using (var ctx = new MVC_GalleryDbEntities1())
     {
         account.Id = Guid.NewGuid();
         ctx.Accounts.Add(account);
         ctx.SaveChanges();
     }
 }
예제 #13
0
 public static void CreateAlbum(Album album)
 {
     using (var ctx = new MVC_GalleryDbEntities1())
     {
         album.DateCreated = DateTime.Now;
         album.Id          = Guid.NewGuid();
         ctx.Albums.Add(album);
         ctx.SaveChanges();
     }
 }
예제 #14
0
 public static void CreateComment(Comment comment)
 {
     using (var ctx = new MVC_GalleryDbEntities1())
     {
         comment.DateCreated = DateTime.Now;
         comment.Id          = Guid.NewGuid();
         ctx.Comments.Add(comment);
         ctx.SaveChanges();
     }
 }
예제 #15
0
        public static Picture GetPicture(Guid id)
        {
            using (var ctx = new MVC_GalleryDbEntities1())
            {
                ctx.Configuration.LazyLoadingEnabled = false;

                var Entity = ctx.Pictures.FirstOrDefault(x => x.Id == id);
                ctx.Entry(Entity).Collection(x => x.Comments).Load();
                return(Entity);
            }
        }
예제 #16
0
 public static void DeletePicture(Picture picture)
 {
     using (var ctx = new MVC_GalleryDbEntities1())
     {
         var EntityPicture  = ctx.Pictures.Find(picture.Id);
         var EntityComments = ctx.Comments.Where(x => x.PictureRefID == picture.Id);
         ctx.Comments.RemoveRange(EntityComments);
         ctx.Pictures.Remove(EntityPicture);
         ctx.SaveChanges();
     }
 }
예제 #17
0
 public static List <Comment> GetComment(Guid id, string idType)
 {
     using (var ctx = new MVC_GalleryDbEntities1())
     {
         if (idType == "picture")
         {
             return(ctx.Comments.Where(x => x.PictureRefID == id).ToList());
         }
     }
     return(null);
 }
예제 #18
0
 public static void EditPicture(Picture picture)
 {
     using (var ctx = new MVC_GalleryDbEntities1())
     {
         ctx.Configuration.LazyLoadingEnabled = false;
         var EntityToEdit = ctx.Pictures.FirstOrDefault(x => x.Id == picture.Id);
         EntityToEdit.Name = picture.Name;
         EntityToEdit.Url  = picture.Url;
         EntityToEdit.Size = picture.Size;
         ctx.SaveChanges();
     }
 }
예제 #19
0
 public static void CreateChatPost(Chat chat)
 {
     using (var ctx = new MVC_GalleryDbEntities1())
     {
         if (chat.AccountRefID == new Guid())
         {
             chat.AccountRefID = null;
         }
         chat.Id = Guid.NewGuid();
         ctx.Chats.Add(chat);
         ctx.SaveChanges();
     }
 }
예제 #20
0
 public static List <Chat> GetChat()
 {
     using (var ctx = new MVC_GalleryDbEntities1())
     {
         var sortedChat = ctx.Chats.OrderBy(x => x.PostDate).ToList();
         var result     = new List <Chat>();
         for (int i = sortedChat.Count - 10; i < sortedChat.Count; i++)
         {
             result.Add(sortedChat[i]);
         }
         return(result);
     }
 }
예제 #21
0
 public static string GetAccountName(Guid accountRefID)
 {
     using (var ctx = new MVC_GalleryDbEntities1())
     {
         if (accountRefID != new Guid())
         {
             return(ctx.Accounts.SingleOrDefault(x => x.Id == accountRefID).UserName);
         }
         else
         {
             return(null);
         }
     }
 }
예제 #22
0
        public static Account GetAccount(Guid id, string Type)
        {
            var accid = new Guid();

            using (var ctx = new MVC_GalleryDbEntities1())
            {
                if (Type == "album")
                {
                    var album = ctx.Albums.SingleOrDefault(x => x.Id == id);
                    accid = (Guid)album.AccountRefID;
                }
                return(ctx.Accounts.FirstOrDefault(x => x.Id == accid));
            }
        }
예제 #23
0
 public static void CreateOrUpdate(Picture picture)
 {
     using (var ctx = new MVC_GalleryDbEntities1())
     {
         var Entity = ctx.Pictures.FirstOrDefault(m => m.Id == picture.Id)
                      ?? new Picture()
         {
             Id = Guid.NewGuid()
         };
         Entity.Name   = picture.Name;
         Entity.Public = picture.Public;
         ctx.Pictures.AddOrUpdate(Entity);
         ctx.SaveChanges();
     }
 }
예제 #24
0
        public static void CreateOrUpdate(Album album)
        {
            using (var ctx = new MVC_GalleryDbEntities1())
            {
                var entity =
                    ctx.Albums.FirstOrDefault(x => x.Id == album.Id)
                    ?? new Album()
                {
                    Id = Guid.NewGuid(), DateCreated = DateTime.Now
                };

                entity.Name         = album.Name;
                entity.Topic        = album.Topic;
                entity.AccountRefID = album.AccountRefID;
                ctx.Albums.AddOrUpdate(entity);
                ctx.SaveChanges();
            }
        }
예제 #25
0
 public static void DeleteAlbum(Album album)
 {
     using (var ctx = new MVC_GalleryDbEntities1())
     {
         var Comments = new List <Comment>();
         //Albument
         var Album = ctx.Albums.Find(album.Id);
         //Alla bilder från det albumet
         var Pictures = ctx.Pictures.Where(x => x.AlbumRefID == album.Id).ToList <Picture>();
         //Alla kommentarer på alla bilder
         foreach (var item in Pictures)
         {
             var comments = ctx.Comments.Where(x => x.PictureRefID == item.Id).ToList <Comment>();
             Comments.AddRange(comments);
         }
         ctx.Comments.RemoveRange(Comments);
         ctx.Pictures.RemoveRange(Pictures);
         ctx.Albums.Remove(Album);
         ctx.SaveChanges();
     }
 }
예제 #26
0
        public static bool CreateOrUpdate(Account account)
        {
            using (var ctx = new MVC_GalleryDbEntities1())
            {
                try
                {
                    var Entity = ctx.Accounts.FirstOrDefault(x => x.Id == account.Id)
                                 ?? new Account()
                    {
                        Id = Guid.NewGuid()
                    };

                    //Entity.UserName = account.UserName;
                    //ctx.Accounts.AddOrUpdate(Entity);
                    //ctx.SaveChanges();
                }
                catch
                {
                    return(false);
                }
                return(true);
            }
        }