Beispiel #1
0
        public async Task <IActionResult> AddOrEdit(Blog entity, IFormFile formFile)
        {
            if (ModelState.IsValid)
            {
                if (formFile != null)
                {
                    var path = Path.Combine("wwwroot\\img", formFile.FileName);
                    using (var stream = new FileStream(path, FileMode.Create))
                    {
                        await formFile.CopyToAsync(stream);
                    }

                    entity.Image = formFile.FileName;
                }

                _blogRepository.AddOrEditCategory(entity);
                TempData["message"] = $"{entity.Title} guncellendi";
                return(RedirectToAction("List"));
            }
            ViewBag.Categories = new SelectList(_categoryRepository.GetAll(), "CategoryId", "Name");
            return(View(entity));
        }