public void Delete(int id) { using (AzurePhotoManagerContext context = new AzurePhotoManagerContext()) { var photo = context.Photos.Find(id); context.Photos.Remove(photo); context.SaveChanges(); } }
public void InsertOrUpdate(Photo photo) { using (AzurePhotoManagerContext context = new AzurePhotoManagerContext()) { Photo current = null; if (photo.Id == default(int)) { // New entity current = context.Photos.FirstOrDefault<Photo>(p => p.Name == photo.Name); if (current == null) { context.Photos.Add(photo); } else { photo.Id = current.Id; context.Entry(photo).State = EntityState.Modified; } } else { // Existing entity context.Entry(photo).State = EntityState.Modified; } context.SaveChanges(); } }