Esempio n. 1
0
        public void TestUpdateClient()
        {
            var clientGuid = Guid.NewGuid();
            var client     = new Client
            {
                Guid     = clientGuid,
                Login    = "******",
                Password = "******"
            };

            DbClientWorker.AddClient(client);

            var getClient = DbClientWorker.GetClient(clientGuid);

            Assert.IsNotNull(getClient);

            getClient.Login    = "******";
            getClient.Password = "******";
            DbClientWorker.UpdateClient(getClient);

            var updatedClient = DbClientWorker.GetClient(clientGuid);

            Assert.IsNotNull(getClient);
            Assert.AreEqual(getClient.Login, "nigoLtseTtinU");
            Assert.AreEqual(getClient.Password, "drowssaPtseTtinU");

            DbClientWorker.DeleteClient(clientGuid);
        }
        private void SaveBtn_Click(object sender, RoutedEventArgs e)
        {
            //TODO: Сохранение новой инфы о клиенте

            try
            {
                CheckInputs();

                var uri = new Uri(((BitmapFrame)EditImage.Source).Decoder.ToString());

                var client = new Client
                {
                    Guid           = UserData.User.UserGuid.Value,
                    Login          = LoginTxt.Text,
                    Password       = Password.Password,
                    FirstName      = FirstNameTxt.Text,
                    LastName       = SecondNameTxt.Text,
                    Patronymic     = PatronymicTxt.Text,
                    Birthday       = Burthday.SelectedDate,
                    Sex            = SexCmb.SelectedIndex > -1 ? SexCmb.SelectedValue.ToString() : null,
                    Email          = EmailTxt.Text,
                    Phone          = PhoneTxt.Text,
                    PassportNumber = PassportNumberTxt.Text,
                    PassportSeries = PassportSeriaTxt.Text,
                    BankCard       = BankCard.Text,
                    ImagePath      = @"Users\" + System.IO.Path.GetFileName(uri.AbsolutePath)
                };

                if (DbClientWorker.UpdateClient(client))
                {
                    var imagePath = System.IO.Path.Combine(Settings.AttachedFiles, client.ImagePath);
                    if (!System.IO.File.Exists(imagePath))
                    {
                        System.IO.File.Copy(uri.AbsolutePath, System.IO.Path.Combine(Settings.AttachedFiles, client.ImagePath));
                    }

                    var model = (PersonnelCabinetWindowModel)DataContext;
                    model.Login          = client.Login;
                    model.Password       = client.Password;
                    model.FirstName      = client.FirstName;
                    model.SecondName     = client.LastName;
                    model.Patronymic     = client.Patronymic;
                    model.Burthday       = client.Birthday.ToString();
                    model.Sex            = client.Sex;
                    model.Email          = client.Email;
                    model.Phone          = client.Phone;
                    model.PassportNumber = client.PassportNumber;
                    model.PassportSeria  = client.PassportSeries;
                    model.BankCard       = client.BankCard;
                    model.ImagePath      = imagePath;

                    Close();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }