public IActionResult Create(HomeCreateViewModel model) { if (ModelState.IsValid) { var flower = new Flower() { Name = model.Name, TypeF = model.TypeF }; var fileName = string.Empty; if (model.Avatar != null) { string uploadFolder = Path.Combine(webHostEnvironment.WebRootPath, "images"); fileName = $"{Guid.NewGuid()}_{model.Avatar.FileName}"; var filePath = Path.Combine(uploadFolder, fileName); using (var fs = new FileStream(filePath, FileMode.Create)) { model.Avatar.CopyTo(fs); } } flower.AvatarPath = fileName; var newEmp = flowerRepository.Create(flower); return(RedirectToAction("Details", new { id = newEmp.Id })); } return(View()); }
public IActionResult Create(Flower flower) { if (!ModelState.IsValid) { return(View(flower)); } _flowerRepository.Create(flower); return(RedirectToAction("List")); }