コード例 #1
0
 public static void CreatePicture(Picture picture)
 {
     using (var ctx = new MVC_GalleryDbEntities1())
     {
         ctx.Pictures.Add(picture);
         ctx.SaveChanges();
     }
 }
コード例 #2
0
 public static void CreateAccount(Account account)
 {
     using (var ctx = new MVC_GalleryDbEntities1())
     {
         account.Id = Guid.NewGuid();
         ctx.Accounts.Add(account);
         ctx.SaveChanges();
     }
 }
コード例 #3
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();
     }
 }
コード例 #4
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();
     }
 }
コード例 #5
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();
     }
 }
コード例 #6
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();
     }
 }
コード例 #7
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();
     }
 }
コード例 #8
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();
     }
 }
コード例 #9
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();
     }
 }
コード例 #10
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();
            }
        }
コード例 #11
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();
     }
 }