public async Task <ActionResult> EditPasswordAsync(EditAccountViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = await _userManager.GetUserAsync(HttpContext.User);

                var oldAccount = _accountService.VerifyAccount(user.UserName, model.OldPassword);
                if (oldAccount != null)
                {
                    oldAccount.PasswordHash  = PasswordHash.GenerateSHA512String(model.NewPassword);
                    oldAccount.UpdatedUserId = user.UserId;
                    _accountService.Update(oldAccount);
                    return(RedirectToAction("Index", "Home", new { Area = "Admin" }));
                }
                ModelState.AddModelError("", Constants.InvalidOldPassword);
                return(RedirectToAction("Index"));
            }
            ModelState.AddModelError("", Constants.UnknowErrorMessage);
            return(RedirectToAction("Index"));
        }
        public Account VerifyAccount(string username, string password)
        {
            var passwordHash = PasswordHash.GenerateSHA512String(password);

            return(GetAccountLogin(username, passwordHash));
        }
        private void ButtonConfirm_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (TextBoxCity.Text != "" && TextBoxEmail.Text != "" && TextBoxFirstName.Text != "" && TextBoxHouse.Text != "" && TextBoxLogin.Text != "" && TextBoxName.Text != "" &&
                    PasswordBoxPassword.Password != "" && TextBoxPhone.Text != "" && TextBoxAddressCode.Text != "" && TextBoxStreet.Text != "" && ComboBoxType.SelectedIndex > -1)
                {
                    _client.requestStatus = 0;
                    MyMessageBox myMessageBox = new MyMessageBox(_client, 0);
                    myMessageBox.ShowDialog();

                    if (_client.requestStatus == 1)
                    {
                        _client.SendMessage("0011<EOP>" + TextBoxLogin.Text + "<EOP>" + PasswordHash.GenerateSHA512String(PasswordBoxPassword.Password) + "<EOP>" + TextBoxEmail.Text + "<EOP>" + TextBoxFirstName.Text + "<EOP>" + TextBoxName.Text +
                                            "<EOP>" + TextBoxCity.Text + "<EOP>" + TextBoxAddressCode.Text + "<EOP>" + TextBoxStreet.Text + "<EOP>" + TextBoxHouse.Text + "<EOP>" + TextBoxPhone.Text +
                                            "<EOP>" + (ComboBoxType.SelectedIndex + 1).ToString() + "<EOP>" + TextBoxSalary.Text + "<EOP>");
                        _client.requestStatus = 0;
                        int time = DateTime.Now.Second;
                        while (_client.requestStatus == 0)
                        {
                            if (time - DateTime.Now.Second > 60)
                            {
                                myMessageBox = new MyMessageBox(_client, 3);
                                myMessageBox.ShowDialog();
                                return;
                            }
                        }
                        myMessageBox = new MyMessageBox(_client, _client.requestStatus);
                        myMessageBox.ShowDialog();

                        Grid ParentGrid = (Grid)this.Parent;
                        ParentGrid.Children.Add(new UsersControl(_client));
                        ParentGrid.Children.RemoveAt(ParentGrid.Children.Count - 2);
                    }
                    else
                    {
                        return;
                    }
                }
                else
                {
                    MyMessageBox myMessageBox = new MyMessageBox(_client, 2);
                    myMessageBox.ShowDialog();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
        private async void Login(string login, string password)
        {
            _client.SendMessage("0008<EOP>" + login + "<EOP>" + PasswordHash.GenerateSHA512String(password) + "<EOP>");
            string type    = "0";
            bool   succeed = true;

            if (connected)
            {
                await Task.Run(() =>
                {
                    type = _client.ReceiveMessage();
                    switch (type)
                    {
                    case "1":
                        _client.SendMessage("0010<EOP>");
                        _client.ReceiveMessage();
                        _client.SendMessage("0014<EOP>");
                        _client.ReceiveMessage();
                        _client.SendMessage("0020<EOP>");
                        _client.ReceiveMessage();
                        _client.SendMessage("0030<EOP>");
                        _client.ReceiveMessage();
                        _client.SendMessage("0034<EOP>");
                        _client.ReceiveMessage();
                        _client.SendMessage("0037<EOP>");
                        _client.ReceiveMessage();
                        _client.SendMessage("0040<EOP>");
                        _client.ReceiveMessage();
                        _client.SendMessage("0050<EOP>");
                        _client.ReceiveMessage();
                        _client.SendMessage("0060<EOP>");
                        _client.ReceiveMessage();
                        _client.SendMessage("0062<EOP>");
                        _client.ReceiveMessage();
                        _client.SendMessage("0066<EOP>");
                        _client.ReceiveMessage();
                        _client.SendMessage("0070<EOP>");
                        _client.ReceiveMessage();
                        _client.SendMessage("0074<EOP>");
                        _client.ReceiveMessage();
                        _client.SendMessage("0075<EOP>");
                        _client.ReceiveMessage();
                        break;

                    case "2":
                        _client.SendMessage("0020<EOP>");
                        _client.ReceiveMessage();
                        _client.SendMessage("0030<EOP>");
                        _client.ReceiveMessage();
                        _client.SendMessage("0034<EOP>");
                        _client.ReceiveMessage();
                        _client.SendMessage("0037<EOP>");
                        _client.ReceiveMessage();
                        _client.SendMessage("0050<EOP>");
                        _client.ReceiveMessage();
                        _client.SendMessage("0060<EOP>");
                        _client.ReceiveMessage();
                        _client.SendMessage("0062<EOP>");
                        _client.ReceiveMessage();
                        _client.SendMessage("0066<EOP>");
                        _client.ReceiveMessage();
                        break;

                    case "3":
                        _client.SendMessage("0030<EOP>");
                        _client.ReceiveMessage();
                        _client.SendMessage("0034<EOP>");
                        _client.ReceiveMessage();
                        _client.SendMessage("0037<EOP>");
                        _client.ReceiveMessage();
                        _client.SendMessage("0040<EOP>");
                        _client.ReceiveMessage();
                        _client.SendMessage("0070<EOP>");
                        _client.ReceiveMessage();
                        _client.SendMessage("0074<EOP>");
                        _client.ReceiveMessage();
                        _client.SendMessage("0075<EOP>");
                        _client.ReceiveMessage();
                        break;

                    case "4":
                        _client.SendMessage("0030<EOP>");
                        _client.ReceiveMessage();
                        _client.SendMessage("0034<EOP>");
                        _client.ReceiveMessage();
                        _client.SendMessage("0037<EOP>");
                        _client.ReceiveMessage();
                        _client.SendMessage("0040<EOP>");
                        _client.ReceiveMessage();
                        _client.SendMessage("0060<EOP>");
                        _client.ReceiveMessage();
                        _client.SendMessage("0062<EOP>");
                        _client.ReceiveMessage();
                        _client.SendMessage("0066<EOP>");
                        _client.ReceiveMessage();
                        break;

                    default:
                        break;
                    }
                });
            }
            else
            {
                StorageData.IngredientsList.Clear();
                StorageData.MenuItemsCategoriesList.Clear();
                StorageData.MenuItemsIngredientsList.Clear();
                StorageData.MenuItemsList.Clear();
                StorageData.OrdersDetailsList.Clear();
                StorageData.OrdersStatesList.Clear();
                StorageData.OrdersList.Clear();
                StorageData.RecipesList.Clear();
                StorageData.ReservationsDetailsList.Clear();
                StorageData.ReservationsList.Clear();
                StorageData.TablesList.Clear();
                StorageData.UsersList.Clear();
                StorageData.UsersTypesIdList.Clear();
                MyMessageBox myMessageBox = new MyMessageBox(_client, 3);
                myMessageBox.ShowDialog();
                ButtonLogin.IsEnabled = true;
                return;
            }

            if (_client.requestStatus == 3)
            {
                MyMessageBox myMessageBox = new MyMessageBox(_client, 3);
                myMessageBox.ShowDialog();
                ButtonLogin.IsEnabled = true;
                return;
            }
            switch (type)
            {
            case "1":
                new Admin.AdminWindow(_client);
                Close();
                break;

            case "2":
                new Cook.CookWindow(_client);
                Close();
                break;

            case "3":
                new Receptionist.ReceptionistWindow(_client);
                Close();
                break;

            case "4":
                new Waiter.WaiterWindow(_client);
                Close();
                break;

            default:
                MyMessageBox myMessageBox = new MyMessageBox(_client, 5);
                myMessageBox.ShowDialog();
                ButtonLogin.IsEnabled = true;
                break;
            }
        }