public IActionResult Gallery(Gallery gallery) { if (ModelState.IsValid) { string uniqueFileName = null; uniqueFileName = MethodExtraction(gallery, uniqueFileName); Galleries galleris = new Galleries { Id = gallery.Id, Name = gallery.Name, Photo = uniqueFileName, }; _mercyContext.Add(galleris); _mercyContext.SaveChanges(); return(RedirectToAction("Index")); } return(View()); }
public async Task <IActionResult> Create([Bind("Id,Name,Image")] Galleries galleries) { if (ModelState.IsValid) { string webroothpath = _webHostEnvironment.WebRootPath; string fileName = Path.GetFileNameWithoutExtension(galleries.Image.FileName); string extension = Path.GetExtension(galleries.Image.FileName); string path = Path.Combine(webroothpath + "/images/", fileName); galleries.Photo = fileName + fileName + extension; using (var filestream = new FileStream(path, FileMode.Create)) { await galleries.Image.CopyToAsync(filestream); } _context.Add(galleries); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(galleries)); }