public ActionResult KullaniciDuzenle(KullaniciDuzenleViewModel model) { if (!ModelState.IsValid) { return(RedirectToAction("Index")); } var userManager = MembershipTools.NewUserManager(); var seciliUser = userManager.Users.Where(x => x.Id == model.ID).FirstOrDefault(); // var checkUser = userManager.FindByName(model.Username); //if (checkUser!=null) //{ // ModelState.AddModelError(string.Empty, "Bu kullanıcı adı daha önceden kayıt edilmiş!"); // return RedirectToAction("KullaniciDuzenle",new { id=model.ID}); //} var eskirol = MembershipTools.NewRoleManager().FindById(seciliUser.Roles.FirstOrDefault().RoleId).Name; var yenirol = MembershipTools.NewRoleManager().FindById(model.RoleID).Name; userManager.RemoveFromRole(model.ID, eskirol); //eskirol silindi userManager.AddToRole(model.ID, yenirol); // rol eklendi //if (model.Password!=null) //{ // userManager.RemovePassword(model.ID); // userManager.AddPassword(model.ID, model.Password); //} seciliUser.Name = model.Name; seciliUser.SurName = model.Surname; seciliUser.UserName = model.Username; seciliUser.PhoneNumber = model.Telefon; seciliUser.FirmaAdi = model.FirmaAdi; seciliUser.Email = model.Email; userManager.Update(seciliUser); return(RedirectToAction("KullaniciListele", "Admin")); }
public ActionResult KullaniciDuzenle(string id) { ViewBag.roller = RoleSelectList(); var userManager = MembershipTools.NewUserManager(); var seciliUser = userManager.Users.FirstOrDefault(x => x.Id == id); KullaniciDuzenleViewModel gorevli = new KullaniciDuzenleViewModel() { Email = seciliUser.Email, Name = seciliUser.Name, Surname = seciliUser.SurName, RoleID = seciliUser.Roles.FirstOrDefault(x => x.UserId == seciliUser.Id).RoleId, Username = seciliUser.UserName, FirmaAdi = seciliUser.FirmaAdi, Telefon = seciliUser.PhoneNumber, ID = seciliUser.Id }; return(View(gorevli)); }