Пример #1
0
 private void DeleteUserInDrafts()
 {
     if (selectedValue != null)
     {
         userDbRepository.DeleteUserInDrafts(SelectedValue.Nip);
     }
     OnResume();
 }
Пример #2
0
        private void SaveChanges()
        {
            try
            {
                #region CheckPropertis
                if (Nip != ParentNip && userDbRepository.CheckReproducibility(Nip))
                {
                    Status           = NipReproducibility;
                    ForegroundStatus = "Red";
                    return;
                }
                else if (NameCompany == string.Empty)
                {
                    Status           = NameCompanyErrorMessage;
                    ForegroundStatus = "Red";
                    return;
                }
                else if (FirstName == string.Empty)
                {
                    Status           = FirstNameErrorMessage;
                    ForegroundStatus = "Red";
                    return;
                }
                else if (LastName == string.Empty)
                {
                    Status           = LastNameErrorMessage;
                    ForegroundStatus = "Red";
                    return;
                }
                else if (Type == string.Empty)
                {
                    Status           = TypeErrorMessage;
                    ForegroundStatus = "Red";
                    return;
                }
                else if (Nip == string.Empty)
                {
                    Status           = NipErrorMessage;
                    ForegroundStatus = "Red";
                    return;
                }
                else if (!Strings.IsDigit(Nip))
                {
                    Status           = NipSyntaxError;
                    ForegroundStatus = "Red";
                    return;
                }
                else if (Nip.Length < 10)
                {
                    Status           = NipLengthErrorMessage;
                    ForegroundStatus = "IndianRed";
                    return;
                }
                else if (Regon != string.Empty && !Strings.IsDigit(Regon))
                {
                    Status           = RegonSyntaxError;
                    ForegroundStatus = "Red";
                    return;
                }
                else if (Regon != string.Empty && Regon.Length < 9)
                {
                    Status           = RegonLengthErrorMessage;
                    ForegroundStatus = "IndianRed";
                    return;
                }
                else if (Pesel != string.Empty && !Strings.IsDigit(Pesel))
                {
                    Status           = PeselSyntaxError;
                    ForegroundStatus = "Red";
                    return;
                }
                else if (Pesel != string.Empty && Pesel.Length < 11)
                {
                    Status           = PeselLengthErrorMessage;
                    ForegroundStatus = "IndianRed";
                    return;
                }
                else if (PostalCode == string.Empty)
                {
                    Status           = PostCodeErrorMessage;
                    ForegroundStatus = "Red";
                    return;
                }
                else if (City == string.Empty)
                {
                    Status           = CityErrorMessage;
                    ForegroundStatus = "Red";
                    return;
                }
                else if (Address == string.Empty)
                {
                    Status           = AddressErrorMessage;
                    ForegroundStatus = "Red";
                    return;
                }
                else if (Email != string.Empty && !Email.Contains("@"))
                {
                    Status           = EmailSyntaxError;
                    ForegroundStatus = "Red";
                    return;
                }
                #endregion

                User user = new User()
                {
                    NameCompany = NameCompany,
                    FirstName   = FirstName,
                    LastName    = LastName,
                    Type        = Type,
                    Nip         = Nip,
                    Regon       = Regon,
                    Pesel       = Pesel,
                    PostalCode  = PostalCode,
                    City        = City,
                    Address     = Address,
                    State       = State,
                    Country     = Country,
                    Email       = Email,
                    PhoneNumber = PhoneNumber,
                    WhereIsIt   = "Database",
                };

                userDbRepository.DeleteUserInDrafts(ParentNip);
                userDbRepository.Insert(user);

                if (Nip != ParentNip)
                {
                    documentDbRepository.RenameNipInDocuments(ParentNip, Nip);
                }

                ClearFields();

                Status           = SaveChangesMessage;
                ForegroundStatus = "Green";

                IsEnabledAllFields = false;
            }
            catch
            {
                ForegroundStatus = "Red";
                Status           = FatalError;
            }
        }