示例#1
0
        /// <summary>
        /// Adds zip files to the database.
        /// </summary>
        /// <param name="vms">The vms<see cref="IEnumerable{ZipFileViewModel}"/>.</param>
        public static void Add(IEnumerable <ZipFileViewModel> vms)
        {
            Debug.Assert(vms != null);
            using var dbc = new PmDb();

            var pis    = new List <ZipFile>();
            var vmlist = new List <ZipFileViewModel>(vms);

            for (var i = 0; i < vmlist.Count; i++)
            {
                var vm  = vmlist[i];
                var ent = new ZipFile();
                ent.GetViewModel(vm);
                pis.Add(ent);
            }

            dbc.ZipFiles.AddRange(pis);
            dbc.SaveChanges();

            for (int i = 0; i < vmlist.Count; i++)
            {
                var vm  = vmlist[i];
                var ent = pis[i];
                vm.GetModel(ent);
            }
        }
示例#2
0
        /// <summary>
        /// Updates a single zip file of the database.
        /// </summary>
        /// <param name="vm">The vm<see cref="ZipFileViewModel"/>.</param>
        public static void Update(ZipFileViewModel vm)
        {
            Debug.Assert(vm != null);
            Debug.Assert(vm.PackageId != 0);
            using var dbc = new PmDb();
            var ent = dbc.Find <ZipFile>(vm.PackageId);

            ent.GetViewModel(vm);
            dbc.SaveChanges();
        }
示例#3
0
        /// <summary>
        /// Updates a folder of the database.
        /// </summary>
        /// <param name="vm">The vm<see cref="FolderViewModel"/>.</param>
        public static void Update(FolderViewModel vm)
        {
            Debug.Assert(vm != null);
            Debug.Assert(vm.FolderId != 0);
            using var dbc = new PmDb();
            var ent = dbc.Find <Folder>(vm.FolderId);

            ent.GetViewModel(vm);
            dbc.SaveChanges();
        }
示例#4
0
        /// <summary>
        /// Deletes a folder from the database.
        /// </summary>
        /// <param name="vm">The vm<see cref="FolderViewModel"/>.</param>
        public static void Delete(FolderViewModel vm)
        {
            Debug.Assert(vm != null);
            Debug.Assert(vm.FolderId != 0);
            using var dbc = new PmDb();
            var ent = dbc.Find <Folder>(vm.FolderId);

            dbc.Folders.Remove(ent);
            dbc.SaveChanges();
        }
示例#5
0
        /// <summary>
        /// Adds a single folder to the database.
        /// </summary>
        /// <param name="vm">The vm<see cref="FolderViewModel"/>.</param>
        public static void Add(FolderViewModel vm)
        {
            Debug.Assert(vm != null);
            using var dbc = new PmDb();
            var ent = new Folder();

            ent.GetViewModel(vm);
            dbc.Folders.Add(ent);
            dbc.SaveChanges();
            vm.GetModel(ent);
        }
示例#6
0
        /// <summary>
        /// Adds a single zip file to the database.
        /// </summary>
        /// <param name="vm">The vm<see cref="ZipFileViewModel"/>.</param>
        public static void Add(ZipFileViewModel vm)
        {
            Debug.Assert(vm != null);
            using var dbc = new PmDb();
            var ent = new ZipFile();

            ent.GetViewModel(vm);
            dbc.ZipFiles.Add(ent);
            dbc.SaveChanges();
            vm.GetModel(ent);
        }
示例#7
0
        /// <summary>
        /// Updates zip files of the database.
        /// </summary>
        /// <param name="vms">The vms<see cref="IEnumerable{ZipFileViewModel}"/>.</param>
        public static void Update(IEnumerable <ZipFileViewModel> vms)
        {
            Debug.Assert(vms != null);
            using var dbc = new PmDb();

            foreach (var vm in vms)
            {
                Debug.Assert(vm.PackageId != 0);
                var ent = dbc.Find <ZipFile>(vm.PackageId);
                ent.GetViewModel(vm);
            }

            dbc.SaveChanges();
        }
示例#8
0
        /// <summary>
        /// Deletes folders from the database.
        /// </summary>
        /// <param name="vms">The vms<see cref="IEnumerable{FolderViewModel}"/>.</param>
        public static void Delete(IEnumerable <FolderViewModel> vms)
        {
            Debug.Assert(vms != null);
            using var dbc = new PmDb();

            foreach (var vm in vms)
            {
                Debug.Assert(vm.FolderId != 0);
                var ent = dbc.Find <Folder>(vm.FolderId);
                dbc.Folders.Remove(ent);
            }

            dbc.SaveChanges();
        }
示例#9
0
        /// <summary>
        /// Deletes zip files from the database.
        /// </summary>
        /// <param name="vms">The vms<see cref="IEnumerable{ZipFileViewModel}"/>.</param>
        public static void Delete(IEnumerable <ZipFileViewModel> vms)
        {
            Debug.Assert(vms != null);
            var dbc = new PmDb();

            foreach (var vm in vms)
            {
                Debug.Assert(vm.PackageId != 0);
                var ent = dbc.Find <ZipFile>(vm.PackageId);
                dbc.ZipFiles.Remove(ent);
            }

            dbc.SaveChanges();
            dbc.Dispose();
        }
示例#10
0
        /// <summary>
        /// Deletes a single zip file from the database.
        /// </summary>
        /// <param name="vm">The vm<see cref="ZipFileViewModel"/>.</param>
        public static void Delete(ZipFileViewModel vm)
        {
            Debug.Assert(vm != null);
            Debug.Assert(vm.PackageId != 0);

            using var dbc = new PmDb();
            foreach (var item in vm.Folders)
            {
                item.PackageId = null;
                var folderEnt = dbc.Find <Folder>(item.FolderId);
                folderEnt.PackageId = null;
                dbc.Update(folderEnt);
            }

            var ent = dbc.Find <ZipFile>(vm.PackageId);

            dbc.ZipFiles.Remove(ent);
            dbc.SaveChanges();
        }