public async Task <IActionResult> Create([Bind("ImageId,Title,ImageFile")] ImageModel imageModel)
        {
            if (ModelState.IsValid)
            {
                //Bu kodlar resimleri wwwroot a kaydeder

                string wwwRoothPath = _hostEnvironment.WebRootPath;
                string fileName     = Path.GetFileNameWithoutExtension(imageModel.ImageFile.FileName);
                string extension    = Path.GetExtension(imageModel.ImageFile.FileName);
                imageModel.ImageName = fileName = fileName + DateTime.Now.ToString("yymmssfff") + extension;
                string path = Path.Combine(wwwRoothPath + "/Image/", fileName);

                using (var fileStream = new FileStream(path, FileMode.Create))
                {
                    await imageModel.ImageFile.CopyToAsync(fileStream);
                }


                _context.Add(imageModel);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(imageModel));
        }
Exemplo n.º 2
0
        public async Task <int> Create(ImageModel imageModel)
        {
            Image image = ConvertImageModelToImage(imageModel);

            _context.Add(image);
            int success = await _context.SaveChangesAsync();

            return(success);
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Create([Bind("WordId,Title,WordName")] WordModel wordModel)
        {
            if (ModelState.IsValid)
            {
                _context.Add(wordModel);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(wordModel));
        }
Exemplo n.º 4
0
        public async Task <IActionResult> Create([Bind("HaberId,Baslik,İcerik,SonDakika,ResimDosyası")] Haber haber)
        {
            if (ModelState.IsValid)
            {
                string wwwRoothPath = _hostEnvironment.WebRootPath;
                string fileName     = Path.GetFileNameWithoutExtension(haber.ResimDosyası.FileName);
                string extension    = Path.GetExtension(haber.ResimDosyası.FileName);
                haber.ResimYolu = fileName = fileName + DateTime.Now.ToString("yymmssfff") + extension;
                string path = Path.Combine(wwwRoothPath + "/HaberResimleri/", fileName);

                using (var fileStream = new FileStream(path, FileMode.Create))
                {
                    await haber.ResimDosyası.CopyToAsync(fileStream);
                }
                _context.Add(haber);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(haber));
        }
Exemplo n.º 5
0
        public async Task <IActionResult> Create([Bind("Id,Name,FileType,Description,FilePath,VideoYolu")] VideoModel videoModel)
        {
            if (ModelState.IsValid)
            {
                string wwwRoothPath = _hostEnvironment.WebRootPath;
                string fileName     = Path.GetFileNameWithoutExtension(videoModel.VideoDosyası.FileName);
                string extension    = Path.GetExtension(videoModel.VideoDosyası.FileName);
                videoModel.FilePath = fileName = fileName + DateTime.Now.ToString("yymmssfff") + extension;
                string path = Path.Combine(wwwRoothPath + "/Videolar/", fileName);

                using (var fileStream = new FileStream(path, FileMode.Create))
                {
                    await videoModel.VideoDosyası.CopyToAsync(fileStream);
                }
                _context.Add(videoModel);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }

            return(View(videoModel));
        }
Exemplo n.º 6
0
        public async Task GetImagesFromUrl(string url)
        {
            WebClient webClient = new WebClient();
            string    source    = webClient.DownloadString(url);

            HtmlAgilityPack.HtmlDocument document = new HtmlAgilityPack.HtmlDocument();
            document.LoadHtml(source);

            var lista = document.DocumentNode.Descendants("img").Select(i => i.Attributes["src"]);

            foreach (var link in lista)
            {
                string urlDownload = link.Value.ToString();
                if (urlDownload.StartsWith("/"))
                {
                    urlDownload = url + link.Value.ToString();
                }

                string fileName = "image" + DateTime.Now.ToString("yymmssfff") + Path.GetExtension(link.Value.ToString()).Substring(0, 4);
                string path     = Path.Combine(_hostEnvironment.WebRootPath + "/image", fileName);

                ImageModel model = new ImageModel();
                model.ImageName = fileName;
                model.Title     = url;

                MemoryStream ms = new MemoryStream(webClient.DownloadData(urlDownload));
                model.ImageFile = new FormFile(ms, 0, ms.Length, fileName, fileName);

                using (var fileStream = new FileStream(path, FileMode.Create))
                {
                    await model.ImageFile.CopyToAsync(fileStream);
                }

                _context.Add(model);
                await _context.SaveChangesAsync();
            }
        }