Ejemplo n.º 1
0
    }//end void


    private void UpdateInstallationObject(bool isService = false, bool isStaff = false, bool isDateAndTime = false, bool isUserInfo = false, bool isPayment = false, bool isConfirmation = false) {
        try {

            //get installation and current appt from session 
            Installation i = WebUtils.GetInstallationObjectFromSession();
            ApptBLL currAppt = SessionVariables.CURRENT_APPOINTMENT;
            if (currAppt == null)
                currAppt = new ApptBLL();

            //R SaveInstallationToDB (test installation isnt save to DB)

            //get selected service details
            if (isService) {//1
                int servSel = this.ServiceSelectionUserControl.GetSelectedServiceIndex();
                int? servID = i.Services[servSel].ID;
                currAppt.serviceID = (int)servID;
            }

            //get selected employee details
            if (isStaff) {//2               
                int staffSel_index = this.StaffSelectionUserControl.GetSelectedServiceIndex();
                string staffSel_1stnameWithTitle = this.StaffSelectionUserControl.GetStaffelected();
                EmployeeBLL selStaff = null;
                //NB index 0 = "No Preference"
                if (staffSel_index > 0) {
                    selStaff = i.Employees[staffSel_index - 1];
                    currAppt.provider = staffSel_1stnameWithTitle;
                    //update date&time control == staff calendar
                    PopulateDateAndTimeUserControl(selStaff, this.DateSelectionUserControl.GetSelectedDate());
                }
                else {
                    //ALWAYS pick 1st staff by default
                    selStaff = i.Employees[0];//staff can be null
                    currAppt.provider = selStaff.title + " " + selStaff.firstName;
                }
                //update LabelServProvider
                //-- IMPORTANT LABEL USED ON UPDATE_INSTALLATION()
                this.LabelServProvider.Text = selStaff.firstName;
                //R PopulateDateAndTimeUserControl(selStaff, )

            }//endif isStaff

            //get selected Date&Time details
            if (isDateAndTime) {//3
                // get user entries from userControl
                string userSelDate = this.DateSelectionUserControl.GetSelectedDateStrg();
                string userSelTime = this.DateSelectionUserControl.GetSelectedTimeStrg();
                //convert entries into correct datat type
                DateTime userDate = (DateTime)Utils.GetDateFromString(userSelDate);
                TimeSpan userTime = (TimeSpan)Utils.GetTimeFromString(userSelTime);

                //assign entries to current appt in the session
                currAppt.date = userDate;
                currAppt.time = userTime;
                System.Diagnostics.Debug.Print(currAppt.provider);
            }

            //get entered userInformation details
            if (isUserInfo) {
                //get user entries from user control
                List<string> userPersoDet = this.UserInfoUserControl.GetPersonalDetails();

                //NB added programmatically END-USER username is their email address.
                //add ASP.NETUSER, If it already exists return aspnetID
                Guid endUserASPUserID = WebUtils.AddEndUserASPNETUser(userPersoDet[2], userPersoDet[1], userPersoDet[3]);
                //check user exists of DB/session 20/716 revise?
                int userIndex = i.EndUsers.FindIndex(endUser => endUser.aspnetUserID.ToString().Equals(endUserASPUserID.ToString(), StringComparison.Ordinal));
                //create new
                if (userIndex < 0) {
                    //create new end-user contact Details
                    ContactDetailsBLL newEndUserContact = new ContactDetailsBLL(userPersoDet[5], userPersoDet[6], userPersoDet[7], "UK", null, userPersoDet[4], userPersoDet[3]);
                    //create new end-user
                    EndUserBLL newEndUser = new EndUserBLL(userPersoDet[0], userPersoDet[1], userPersoDet[2], newEndUserContact, endUserASPUserID);
                    //add to installation
                    i.EndUsers.Add(newEndUser);
                }
                //add notes to current appt (userID is added on SaveInstallationToDB2)
                currAppt.notes = userPersoDet[8];
            }

            if (isPayment) {
                //

            }

            if (isConfirmation) {
                //----- Add appt to installation on session ------                
                i.Appointments.Add(currAppt);
                string curSelStaff1stName = this.LabelServProvider.Text;

                //----- process data and save to database ------
                InstallationBLL.SaveInstallationToDB2(ref i, ref currAppt, curSelStaff1stName, SessionVariables.TempStaffFolder, SessionVariables.ISummaryXML);
            }

            //save current appt back to session installation and current appt from session 
            SessionVariables.CURRENT_APPOINTMENT = currAppt;

            //add installation back to session
            WebUtils.PutInstallationObjectinSession(i);



        }
        catch (Exception ex) {
            System.Diagnostics.Debug.Print("<h2>BookAppt.aspx, UpdateInstallationObject(x6)</h2>\n" + ex.ToString() + "\n" + ex.InnerException + "\n" + ex.Message);
            // Log the exception and notify system operators
            ExceptionUtility.LogException(ex, "BookAppt.aspx, UpdateInstallationObject(x6)");
            ExceptionUtility.NotifySystemOps(ex);
        }
    }//end UpdateInstallationObject(x6)