예제 #1
0
        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;
        }
예제 #2
0
        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();
            }
        }
예제 #3
0
        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"
                };
            }
        }
예제 #4
0
 public List<Configuration> GetAll()
 {
     using (var data = new SafeFolderEntities())
     {
         return data.Configurations.ToList();
     }
 }
예제 #5
0
 public List<AddressBook> GetAll()
 {
     using (var data = new SafeFolderEntities())
     {
         return data.AddressBooks.ToList();
     }
 }
예제 #6
0
        public Configuration GetDefault()
        {
            using (var data = new SafeFolderEntities())
            {
                var result = from config in data.Configurations.Where(x => x.IsDefault) select config;

                return result.FirstOrDefault();
            }
        }
예제 #7
0
        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();
            }
        }
예제 #8
0
 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();
     }
 }
예제 #9
0
        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();
            }
        }
예제 #10
0
        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();
            }
        }
예제 #11
0
        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;
        }
예제 #12
0
        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;
        }
예제 #13
0
        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;
        }
예제 #14
0
        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;
        }
예제 #15
0
        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;
            }
        }
예제 #16
0
        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;
            }
        }
예제 #17
0
        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;
        }
예제 #18
0
        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;
        }
예제 #19
0
        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;
            }
        }