public void Delete(string name) { using (WGHotelBaseEntities db = new WGHotelBaseEntities()) { var ImageFile = db.ImageStore.Where(o => o.Name == name).FirstOrDefault(); if (ImageFile != null) { db.ImageStore.Attach(ImageFile); db.ImageStore.Remove(ImageFile); db.SaveChanges(); } } }
public void Save(List <ImageViewModel> models) { using (WGHotelBaseEntities db = new WGHotelBaseEntities()) { var dbImg = db.ImageStore; var Now = DateTime.Now; foreach (var img in models) { dbImg.Add(new ImageStore { ReferIdUS = img.ReferIdUS, ReferIdZH = img.ReferIdZH, Created = Now, Image = img.Image, Extension = img.Extension, Deleted = false, Path = null, Name = img.Name, Type = img.Type }); } db.SaveChanges(); } }