Пример #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 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();
            }
        }
Пример #3
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;
        }
Пример #4
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;
        }
Пример #5
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;
        }
Пример #6
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;
        }
Пример #7
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;
        }
Пример #8
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;
            }
        }