コード例 #1
0
        public GalleryViewModel ReadGalleryFilesFromDB(GalleryViewModel viewModel)
        {
            foreach (GalleryFileImg galleryImg in _dbContext.GalleryFilesImgs)
            {
                var gi = new GalleryFileImg();
                gi.Id       = galleryImg.Id;
                gi.FileName = galleryImg.FileName;
                gi.Size     = galleryImg.Size;
                viewModel.GalleryItemImgs.Add(gi);
            }

            foreach (GalleryFileSound gallerySound in _dbContext.GalleryFilesSounds)
            {
                var gi = new GalleryFileSound();
                gi.Id       = gallerySound.Id;
                gi.FileName = gallerySound.FileName;
                gi.Size     = gallerySound.Size;
                viewModel.GalleryItemSounds.Add(gi);
            }

            foreach (UploadFileImg uploadImg in _dbContext.UploadFilesImgs.Where(a => a.UserId == UserID))
            {
                var gi = new UploadFileImg();
                gi.UserId   = UserID;
                gi.Id       = uploadImg.Id;
                gi.FileName = uploadImg.FileName;
                gi.Size     = uploadImg.Size;
                viewModel.UploadItemImgs.Add(gi);
            }

            foreach (UploadFileSound uploadSound in _dbContext.UploadFilesSounds.Where(a => a.UserId == UserID))
            {
                var gi = new UploadFileSound();
                gi.UserId   = UserID;
                gi.Id       = uploadSound.Id;
                gi.FileName = uploadSound.FileName;
                gi.Size     = uploadSound.Size;
                viewModel.UploadItemSounds.Add(gi);
            }

            viewModel.ImageGalleryCount = _dbContext.GalleryFilesImgs.Count();
            viewModel.SoundGalleryCount = _dbContext.GalleryFilesSounds.Count();
            viewModel.ImageUploadCount  = _dbContext.UploadFilesImgs.Where(a => a.UserId == UserID).Count();
            viewModel.SoundUploadCount  = _dbContext.UploadFilesSounds.Where(a => a.UserId == UserID).Count();

            return(viewModel);
        }
コード例 #2
0
ファイル: DefaultDataDB.cs プロジェクト: Shalex9/TestNetCore
        public void GallerySound()
        {
            if (!_dbContext.GalleryFilesSounds.Any())
            {
                var filePath = "Files/gallery_sound.txt";
                var data     = File.ReadAllLines(filePath);

                foreach (var line in data)
                {
                    GalleryFileSound w = new GalleryFileSound();

                    string[] lineData = line.Split(new char[] { ' ' });

                    w.FileName = lineData[0];
                    w.Size     = lineData[1];

                    _dbContext.GalleryFilesSounds.Add(w);
                }
                _dbContext.SaveChanges();
            }
        }