コード例 #1
0
ファイル: MudursController.cs プロジェクト: sehend/AspNetCore
        public async Task <IActionResult> Create([Bind("MudurId,imageFile,MudurAd,MudurSoyad,MudurEmail,MudurAdres,PersonelTc,UrunId")] Mudur mudur)
        {
            if (ModelState.IsValid)
            {
                string wwRootPath = _hostEnvironment.WebRootPath;
                string fileName   = Path.GetFileNameWithoutExtension(mudur.imageFile.FileName);
                string extention  = Path.GetExtension(mudur.imageFile.FileName);
                mudur.imageName = fileName = fileName + DateTime.Now.ToString("yymmssfff") + extention;
                string path = Path.Combine(wwRootPath + "/image/Admin/", fileName);

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



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

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["UrunId"] = new SelectList(_context.Urunlers, "UrunId", "UrunId", mudur.UrunId);
            return(View(mudur));
        }
コード例 #2
0
        public async Task <IActionResult> Create([Bind("OppoId,imageFile,OppoAciklama,Fiyat")] Oppo oppo)
        {
            if (ModelState.IsValid)
            {
                string wwRootPath = _hostEnvironment.WebRootPath;
                string fileName   = Path.GetFileNameWithoutExtension(oppo.imageFile.FileName);
                string extention  = Path.GetExtension(oppo.imageFile.FileName);
                oppo.imageName = fileName = fileName + DateTime.Now.ToString("yymmssfff") + extention;
                string path = Path.Combine(wwRootPath + "/image/Oppo/", fileName);

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



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

                return(RedirectToAction(nameof(Index)));
            }
            return(View(oppo));
        }
コード例 #3
0
        public async Task <IActionResult> Create([Bind("PersonelId,imageFile,PersonelAd,PersonelSoyad,PersonelEmail,PersonelAdres")] Personel personel)
        {
            if (ModelState.IsValid)
            {
                string wwRootPath = _hostEnvironment.WebRootPath;
                string fileName   = Path.GetFileNameWithoutExtension(personel.imageFile.FileName);
                string extention  = Path.GetExtension(personel.imageFile.FileName);
                personel.imageName = fileName = fileName + DateTime.Now.ToString("yymmssfff") + extention;
                string path = Path.Combine(wwRootPath + "/image/Personel/", fileName);

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



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

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