public async Task <ActionResult> Edit(int id) { UserWorkModel model = new UserWorkModel(); if (MyUser.UserId == id || User.IsInRole(RoleSuperAdmin)) { Task task = GetLanguages(model); var response = await _crudService.Get <UserModel>(id, Token, UserService.UserEntity); if (response.Success) { model.Id = response.Value.Id; model.Firstname = response.Value.Firstname; model.Lastname = response.Value.Lastname; model.Email = response.Value.Email; model.UseLdaplogin = response.Value.UseLdaplogin; model.LdapUrl = response.Value.LdapUrl; model.LanguageId = response.Value.LanguageId.ToString(); } else { AddMessageToModel(model, response.Message); } await Task.WhenAll(task); } else { model.CanView = false; AddMessageToModel(model, "You cannot edit this user!"); } return(View(model)); }
public async Task <IActionResult> Edit(int id, UserWorkModel model) { Task select = GetLanguages(model); if (ModelState.IsValid) { Task userTask = _crudService.Edit(id, model, Token, UserService.UserEntity).ContinueWith(async r => { var result = r.Result; if (result.Success) { var user = MyUser; user.Firstname = model.Firstname; user.Lastname = model.Lastname; user.Email = model.Email; await UserLogin(user, Token); } if (!model.UseLdaplogin) { model.LdapUrl = null; } AddMessageToModel(model, result.Message, !result.Success); }); Task passwordTask = Task.CompletedTask; if (!string.IsNullOrEmpty(model.OldPassword) && !string.IsNullOrEmpty(model.Password) && !string.IsNullOrEmpty(model.ConfirmPassword)) { if (model.Password == model.ConfirmPassword) { passwordTask = _crudService.PartialEdit(id, CreatePatchList(CreatePatchModel("password", $"{model.OldPassword};;;{model.Password}")), Token, UserService.UserEntity).ContinueWith(r => { var passwordResult = r.Result; if (passwordResult.Success) { AddMessageToModel(model, "Password was changed!", false); } else { AddMessageToModel(model, passwordResult.Message); } }); } else { AddMessageToModel(model, "Password and cofirmed password are not equal! Password wasn't changed."); } } await Task.WhenAll(userTask, passwordTask); } else { AddModelStateErrors(model); } await Task.WhenAll(select); return(View(model)); }