Beispiel #1
0
        private void AddUserToDataBase(string userName, int score)
        {
            var user = new User()
            {
                Name  = userName,
                Score = score,
                Level = Singleton.Instance.LevelType
            };

            userDbRepository.Insert(user);
        }
        private void AddUserToDatabase()
        {
            try
            {
                #region CheckPropertis
                if (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.Insert(user);

                ClearFields();

                Status           = AddMessage;
                ForegroundStatus = "Green";
            }
            catch
            {
                ClearFields();
                ForegroundStatus = "Red";
                Status           = FatalError;
            }
        }