public async Task <IActionResult> Create([Bind("Id,Mobile,Email,Nationality,Residence,ImageFile")] Personal_Info_Ar personal_Info_Ar) { if (ModelState.IsValid) { //save image to wwwroot/Images/MyProjectsEn string wwwRootPath = _hostEnvironment.WebRootPath; string fileName = Path.GetFileNameWithoutExtension(personal_Info_Ar.ImageFile.FileName); string extension = Path.GetExtension(personal_Info_Ar.ImageFile.FileName); fileName = fileName + DateTime.Now.ToString("yymmssff") + extension; personal_Info_Ar.ImageName = fileName; string path = Path.Combine(wwwRootPath + "/Images/Personal_Info_Ar/", fileName); using (var fileStream = new FileStream(path, FileMode.Create)) { await personal_Info_Ar.ImageFile.CopyToAsync(fileStream); } //insert record _context.Add(personal_Info_Ar); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(personal_Info_Ar)); }
public async Task <IActionResult> Edit(int?id, Personal_Info_Ar personal_Info_Ar, IFormFile file) { if (id == null) { return(NotFound()); } Personal_Info_Ar personal_Info_Ar2 = await _context.Personal_Info_Ar.Where(x => x.Id == id).FirstOrDefaultAsync(); if (personal_Info_Ar2 == null) { return(NotFound()); } if (file != null || file.Length != 0) { string filename = System.Guid.NewGuid().ToString() + ".jpg"; var path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "Images/Personal_Info_Ar", filename); using (var stream = new FileStream(path, FileMode.Create)) { await file.CopyToAsync(stream); } personal_Info_Ar2.ImageName = filename; } personal_Info_Ar2.Mobile = personal_Info_Ar.Mobile; personal_Info_Ar2.Email = personal_Info_Ar.Email; personal_Info_Ar2.Nationality = personal_Info_Ar.Nationality; personal_Info_Ar2.Residence = personal_Info_Ar.Residence; await _context.SaveChangesAsync(); return(RedirectToAction("Index")); }
public async Task <IActionResult> Edit(int?id) { if (id == null) { return(NotFound()); } Personal_Info_Ar personal_Info_Ar2 = await _context.Personal_Info_Ar.Where(x => x.Id == id).FirstOrDefaultAsync(); if (personal_Info_Ar2 == null) { return(NotFound()); } return(View(personal_Info_Ar2)); }