Exemplo n.º 1
0
        public async Task <IActionResult> Create([Bind("BlogID,Tag,Title,Description,Photo")] Blog blog, IFormFile upload)
        {
            //dosya uzantısı ıcın gecerliik denetimi
            if (upload != null && !IsExtensionValid(upload))
            {
                ModelState.AddModelError("Photo", "Dosya uzantısı jpg, jpeg ,gif , png olmalıdır.");
            }
            else if (upload == null)
            {
                ModelState.AddModelError("Photo", "Resim yüklemeniz gerekmektedir");
            }



            if (ModelState.IsValid)
            {
                //dosya yuklemesi
                if (upload != null && upload.Length > 0 && IsExtensionValid(upload))
                {
                    blog.Photo = await UploadFileAsync(upload);
                }



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

                return(RedirectToAction(nameof(Index)));
            }
            return(View(blog));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Create([Bind("BlogID,Tag,Title,Description,Photo")] Blog blog)
        {
            if (ModelState.IsValid)
            {
                _context.Add(blog);
                await _context.SaveChangesAsync();

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