Пример #1
0
        public async Task <IActionResult> Create([Bind("Matintuc,Tieude,Tieudecon,Noidung,Anh,Ngaydang,Tacgia,Machuyenmuc")] Tintuc tintuc, IFormFile Anh, Chuyenmuc chuyenmuc)
        {
            if (ModelState.IsValid)
            {
                if (Anh != null && Anh.Length > 0)
                {
                    var uploadpath = Path.Combine(_enviroment.WebRootPath, "images");
                    Directory.CreateDirectory(Path.Combine(uploadpath));
                    string filename = Anh.FileName;
                    if (filename.Contains('\\'))
                    {
                        filename = filename.Split('\\').Last();
                    }
                    using (FileStream fileStream = new FileStream(Path.Combine(uploadpath, filename), FileMode.Create))
                    {
                        await Anh.CopyToAsync(fileStream);

                        tintuc.Anh = Anh.FileName;
                    }
                }
                tintuc.Ngaydang = DateTime.Now;
                var sbv = await _context.Chuyenmuc.SingleOrDefaultAsync(c => c.Machuyenmuc == tintuc.Machuyenmuc);

                var encode = _javaScriptEncoder.Encode(tintuc.Noidung);

                tintuc.Noidung = encode;
                _context.Add(tintuc);

                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            ViewData["Machuyenmuc"] = new SelectList(_context.Chuyenmuc, "Tenchuyenmuc", "Tenchuyenmuc", tintuc.Machuyenmuc);
            return(View(tintuc));
        }
Пример #2
0
        public async Task <IActionResult> Create([Bind("Machuyenmuc,Tenchuyenmuc,Sobaiviet")] Chuyenmuc chuyenmuc)
        {
            if (ModelState.IsValid)
            {
                _context.Add(chuyenmuc);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(chuyenmuc));
        }
Пример #3
0
 public async Task<IActionResult> Create([Bind("Matinnhanh,Noidung,Machuyenmuc")] Tinnhanh tinnhanh,Chuyenmuc chuyenmuc)
 {
     if (ModelState.IsValid)
     {
         var sbv =await _context.Chuyenmuc.SingleOrDefaultAsync(c => c.Machuyenmuc == tinnhanh.Machuyenmuc);
         //sbv.Sobaiviet = sbv.Sobaiviet + 1;
         _context.Add(tinnhanh);
         await _context.SaveChangesAsync();
         return RedirectToAction("Index");
     }
     ViewData["Machuyenmuc"] = new SelectList(_context.Chuyenmuc, "Machuyenmuc", "Tenchuyenmuc", tinnhanh.Machuyenmuc);
     return View(tinnhanh);
 }