Пример #1
0
        /// <summary>
        ///     Call this method to save the last completed test to the database using a
        ///     unique test id.
        /// </summary>
        /// <param name="testId"></param>
        /// <returns></returns>
        public string PersistTestData(string testId)
        {
            try
            {
                /*
                 * The number has been validated, now we can use it.  Don't worry about it being
                 * null. If it is I want an exception to be thrown so there are clues to the user
                 * as to why the test was not saved to the database.
                 */
                _testToSave.TestId = testId;

                // passsed verification, so save to db.
                var recordsSaved = TorqueTestDb.SaveToDatabase(_testToSave);

                if (recordsSaved > 0)
                {
                    // add to completed tests, the view model will grab it next time it updates.
                    CompletedTests.Add(_testToSave);

                    // there is no longer a test that needs to be saved, so set to null.
                    _testToSave = null;

                    return(Messages.DatabaseSaveSuccessful());
                }
                return(Messages.DatabaseSaveUnsuccessful());
            }
            catch (Exception ex)
            {
                Debug.WriteLine(Messages.GeneralExceptionMessage(ex, "SaveTestToDatabase"));
                return(ex.Message);
            }
        }
Пример #2
0
        /// <summary>
        ///     Verifies that the test id has not already been used, is not null,
        ///     and is not an empty value.  If the number is verified, this call
        ///     will also save the _testToSave, and indicate that in the response
        ///     to the caller.
        /// </summary>
        /// <param name="testId">
        ///     The testId the user is trying to assign to the test that just completed.
        /// </param>
        /// <returns>
        ///     If the testId is null, whitespace, or a duplicate testId, an error
        ///     will be returned to the user.  If no error is detected, null will be
        ///     returned
        /// </returns>
        public static string VerifyTestId(string testId)
        {
            try
            {
                // verification of number provided

                if (string.IsNullOrWhiteSpace(testId))
                {
                    return(Messages.BlankTorqueTestId());
                }
                if (TorqueTestDb.InvalidTestId(testId))
                {
                    return(Messages.DuplicateTestId(testId));
                }
                return(null);
            }
            catch (Exception)
            {
                throw;
            }
        }