private void saveActivity()
        {
            bool valid = validateEntry();

            if (!valid)
            {
                return;
            }

            //Need to create the service sheet / day entities and save
            ServiceSheetViewModel serviceSheetCreated = new ServiceSheetViewModel(SelectedUser, SelectedActivity, StartDate, EndDate);

            //Now save
            serviceSheetCreated.SaveToModel();
            bool saveSuccessful = DbServiceSheet.saveSheetsAndDays(serviceSheetCreated);

            if (!saveSuccessful)
            {
                MessageBox.Show("Error saving to database.  Need to show error message!");
                return;
            }
            else
            {
                MessageBox.Show("Activity added to database");
            }
        }
        //public static oldServiceSubmissionModel createSubmissionForXml(XElement submissionXml)
        //RT  - 29/11/16 - Rewriting to use the VM
        public static ServiceSheetViewModel createSubmissionForXml(XElement submissionXml)
        {
            //ServiceSheetViewModel retval = new ServiceSheetViewModel();
            //ServiceSheet serviceSheetReturn = new ServiceSheet();
            int submissionNumberEntered = Int32.Parse(submissionXml.Element(SUBMISSION_NUMBER).Value);
            //RT 11/8/16 - Adding in the response id
            string canvasResponseIdEntered = submissionXml.Element(RESPONSE_ID).Value;
            //Adding response date time
            string   responseDateStr   = submissionXml.Element(RESPONSE_DATE_TIME).Value;
            DateTime dtResponseEntered = Convert.ToDateTime(responseDateStr);
            //Adding device date
            string   deviceDateStr   = submissionXml.Element(DEVICE_DATE_TIME).Value;
            DateTime dtDeviceEntered = Convert.ToDateTime(deviceDateStr);
            //Submission version is in the form element
            XElement formDetailsXml = submissionXml.Element(FORM);
            //RT 23/1/17 - Adding app and form names
            //The app name isn't contained in the XML, but won't change.
            string submissionAppName            = "Service Sheet";
            string submissionFormName           = formDetailsXml.Element(SUBMISSION_FORM_NAME).Value;
            int    submissionFormVersionEntered = Int32.Parse(formDetailsXml.Element(SUBMISSION_VERSION).Value);
            string usernameEntered      = submissionXml.Element(USERNAME).Value;
            string userFirstNameEntered = submissionXml.Element(FIRST_NAME).Value;
            string userSurnameEntered   = submissionXml.Element(SURNAME).Value;

            string   customerEntered         = "";
            string   addressLine1Entered     = "";
            string   addressLine2Entered     = "";
            string   townCityEntered         = "";
            string   postcodeEntered         = "";
            string   customerContactEntered  = "";
            string   customerPhoneNoEntered  = "";
            string   machineMakeModelEntered = "";
            string   machineSerialEntered    = "";
            string   cncControlEntered       = "";
            string   jobStartStr             = "";
            DateTime dtJobStartEntered       = new DateTime();
            string   customerOrderNoEntered  = "";
            string   mttJobNumberEntered     = "";
            string   jobDescriptionEntered   = "";
            double   jobTotalTimeOnsiteEntered;
            double   jobTotalTravelTimeEntered;
            int      mileageEntered;
            int      totalDaEntered;
            int      totalOaEntered;
            int      totalBpEntered;
            string   jobStatusEntered        = "";
            string   finalJobReportEntered   = "";
            string   additionalFaultsEntered = "";
            bool     quoteRequiredEntered;
            string   followUpPartsRequiredEntered = "";
            string   image1UrlEntered             = "";
            string   image2UrlEntered             = "";
            string   image3UrlEntered             = "";
            string   image4UrlEntered             = "";
            string   image5UrlEntered             = "";
            string   customerSignatureUrlEntered  = "";
            string   customerNameEntered          = "";
            DateTime dtSignedEntered;
            string   mttEngSignatureUrlEntered = "";
            List <ServiceDayViewModel> dayVMs  = null;

            XElement sectionsXml = submissionXml.Element(SECTIONS);

            // Loop through the sections
            foreach (XElement sectionXml in sectionsXml.Elements())
            {
                string sectionName = sectionXml.Element(SECTION_NAME).Value;
                if (sectionName.Equals(JOB_DETAILS))
                {
                    XElement screensXml   = sectionXml.Element(SCREENS);
                    XElement screenXml    = screensXml.Element(SCREEN);
                    XElement responsesXml = screenXml.Element(RESPONSES);
                    //Parse the job details

                    customerEntered         = xmlResult(CUSTOMER, responsesXml);
                    addressLine1Entered     = xmlResult(ADDRESS_1, responsesXml);
                    addressLine2Entered     = xmlResult(ADDRESS_2, responsesXml);
                    townCityEntered         = xmlResult(TOWN_CITY, responsesXml);
                    postcodeEntered         = xmlResult(POSTCODE, responsesXml);
                    customerContactEntered  = xmlResult(CUSTOMER_CONTACT, responsesXml);
                    customerPhoneNoEntered  = xmlResult(CUSTOMER_PHONE, responsesXml);
                    machineMakeModelEntered = xmlResult(MACHINE_MAKE_MODEL, responsesXml);
                    machineSerialEntered    = xmlResult(SERIAL_NUMBER, responsesXml);

                    cncControlEntered      = xmlResult(MACHINE_CONTROL, responsesXml);
                    jobStartStr            = xmlResult(JOB_START_DATE, responsesXml);
                    dtJobStartEntered      = Convert.ToDateTime(jobStartStr);
                    customerOrderNoEntered = xmlResult(CUSTOMER_ORDER, responsesXml);
                    mttJobNumberEntered    = xmlResult(MTT_JOB_NO, responsesXml);
                    jobDescriptionEntered  = xmlResult(JOB_DESC, responsesXml);
                }
                else if (sectionName.Equals(TIME_SHEET))
                {
                    XElement screensXml        = sectionXml.Element(SCREENS);
                    XElement screenXml         = screensXml.Element(SCREEN);
                    XElement responseGroupsXml = screenXml.Element(RESPONSE_GROUPS);
                    //retval.ServiceTimesheets = ServiceDay.createDays(responseGroupsXml);
                    dayVMs = createDays(responseGroupsXml);
                }
                else if (sectionName.Equals(JOB_SIGNOFF))
                {
                    XElement screensXml   = sectionXml.Element(SCREENS);
                    XElement screenXml    = screensXml.Element(SCREEN);
                    XElement responsesXml = screenXml.Element(RESPONSES);

                    jobTotalTimeOnsiteEntered = Convert.ToDouble(xmlResult(JOB_TOTAL_TIME_ONSITE, responsesXml));
                    jobTotalTravelTimeEntered = Convert.ToDouble(xmlResult(TOTAL_TRAVEL_TIME, responsesXml));

                    //RT 13/10/16 - Mileage, daily/overnight and BP are int, although canvas returns a string like a double.  There will never be a decimal point in them
                    double mileageDouble = Convert.ToDouble(xmlResult(TOTAL_MILEAGE, responsesXml));
                    mileageEntered = (int)mileageDouble;
                    double totalDaDouble = Convert.ToDouble(xmlResult(TOTAL_DAILY_ALLOWANCES, responsesXml));
                    totalDaEntered = (int)totalDaDouble;
                    double totalOaDouble = Convert.ToDouble(xmlResult(TOTAL_OVERNIGHT_ALLOWANCES, responsesXml));
                    totalOaEntered = (int)totalOaDouble;
                    double totalBpDouble = Convert.ToDouble(xmlResult(TOTAL_BARRIER_PAYMENTS, responsesXml));
                    totalBpEntered               = (int)totalBpDouble;
                    jobStatusEntered             = xmlResult(JOB_STATUS, responsesXml);
                    finalJobReportEntered        = xmlResult(FINAL_JOB_REPORT, responsesXml);
                    additionalFaultsEntered      = xmlResult(ADDITIONAL_FAULTS_FOUND, responsesXml);
                    quoteRequiredEntered         = Convert.ToBoolean(xmlResult(QUOTE_REQUIRED, responsesXml));
                    followUpPartsRequiredEntered = xmlResult(FOLLOWUP_PARTS, responsesXml);
                    image1UrlEntered             = xmlResult(IMAGE_1_URL, responsesXml);
                    image2UrlEntered             = xmlResult(IMAGE_2_URL, responsesXml);
                    image3UrlEntered             = xmlResult(IMAGE_3_URL, responsesXml);
                    image4UrlEntered             = xmlResult(IMAGE_4_URL, responsesXml);
                    image5UrlEntered             = xmlResult(IMAGE_5_URL, responsesXml);
                    customerSignatureUrlEntered  = xmlResult(CUSTOMER_SIGNATURE, responsesXml);
                    customerNameEntered          = xmlResult(CUSTOMER_NAME, responsesXml);
                    dtSignedEntered              = Convert.ToDateTime(xmlResult(DATE_SIGNED, responsesXml));
                    mttEngSignatureUrlEntered    = xmlResult(MTT_ENG_SIGNATURE, responsesXml);

                    //Now we create the Service Sheet VM
                    ServiceSheetViewModel retval = new ServiceSheetViewModel(submissionNumberEntered, submissionAppName, userFirstNameEntered, userSurnameEntered, canvasResponseIdEntered, dtResponseEntered,
                                                                             dtDeviceEntered, submissionFormName, submissionFormVersionEntered, customerEntered, addressLine1Entered, addressLine2Entered, townCityEntered, postcodeEntered, customerContactEntered,
                                                                             customerPhoneNoEntered, machineMakeModelEntered, machineSerialEntered, cncControlEntered, dtJobStartEntered, customerOrderNoEntered, mttJobNumberEntered, jobDescriptionEntered,
                                                                             jobTotalTimeOnsiteEntered, jobTotalTravelTimeEntered, mileageEntered, totalDaEntered, totalOaEntered, totalBpEntered, jobStatusEntered, finalJobReportEntered, additionalFaultsEntered,
                                                                             quoteRequiredEntered, followUpPartsRequiredEntered, image1UrlEntered, image2UrlEntered, image3UrlEntered, image4UrlEntered, image5UrlEntered, customerSignatureUrlEntered, customerNameEntered, dtSignedEntered,
                                                                             mttEngSignatureUrlEntered, dayVMs, usernameEntered);
                    retval.SaveToModel();

                    return(retval);
                }
                else
                {
                    new Exception("Unknown Canvas Data Section");
                }
            }

            //If we get to here, then an error has occurred.
            return(null);
            //retval.ServiceSubmission = serviceSheetReturn;
            //return retval;
        }