private void AddButton_Click(object sender, RoutedEventArgs e)
        {
            bool formatPredicate = CheckIfAllInputsFilled();

            if (formatPredicate)
            {
                //Creating objects to fill with data from user input (and then add them to db)
                Room                choosedRoom = new Room();
                Booking             bookingInfo = new Booking();
                AddToDatabaseResult bookingInfoResults;
                List <Room>         roomsfullList = DatabaseOperations.GetFullTableBaseOnType <Room>().ReturnedData.ConvertToGenericList <Room>();

                try
                {
                    bookingInfo = new Booking()
                    {
                        BookingDate   = DateTime.Now,
                        ReservedTo    = ToDatePicker.SelectedDate ?? DateTime.MaxValue,
                        ReservedFrom  = FromDatePicker.SelectedDate ?? DateTime.MinValue.Date,
                        BookingMethod = (BookingMethods)Enum.Parse(typeof(BookingMethods), BookingMethodsCombobox.Text)
                    };
                }
                catch (InvalidCastException ex)
                {
                    ErrorLogger.AddLog(new ErrorLogger.Error(ex));
                }

                bookingInfoResults = DatabaseOperations.AddDataToHotelDatabase(bookingInfo);

                for (int index = 0; index < roomsfullList.Count; index++)
                {
                    if (roomsfullList[index].RoomNumber.ToString().Equals(roomChooseComboBox.Text.Last().ToString()))
                    {
                        choosedRoom = roomsfullList[index];
                    }
                }

                Guest buildedGuest = new GuestBuilder().SetName(addingNewGuestSubContent.NameTextBox.Text)
                                     .SetSurname(addingNewGuestSubContent.SurnameTextBox.Text)
                                     .SetEmail(addingNewGuestSubContent.EmailTextBox.Text)
                                     .SetTelephoneNumber(addingNewGuestSubContent.MobileNumberTextBox.Text)
                                     .SetAddress(addingNewGuestSubContent.AddressTextBox.Text)
                                     .SetRoom(choosedRoom.RoomNumber)
                                     .SetBooking(bookingInfo.ID)
                                     .Build();

                AddToDatabaseResult buildedGuestResults = DatabaseOperations.AddDataToHotelDatabase(buildedGuest);

                MessageBox.Show((buildedGuestResults.OperationSuccess && bookingInfoResults.OperationSuccess) ?
                                OutputMessages.DataBaseInsertSuccess : OutputMessages.FailedAddedToDatabase);
            }
            else
            {
                MessageBox.Show(OutputMessages.MissingArgumentsMessage);
            }
        }
Пример #2
0
        public RegistrationResult NewUser(string userName, string password, string confirmedPassword, string name, string surname)
        {
            if (!password.Equals(confirmedPassword))
            {
                return(BuildOperationResult(OutputMessages.PasswordNoMatch, false) as RegistrationResult);
            }

            Tuple <bool, string> userValidation = CheckUserValidation(userName, password);

            if (!userValidation.Item1)
            {
                return(BuildOperationResult(userValidation.Item2, false) as RegistrationResult);
            }


            UserSecurity security = new UserSecurity();

            Tuple <string, byte[]> hashingResults = security.HashPasswordSHA256(password);

            string saltValue      = hashingResults.Item1;
            string hashedPassword = String.Join(String.Empty, hashingResults.Item2.ToList().Select(x => Convert.ToChar(x)));

            var localUser = new NewUserBuilder().SetUsername(userName)
                            .SetPassword(hashedPassword)
                            .GetSaltValue(saltValue)
                            .SetName(name)
                            .SetSurname(surname)
                            .Build();

            try
            {
                //TODO check if can take duplicate user or exception because its a key for user
                AddToDatabaseResult result = DatabaseOperations.AddDataToHotelDatabase <User>(localUser);

                return(result.OperationSuccess ? BuildOperationResult(OutputMessages.RegisterSuccessfulMessage, true, obj: localUser)
                       as RegistrationResult
                                               : BuildOperationResult(result.Message, result.OperationSuccess, result.PossibleException, localUser)
                       as RegistrationResult);
            }

            catch (Exception ex)
            {
                Logger.ErrorLogger.AddLog(new Logger.ErrorLogger.Error(ex));
                return(BuildOperationResult(OutputMessages.InternalError, false, ex) as RegistrationResult);
            }
        }
        private void AcceptButton_Click(object sender, RoutedEventArgs e)
        {
            if (UserTypesComboBox.SelectedItem == null)
            {
                MessageBox.Show(HotelManagmentLogic.Configuration.OutputMessages.MissingArgumentsMessage);
                return;
            }
            try
            {
                if (Enum.TryParse <UserType>(UserTypesComboBox.SelectedValue.ToString(), out UserType parsedUserType))
                {
                    AddToDatabaseResult result = UserDatabaseOperations.ChangeUserPermissions(selectedUser, parsedUserType);
                    MessageBox.Show(result.Message);

                    WindowsManagement.GetAdministrationControlInstance().RefreshRegisteredUserList();
                    this.Close();
                }
            }
            catch (Exception ex)
            {
                ErrorLogger.AddLog(new ErrorLogger.Error(ex));
            }
        }