Beispiel #1
0
        public async Task <IActionResult> Edit(int?id, [Bind("BlogID,Tag,Title,Description,Photo")] Blog blog)
        {
            if (id != blog.BlogID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(blog);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!BlogExists(blog.BlogID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(blog));
        }
Beispiel #2
0
        public async Task <IActionResult> Edit(int?id, [Bind("BlogID,Tag,Title,Description,Photo")] Blog blog, IFormFile upload)
        {
            if (id != blog.BlogID)
            {
                return(NotFound());
            }


            //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 && blog.Photo == null)//eger resim yüklenmisse bir daha sectirmiyor
            {
                ModelState.AddModelError("Photo", "Resim yüklemeniz gerekmektedir");
            }


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


                    _context.Update(blog);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!BlogExists(blog.BlogID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(blog));
        }