public CheckResult SaveFile(FileBlobModel model) { if (!model.IsChanged) { return(new CheckResult(model)); } using (DSModel db = DB.GetContext()) { var check = FileBlobValidator.ValidateSave(db, model); if (check.Failed) { return(check); } KeyBinder key = new KeyBinder(); try { FileBlobRepository.SaveBlob(db, key, model); db.SaveChanges(); key.BindKeys(); model.IsChanged = false; return(new CheckResult(model)); } catch (Exception ex) { key.RollbackKeys(); return(new CheckResult(ex)); } } }
public CheckResult AttachMultipleFiles(string[] files) { using (var db = DB.GetContext()) { KeyBinder key = new KeyBinder(); try { foreach (string file in files) { FileBlobModel mod = new FileBlobModel(); mod.BlobName = Path.GetFileNameWithoutExtension(file); mod.BlobExtension = Path.GetExtension(file); mod.BlobData = File.ReadAllBytes(file); mod.DriverID = this.CreationInfo.DriverID; FileBlobRepository.SaveBlob(db, key, mod); } db.SaveChanges(); key.BindKeys(); return(new CheckResult()); } catch (Exception ex) { key.RollbackKeys(); return(new CheckResult(ex)); } } }