public IActionResult Create(Resume resume, IFormFile upload) { if (ModelState.IsValid) { if (upload != null && upload.Length > 0) { //upload işlemi burada yapılır. var fileName = Guid.NewGuid().ToString() + Path.GetExtension(upload.FileName); var path = Path.Combine(_environment.WebRootPath, "Uploads", "Resumes"); var filePath = Path.Combine(path, fileName); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } using (var stream = new FileStream(filePath, FileMode.Create)) { upload.CopyTo(stream); } resume.Photo = fileName; } resumeService.Insert(resume); return(RedirectToAction(nameof(MyResumes), new { id = resume.Id, saved = true })); } ViewData["OccupationId"] = new SelectList(occupationService.GetAll(), "Id", "Name", resume.OccupationId); ViewData["CountryId"] = new SelectList(countryService.GetAll(), "Id", "Name", resume.CountryId); ViewData["CityId"] = new SelectList(cityService.GetAllByCountryId(resume.CountryId), "Id", "Name", resume.CityId); ViewData["CountyId"] = new SelectList(countyService.GetAllByCityId(resume.CityId), "Id", "Name", resume.CountyId); return(View(resume)); }
public async Task <ActionResult> Create(Company company, IFormFile File) { if (ModelState.IsValid) { if (File != null && File.Length > 0) { // upload işlemi yapmak için konum belirle string path = Path.Combine(_environment.WebRootPath, "Uploads", File.FileName); // uploads dizini yoksa oluştur if (!Directory.Exists(Path.Combine(_environment.WebRootPath, "Uploads"))) { Directory.CreateDirectory(Path.Combine(_environment.WebRootPath, "Uploads")); } // belirlenen konuma upload yapılır using (var stream = new FileStream(path, FileMode.Create)) { await File.CopyToAsync(stream); } // dosya adı entity'e atanır company.Logo = File.FileName; } companyService.Insert(company); return(RedirectToAction("Index")); } else { ViewData["CountryId"] = new SelectList(countryService.GetAll(), "Id", "Name", company.CountryId); ViewData["CityId"] = new SelectList(cityService.GetAllByCountryId(company.CountryId), "Id", "Name", company.CityId); ViewData["CountyId"] = new SelectList(countyService.GetAllByCityId(company.CityId), "Id", "Name", company.CountyId); ViewData["SectorId"] = new SelectList(sectorService.GetAll(), "Id", "Name", company.SectorId); return(View(company)); } }