public async Task <IActionResult> Create([Bind("Id,AntrenmanAd,Sure,EtkiBolgesi,KapakFoto,Video,Tarih,BransId,AntrenorId")] Antrenman antrenman) { if (ModelState.IsValid) { //****** string webRootPath = _hostingEnvironment.WebRootPath; var files = HttpContext.Request.Form.Files; string fileName = Guid.NewGuid().ToString(); var uploads = Path.Combine(webRootPath, @"images\antrenman"); var extension = Path.GetExtension(files[0].FileName); using (var fileStream = new FileStream(Path.Combine(uploads, fileName + extension), FileMode.Create)) { files[0].CopyTo(fileStream); } antrenman.KapakFoto = @"\images\antrenman\" + fileName + extension; //******** _context.Add(antrenman); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["AntrenorId"] = new SelectList(_context.Antrenor, "Id", "AntrenorAd", antrenman.AntrenorId); ViewData["BransId"] = new SelectList(_context.Brans, "Id", "BransAd", antrenman.BransId); return(View(antrenman)); }
public async Task <IActionResult> Edit(int id, [Bind("Id,AntrenmanAd,Sure,EtkiBolgesi,KapakFoto,Video,Tarih,BransId,AntrenorId")] Antrenman antrenman) { if (id != antrenman.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(antrenman); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!AntrenmanExists(antrenman.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["AntrenorId"] = new SelectList(_context.Antrenor, "Id", "AntrenorAd", antrenman.AntrenorId); ViewData["BransId"] = new SelectList(_context.Brans, "Id", "BransAd", antrenman.BransId); return(View(antrenman)); }