public async Task <ActionResult> Edit(UserMyRoleViewModel model) { var user = await _userManager.FindByIdAsync(model.Id); if (user == null) { return(NotFound()); } if (model.MyRoleId == "-1") { ViewBag.Message = "Please select an author from the list!"; return(View(GetAllProgrammes())); } user.Email = model.Email; user.PhoneNumber = model.PhoneNumber; user.UserName = model.UserName; user.Fname = model.Fname; user.Lname = model.Lname; user.Programmes.ProgrammeCode = model.ProgrammeCode; user.Programmes.ProgrammeName = model.ProgrammeName; //user.Programmes.ProgrammeCode = model.Programmes.ElementAtOrDefault(0).ProgrammeCode; //user.Programmes.ProgrammeName = model.Programmes.ElementAtOrDefault(0).ProgrammeName; await _userManager.UpdateAsync(user); return(Redirect("/user")); // return View(GetAllProgrammes()); }
UserMyRoleViewModel GetAllProgrammes() { var vmodel = new UserMyRoleViewModel { Programmes = ProgrammeSelectList() }; return(vmodel); }
public async Task <ActionResult> Edit(string id) { var user = await _userManager.FindByNameAsync(id); if (user == null) { return(NotFound()); } var programmesId = user.Programmes == null ? user.Programmes.ProgrammeCode = "-1" : user.Programmes.ProgrammeCode; var viewmodel = new UserMyRoleViewModel { Id = user.Id.ToString(), Email = user.Email, NormalizedEmail = user.NormalizedEmail, NormalizedUserName = user.NormalizedUserName, PasswordHash = user.PasswordHash, PhoneNumber = user.PhoneNumber, UserName = user.UserName, Fname = user.Fname, Lname = user.Lname, ProgrammeCode = programmesId, ProgrammeName = user.Programmes.ProgrammeName, //Programmes = _programmeRepository.List().ToList(), // makes error Programmes = ProgrammeSelectList(), MyRoles = MyRoleSelectList() }; return(View(viewmodel)); }