예제 #1
0
        public async Task <IActionResult> UpdatePassword(int id, [FromForm] Model.Request.ChangePassword model, string redirectUrl)
        {
            if (ModelState.IsValid)
            {
                await crudService.UpdatePassword(id, model);

                TempData["success"] = _localizer.SuccPasswordUpdated;
            }

            return(LocalRedirect(redirectUrl));
        }
예제 #2
0
        public async Task <IActionResult> UpdatePassword(int id, [FromForm] Model.Request.ChangePassword model)
        {
            try
            {
                await CrudService.UpdatePassword(id, model);

                return(Json(new { success = true, message = _localizer.SuccPasswordUpdated }));
            }
            catch (ModelStateException e)
            {
                ModelState.AddModelError(e.Key, _localizer.LocalizedString(e.Message));
            }
            catch (Exception e)
            {
                ModelState.AddModelError("Error", _localizer.ErrUpdatePassword);
            }

            Response.StatusCode = (int)HttpStatusCode.BadRequest;
            return(Json(ModelState.Where(x => x.Value.Errors.Count > 0).ToDictionary(x => x.Key, x => x.Value.Errors.Select(y => y.ErrorMessage))));
        }