public ActionResult ChangePassword(IncidereAccountChangePasswordModel model, string id)
        {
            var resultSuccess = true;
            var resultStatus  = "OK";

            if (string.IsNullOrEmpty(id))
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            if (!ValidatePasswords(model.NewPassword, model.ConfirmPassword))
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            var localUser = m_incidereUserService.GetUser(id);

            if (string.IsNullOrEmpty(localUser.FirebaseKey))
            {
                return(new HttpStatusCodeResult(HttpStatusCode.NotFound));
            }

            if (!VerifyPassword(localUser.Password, model.OldPassword))
            {
                return(new HttpStatusCodeResult(HttpStatusCode.Forbidden));
            }

            localUser.Password = CreateHashedPassword(model.ConfirmPassword);
            try
            {
                var result = m_incidereUserService.EditUser(localUser, id);
            }
            catch (Exception ex)
            {
                resultSuccess       = false;
                resultStatus        = $"Error: {ex.Message}";
                Response.StatusCode = (int)HttpStatusCode.InternalServerError;
                return(Json(new { success = resultSuccess, status = resultStatus, id = id }));
            }

            Response.StatusCode = (int)HttpStatusCode.OK;
            return(Json(new { success = resultSuccess, status = resultStatus, id = id }));
        }
        public ActionResult Edit([Bind(Include = "Username,Password,Email,FirstName,LastName,DateOfBirth,Location,Roles")]
                                 LocalUser localUser, string id)
        {
            if (string.IsNullOrEmpty(id))
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            var localUserFromSource = m_incidereUserService.GetUser(id);

            if (string.IsNullOrEmpty(localUserFromSource.FirebaseKey))
            {
                return(HttpNotFound());
            }

            try
            {
                if (ModelState.IsValid)
                {
                    localUser.Roles.RemoveAll(role => string.IsNullOrEmpty(role));
                    localUser.ReferenceNo   = localUserFromSource.ReferenceNo;
                    localUser.ExternalUsers = localUserFromSource.ExternalUsers;

                    var result = m_incidereUserService.EditUser(localUser, id);
                    if (!string.IsNullOrEmpty(result.FirebaseKey))
                    {
                        return(RedirectToAction("Index"));
                    }
                }
            }
            catch (DataException)
            {
                ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator.");
            }

            return(View(localUser));
        }