public async Task <Actor> EditActorAsync(int id, string actorName, IFormFile img) { var actor = await _db.Actors.FirstOrDefaultAsync(x => x.Id == id); if (actor == null) { return(null); } _db.Attach(actor); actor.ActorName = actorName; if (img != null && img.FileName.ToLower() != actor.ActorPicture.ToLower()) { // Real path // var filePath = Path.Combine(_host.WebRootPath + "/images/actors", img.FileName); var filePath = Path.Combine(@"E:\Lab\AngularTutorial\CinamaMovies\src\assets\images\actors", img.FileName); using (FileStream fileStream = new FileStream(filePath, FileMode.Create)) { await img.CopyToAsync(fileStream); } actor.ActorPicture = img.FileName; _db.Entry(actor).Property(x => x.ActorPicture).IsModified = true; } _db.Entry(actor).Property(x => x.ActorName).IsModified = true; await _db.SaveChangesAsync(); return(actor); }
public async Task <ActionResult> ChangePassword(string pass, string passConfirm) { if (pass == null || passConfirm == null) { return(RedirectToAction(nameof(UserControl))); } string password = AppHash.HashPassword(pass); string id = User.FindFirst(ClaimTypes.NameIdentifier)?.Value; if (!string.IsNullOrEmpty(id)) { if (pass == passConfirm) { var user = await db.AppUsers.FirstOrDefaultAsync(a => a.id == id); if (user != null) { user.Password = password; user.PasswordConfirm = password; db.Attach(user); db.Entry(user).Property(x => x.Password).IsModified = true; db.Entry(user).Property(x => x.PasswordConfirm).IsModified = true; await db.SaveChangesAsync(); return(RedirectToAction(nameof(UserControl))); } } else { ViewBag.msg = "كلمتا المرور غير متطابقتين!!"; } } else { return(RedirectToAction("Index", "Home")); } return(View()); }