public int SaveSettings(Core.Entities.File file, List<Core.Entities.AddressBook> addresses) { int result = 0; using (var data = new SafeFolderEntities()) { // Save file so it can be used in the next block of code var savedFile = SaveFile(file); // Construct a FileRecipient object to persist foreach (var address in addresses) { var savedAddress = data.AddressBooks.FirstOrDefault(x => x.EmailAddress == address.EmailAddress); data.FileRecipients.Add(new FileRecipient { AddressBookId = savedAddress.Id, FileId = savedFile.Id }); } if (data.ChangeTracker.HasChanges()) { result = data.SaveChanges(); } } return result; }
public List<Core.Entities.FileRecipient> GetAllSavedFiles() { using (var data = new SafeFolderEntities()) { var files = from fileRecipient in data.FileRecipients join file in data.Files on fileRecipient.FileId equals file.Id join address in data.AddressBooks on fileRecipient.AddressBookId equals address.Id select new Core.Entities.FileRecipient { AddressBook = new Core.Entities.AddressBook { EmailAddress = address.EmailAddress }, File = new Core.Entities.File { Name = file.Name, Path = file.Path, CanCopy = file.CanCopy, CanDelete = file.CanDelete, CanModify = file.CanModify, CanForward = file.CanForward, } }; return files.ToList(); } }
public Core.Entities.Configuration GetDefault() { using (var data = new SafeFolderEntities()) { if (data.Database.Connection.State == ConnectionState.Closed) { data.Database.Connection.Open(); } Configuration configuration = null; var result = from config in data.Configurations.Where(x => x.IsDefault) select config; if (result.Any()) { configuration = result.FirstOrDefault(); if (configuration != null) { return HydrateEntity(configuration); } } return new Core.Entities.Configuration { LocalFilePath = @"c:\SafeFolder" }; } }
public List<Configuration> GetAll() { using (var data = new SafeFolderEntities()) { return data.Configurations.ToList(); } }
public List<AddressBook> GetAll() { using (var data = new SafeFolderEntities()) { return data.AddressBooks.ToList(); } }
public Configuration GetDefault() { using (var data = new SafeFolderEntities()) { var result = from config in data.Configurations.Where(x => x.IsDefault) select config; return result.FirstOrDefault(); } }
public void Delete(Core.Entities.Configuration config) { using (var data = new SafeFolderEntities()) { var model = data.Configurations.FirstOrDefault(x => x.Name == config.Name); data.Configurations.Remove(model); data.SaveChanges(); } }
public List<Core.Entities.AddressBook> GetAll() { using (var data = new SafeFolderEntities()) { return data.AddressBooks.Select(item => new Core.Entities.AddressBook { Id = item.Id, EmailAddress = item.EmailAddress }).ToList(); } }
public Core.Entities.Configuration GetByName(string name) { using (var data = new SafeFolderEntities()) { var model = data.Configurations.FirstOrDefault(x => x.Name == name); if (model != null) { return HydrateEntity(model); } return new Core.Entities.Configuration(); } }
public Core.Entities.Configuration GetById(int id) { using (var data = new SafeFolderEntities()) { var model = data.Configurations.FirstOrDefault(x => x.Id == id); if (model != null) { return HydrateEntity(model); } return new Core.Entities.Configuration(); } }
public int Save(AddressBook addressBook) { int result = 0; using (var data = new SafeFolderEntities()) { data.AddressBooks.Add(addressBook); if (data.ChangeTracker.HasChanges()) { result = data.SaveChanges(); } } return result; }
public int SaveSettings(File file) { int result = 0; using (var data = new SafeFolderEntities()) { data.Files.Add(file); if (data.ChangeTracker.HasChanges()) { result = data.SaveChanges(); } } return result; }
public int Save(Configuration config) { int result = 0; using (var data = new SafeFolderEntities()) { data.Configurations.Add(config); if (data.ChangeTracker.HasChanges()) { result = data.SaveChanges(); } } return result; }
public int Save(Core.Entities.AddressBook addressBook) { int result = 0; using (var data = new SafeFolderEntities()) { data.AddressBooks.Add(new AddressBook { EmailAddress = addressBook.EmailAddress }); if (data.ChangeTracker.HasChanges()) { result = data.SaveChanges(); } } return result; }
private File SaveFile(Core.Entities.File file) { using (var data = new SafeFolderEntities()) { var f = new File { Name = file.Name, Path = file.Path, CanCopy = file.CanCopy, CanDelete = file.CanDelete, CanForward = file.CanForward, CanModify = file.CanModify }; data.Files.Add(f); data.SaveChanges(); return f; } }
public List<Core.Entities.Configuration> GetAll() { var configList = new List<Core.Entities.Configuration>(); using (var data = new SafeFolderEntities()) { if (data.Configurations != null) { if (data.Configurations.Any()) { foreach (var config in data.Configurations) { configList.Add(HydrateEntity(config)); } } } return configList; } }
private Configuration HydrateModel(Configuration existingModel, Core.Entities.Configuration config, SafeFolderEntities data) { Configuration model = null; if (existingModel != null) { model = existingModel; model.Name = config.Name; model.IsDefault = config.IsDefault; model.LocalFilePath = config.LocalFilePath; model.ServicePath = config.ServicePath; if (data.Entry(model.OwnerProfile).State == EntityState.Modified) { model.OwnerProfile.FirstName = config.OwnerProfile.FirstName; model.OwnerProfile.LastName = config.OwnerProfile.LastName; model.OwnerProfile.EmailAddress = config.OwnerProfile.EmailAddress; model.OwnerProfile.Password = config.OwnerProfile.Password; } } else { var owner = data.OwnerProfiles.FirstOrDefault(x => x.EmailAddress == config.OwnerProfile.EmailAddress); model = new Configuration { Name = config.Name, LocalFilePath = config.LocalFilePath, ServicePath = config.ServicePath, IsDefault = config.IsDefault, OwnerProfile = (owner == null) ? new OwnerProfile { FirstName = config.OwnerProfile.FirstName, LastName = config.OwnerProfile.LastName, EmailAddress = config.OwnerProfile.EmailAddress, Password = config.OwnerProfile.Password } : null }; if (owner != null) { model.OwnerId = owner.Id; model.OwnerProfile = null; } } return model; }
public int Save(Core.Entities.Configuration config) { int result = 0; using (var data = new SafeFolderEntities()) { var model = data.Configurations.FirstOrDefault(x=>x.Name == config.Name); if (model != null) { model = HydrateModel(model, config, data); data.Configurations.Attach(model); data.Entry(model).State = EntityState.Modified; } else { var newModel = HydrateModel(model, config, data); data.Configurations.Add(newModel); } if (data.ChangeTracker.HasChanges()) { result = data.SaveChanges(); } } return result; }
public Core.Entities.OwnerProfile GetDefaultOwnerProfile() { using (var data = new SafeFolderEntities()) { Core.Entities.OwnerProfile owner = null; var model = data.Configurations.FirstOrDefault(x=>x.IsDefault); if (model != null) { owner = new Core.Entities.OwnerProfile { FirstName = model.OwnerProfile.FirstName, LastName = model.OwnerProfile.LastName, EmailAddress = model.OwnerProfile.EmailAddress, Password = model.OwnerProfile.Password }; } return owner; } }