public async Task <IActionResult> CreateProfile(AppUserCV model, IFormFile image, AppUser appUser) { try { string path; if (image == null) { path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot\\images", "noimage.jpg"); model.ImagePath = "noimage.jpg"; } else { path = Path.GetFullPath("wwwroot\\images\\" + image.FileName); using (var stream = new FileStream(path, FileMode.Create)) { await image.CopyToAsync(stream); } model.ImagePath = image.FileName; } var user = await userManager.FindByIdAsync(appUser.Id.ToString()); var cv = appUserCVService.GetById(model.ID); model.AppUserId = user.Id; model.AppUser = user; appUserCVService.Add(model); return(RedirectToAction("Index")); } catch (Exception ex) { return(View(model)); } }
public async Task <IActionResult> EditProfile(Guid id) { AppUser user = await userManager.FindByIdAsync(id.ToString()); AppUserCV appUserCV = appUserCVService.GetById(user.Id); return(View(appUserCV)); }
public async Task <IActionResult> EditProfile(AppUserCV model, IFormFile image) { try { string path; if (image == null) { path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot\\images", "noimage.jpg"); model.ImagePath = "noimage.jpg"; } else { path = Path.GetFullPath("wwwroot\\images\\" + image.FileName); using (var stream = new FileStream(path, FileMode.Create)) { await image.CopyToAsync(stream); } model.ImagePath = image.FileName; } AppUser user = userManager.FindByNameAsync(User.Identity.Name).Result; var appUser = await userManager.FindByIdAsync(user.Id.ToString()); var cv = appUserCVService.GetById(model.ID); cv.Department = model.Department; cv.ImagePath = model.ImagePath; cv.PhoneNumber = model.PhoneNumber; appUserCVService.Update(cv); return(RedirectToAction("Index")); } catch (Exception ex) { return(View()); } }