public void RemoveImage(int imageId) { using (ImageClassesDataContext context = new ImageClassesDataContext()) { try { ImageTable entity = context.ImageTables.SingleOrDefault(x => x.Id == imageId); context.ImageTables.DeleteOnSubmit(entity); context.SubmitChanges(); } catch (Exception ex) { throw ex; } } }
public void AddImage(ImageDetails newImage) { using (ImageClassesDataContext context = new ImageClassesDataContext()) { try { ImageTable entity = new ImageTable(); entity.Name = newImage.Name; entity.Image = newImage.Image; entity.Size = newImage.Size; context.ImageTables.InsertOnSubmit(entity); context.SubmitChanges(); } catch (Exception ex) { throw ex; } } }
public List<ImageDetails> RemoveDuplicates() { using (ImageClassesDataContext context = new ImageClassesDataContext()) { try { List<ImageTable> entity = context.ImageTables.GroupBy(x => x.Name).Select(y => y.First()).ToList(); context.ImageTables.DeleteAllOnSubmit(context.ImageTables); context.ImageTables.InsertAllOnSubmit(entity); context.SubmitChanges(); } catch (Exception ex) { throw ex; } } List<ImageDetails> imageList = GetAllImages(); return imageList; }