public static void CreatePicture(Picture picture) { using (var ctx = new MVC_GalleryDbEntities1()) { ctx.Pictures.Add(picture); ctx.SaveChanges(); } }
public static void CreateAccount(Account account) { using (var ctx = new MVC_GalleryDbEntities1()) { account.Id = Guid.NewGuid(); ctx.Accounts.Add(account); ctx.SaveChanges(); } }
public static void DeleteComment(Guid id) { using (var ctx = new MVC_GalleryDbEntities1()) { var Entity = ctx.Comments.Find(id); ctx.Comments.Remove(Entity); ctx.SaveChanges(); } }
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(); } }
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(); } }
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(); } }
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(); } }
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(); } }
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(); } }
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(); } }
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(); } }