private void SaveTimeRecording()
        {
            try
            {
                if (Session[SessionName.TimeDetails] == null)
                {
                    _lblError.Text = "Session is timeout or the time details are not saved in the previous screen. Please go back and enter details again.";
                    return;
                }

                TimeServiceClient timeService = null;
                TimeAdditionalDetail timeAdditionalDetail = null;
                try
                {
                    timeService = new TimeServiceClient();
                    IRIS.Law.WebServiceInterfaces.Time.Time time = new IRIS.Law.WebServiceInterfaces.Time.Time();

                    time.ProjectId = (Guid)Session[SessionName.ProjectId];
                    time.FeeEarnerId = _logonSettings.UserDefaultFeeMemberId;
                    time.TimeTypeId = ((TimeDetails)Session[SessionName.TimeDetails]).TimeTypeId;
                    time.Units = ((TimeDetails)Session[SessionName.TimeDetails]).Units;
                    time.Notes = ((TimeDetails)Session[SessionName.TimeDetails]).Notes;
                    time.Date = DateTime.Now.Date;
                    //No validation for limits from the web
                    time.DontCheckLimits = true;
                    time.BillingCodeID = 1; // Default to "Default - None Selected"

                    if (ViewState["CurrentAdditionalDetail"] != null)
                    {
                        timeAdditionalDetail = new TimeAdditionalDetail();

                        timeAdditionalDetail.CurrentAdditionalDetails = (AdditionalDetails)ViewState["CurrentAdditionalDetail"];

                        //Get the data from listview controls if that additional details is selected
                        //and set HaveAskedLaQuestions
                        switch (timeAdditionalDetail.CurrentAdditionalDetails)
                        {
                            case AdditionalDetails.Attendance:
                                #region Attendance

                                timeAdditionalDetail.AdditionalDetailsLocation = (DetailLocation)Enum.Parse(typeof(DetailLocation), _ddlAttendanceLocation.SelectedIndex.ToString());
                                if (_ddlServiceAttendanceLocation.SelectedValue.Length > 0)
                                {
                                    timeAdditionalDetail.LAId = new Guid(_ddlServiceAttendanceLocation.SelectedValue);
                                }

                                //Get the selected joint client candidates
                                List<ListItem> selectedItems = (from item in _chklstAttendanceIndividuals.Items.Cast<ListItem>()
                                                                where item.Selected
                                                                select item).ToList();

                                int[] attendanceInd = new int[selectedItems.Count];
                                for (int i = 0; i < selectedItems.Count; i++)
                                {
                                    int attendanceIndID = Convert.ToInt32(selectedItems[i].Value);
                                    attendanceInd[i] = attendanceIndID;
                                }
                                timeAdditionalDetail.AttendanceIndividuals = attendanceInd;
                                #endregion
                                break;

                            case AdditionalDetails.Advocacy:
                                #region Advocacy

                                timeAdditionalDetail.AdditionalDetailsLocation = (DetailLocation)Enum.Parse(typeof(DetailLocation), _ddlAdvocacyLocation.SelectedIndex.ToString());
                                if (_ddlServiceAdvocacyLocation.SelectedValue.Length > 0)
                                {
                                    timeAdditionalDetail.LAId = new Guid(_ddlServiceAdvocacyLocation.SelectedValue);
                                }

                                //Get the selected joint client candidates
                                List<ListItem> selectedItemsHearing = (from item in _chklstHearingType.Items.Cast<ListItem>()
                                                                       where item.Selected
                                                                       select item).ToList();

                                int[] advocacyTypeId = new int[selectedItemsHearing.Count];
                                for (int i = 0; i < selectedItemsHearing.Count; i++)
                                {
                                    int tempAdvocacyTypeId = Convert.ToInt32(selectedItemsHearing[i].Value);
                                    advocacyTypeId[i] = tempAdvocacyTypeId;
                                }
                                timeAdditionalDetail.AdvocacyTypes = advocacyTypeId;
                                #endregion
                                break;

                            case AdditionalDetails.Travel:
                                #region Travel
                                if (_txtMiles.Text.Length > 0)
                                {
                                    timeAdditionalDetail.Miles = Convert.ToInt32(_txtMiles.Text);
                                }
                                timeAdditionalDetail.FaresDescription = _txtFaresDescription.Text;
                                if (_txtFares.Text.Length > 0)
                                {
                                    timeAdditionalDetail.FaresAmount = Convert.ToDecimal(_txtFares.Text);
                                }
                                #endregion
                                break;

                            case AdditionalDetails.PoliceStationCalls:
                                #region PoliceStationCalls
                                if (_ddlPoliceStationCalls.SelectedValue == "Police Station")
                                {
                                    timeAdditionalDetail.AdditionalDetailsLocation = DetailLocation.PoliceStation;
                                }
                                else
                                {
                                    timeAdditionalDetail.AdditionalDetailsLocation = DetailLocation.NotApplicable;
                                }

                                if (_ddlServicePoliceStationCalls.SelectedValue.Length > 0)
                                {
                                    timeAdditionalDetail.LAId = new Guid(_ddlServicePoliceStationCalls.SelectedValue);
                                }
                                #endregion
                                break;

                            case AdditionalDetails.RunningTime:
                                #region RunningTime
                                if (_txtHour.Text.Length > 0)
                                {
                                    timeAdditionalDetail.RunningHours = Convert.ToInt32(_txtHour.Text);
                                }
                                if (_txtMinutes.Text.Length > 0)
                                {
                                    timeAdditionalDetail.RunningMinutes = Convert.ToInt32(_txtMinutes.Text);
                                }
                                #endregion
                                break;

                            case AdditionalDetails.CivilImmigrationAsylumSubstantiveHearing:
                                #region CivilImmigrationAsylumSubstantiveHearing
                                timeAdditionalDetail.IsLASubstantiveHearingAttend = _chkCivilImmAsylumSubstantiveHearing.Checked;
                                #endregion
                                break;

                            case AdditionalDetails.CivilImmigrationAsylumTravelWaiting:
                                #region CivilImmigrationAsylumTravelWaiting
                                timeAdditionalDetail.IsTravelWaitingDetCentre = _chkCivilImmAsylumTravelWaitingDetCentre.Checked;
                                if (_ddlServiceCivilImmAsylumTravelWaitingDetCentre.SelectedValue.Length > 0)
                                {
                                    timeAdditionalDetail.LAId = new Guid(_ddlServiceCivilImmAsylumTravelWaitingDetCentre.SelectedValue);
                                }
                                #endregion
                                break;

                            case AdditionalDetails.CivilImmigrationAsylumJRFormFilling:
                                #region CivilImmigrationAsylumJRFormFilling
                                timeAdditionalDetail.LAIsJRFormFilling = _chkCivilImmAsylumJRFormFilling.Checked;
                                #endregion
                                break;

                            case AdditionalDetails.CivilImmigrationAsylumMentalHearing:
                                #region CivilImmigrationAsylumMentalHearing
                                timeAdditionalDetail.IsLAHearingAdjourned = _chkCivilImmAsylumMentalHearingAdjourned.Checked;
                                #endregion
                                break;

                            case AdditionalDetails.CourtDutyAttendance:
                                #region CourtDutyAttendance
                                if (_txtCourtDutyAttNoOfDef.Text.Length > 0)
                                {
                                    timeAdditionalDetail.LASuspect = Convert.ToInt32(_txtCourtDutyAttNoOfDef.Text);
                                }
                                timeAdditionalDetail.IsLAYouth = _chkCourtDutyAtYouth.Checked;
                                if (_ddlCourtDutyAttCourt.SelectedValue.Length > 0)
                                {
                                    timeAdditionalDetail.LAId = new Guid(_ddlCourtDutyAttCourt.SelectedValue);
                                }
                                else
                                {
                                    timeAdditionalDetail.LAId = DataConstants.DummyGuid;
                                }
                                #endregion
                                break;

                            case AdditionalDetails.PoliceStationAttendance:
                                #region PoliceStationAttendance
                                if (_ddlPoliceStationAttendance.SelectedValue == "Police Station")
                                {
                                    timeAdditionalDetail.AdditionalDetailsLocation = DetailLocation.PoliceStation;
                                }
                                else
                                {
                                    timeAdditionalDetail.AdditionalDetailsLocation = DetailLocation.NotApplicable;
                                }

                                //timeAdditionalDetail.AdditionalDetailsLocation = (DetailLocation)Enum.Parse(typeof(DetailLocation), _ddlPoliceStationAttendance.SelectedIndex.ToString());
                                if (_ddlServicePoliceStationAttendance.SelectedValue.Length > 0)
                                {
                                    timeAdditionalDetail.LAId = new Guid(_ddlServicePoliceStationAttendance.SelectedValue);
                                }
                                else
                                {
                                    timeAdditionalDetail.LAId = DataConstants.DummyGuid;
                                }
                                #endregion
                                break;

                            case AdditionalDetails.FileReviews:
                                #region FileReviews
                                if (ViewState["FileReviewProjectId"] == null)
                                {
                                    timeAdditionalDetail.FileReviewsProjectId = DataConstants.DummyGuid;
                                }
                                else
                                {
                                    timeAdditionalDetail.FileReviewsProjectId = new Guid(ViewState["FileReviewProjectId"].ToString());
                                }
                                timeAdditionalDetail.IsFaceToFace = _rdoBtnFaceToFace.Checked;
                                #endregion
                                break;
                        }
                    }

                    TimeReturnValue returnValue = null;

                    if (((TimeDetails)Session[SessionName.TimeDetails]).Id == 0)
                    {
                        //No timeId present. Add a new time entry
                        returnValue = timeService.AddTime(_logonSettings.LogonId, time, timeAdditionalDetail, false);
                    }
                    else
                    {
                        //If a timeId is present then we are updating an existing time entry
                        time.Id = ((TimeDetails)Session[SessionName.TimeDetails]).Id;
                        returnValue = timeService.UpdateTime(_logonSettings.LogonId, time, timeAdditionalDetail);
                    }

                    if (returnValue.Success)
                    {
                        Session[SessionName.TimeDetails] = null;
                        //Redirect the user to the timesheet where entry would be listed
                        Response.Redirect("ViewTimesheet.aspx", false);
                    }
                    else
                    {
                        throw new Exception(returnValue.Message);
                    }
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                finally
                {
                    if (timeService != null)
                    {
                        if (timeService.State != System.ServiceModel.CommunicationState.Faulted)
                            timeService.Close();
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        protected void _btnSave_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                if (_txtUnits.Text == "0")
                {
                    _lblMessage.CssClass = "errorMessage";
                    _lblMessage.Text = "Units cannot be zero";
                    return;
                }

                TimeDetails timeDetails = new TimeDetails();
                timeDetails.ProjectId = (Guid)Session[SessionName.ProjectId];
                timeDetails.FeeEarnerId = _logonSettings.UserDefaultFeeMemberId;
                timeDetails.TimeTypeId = new Guid(GetValueOnIndexFromArray(_ddlTimeType.SelectedValue.Trim(), 0));
                timeDetails.TimeTypeCatId = Convert.ToInt32(GetValueOnIndexFromArray(_ddlTimeType.SelectedValue.Trim(), 1));
                timeDetails.Units = Convert.ToInt32(_txtUnits.Text.Trim());
                timeDetails.Notes = _txtNotes.Text.Trim();
                timeDetails.Date = DateTime.Now.Date;
                // No validation for limits from the web
                timeDetails.CanProceed = true;
                if (ViewState["TimeId"] == null)
                {
                    timeDetails.Id = 0;
                }
                else
                {
                    timeDetails.Id = Convert.ToInt32(ViewState["TimeId"]);
                }

                if (IsAdditionalDetailTimeExists(timeDetails))
                {
                    Session[SessionName.TimeDetails] = timeDetails;
                    Response.Redirect("~/Pages/Time/AdditionalTimeDetails.aspx", true);
                }
                else
                {
                    TimeServiceClient timeService = null;
                    TimeReturnValue returnValue = null;
                    try
                    {
                        timeService = new TimeServiceClient();
                        IRIS.Law.WebServiceInterfaces.Time.Time time = new IRIS.Law.WebServiceInterfaces.Time.Time();

                        time.ProjectId = (Guid)Session[SessionName.ProjectId];
                        time.FeeEarnerId = _logonSettings.UserDefaultFeeMemberId;
                        time.TimeTypeId = timeDetails.TimeTypeId;
                        time.Units = timeDetails.Units;
                        time.Notes = timeDetails.Notes;
                        time.Date = DateTime.Now.Date;
                        //No validation for limits from the web
                        time.DontCheckLimits = true;
                        time.BillingCodeID = 1; // Default to "Default - None Selected"

                        if (timeDetails.Id == 0)
                        {
                            //No timeId present. Add a new time entry
                            returnValue = timeService.AddTime(_logonSettings.LogonId, time, null, false);
                        }
                        else
                        {
                            //If a timeId is present then we are updating an existing time entry
                            time.Id = timeDetails.Id;
                            returnValue = timeService.UpdateTime(_logonSettings.LogonId, time, null);
                        }

                        if (returnValue.Success)
                        {
                            Session[SessionName.TimeDetails] = null;
                            //Redirect the user to the timesheet where entry would be listed
                            Response.Redirect("ViewTimesheet.aspx", true);
                        }
                        else
                        {
                            throw new Exception(returnValue.Message);
                        }
                    }
                    catch (System.ServiceModel.EndpointNotFoundException)
                    {
                        _lblMessage.Text = DataConstants.WSEndPointErrorMessage;
                        _lblMessage.CssClass = "errorMessage";
                    }
                    catch (Exception ex)
                    {
                        _lblMessage.CssClass = "errorMessage";
                        _lblMessage.Text = ex.Message;
                    }
                    finally
                    {
                        if (timeService != null)
                        {
                            if (timeService.State != System.ServiceModel.CommunicationState.Faulted)
                                timeService.Close();
                        }
                    }
                }
            }
        }
        protected void _btnSave_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                if (_txtUnits.Text == "0")
                {
                    _lblMessage.CssClass = "errorMessage";
                    _lblMessage.Text     = "Units cannot be zero";
                    return;
                }

                TimeDetails timeDetails = new TimeDetails();
                timeDetails.ProjectId     = (Guid)Session[SessionName.ProjectId];
                timeDetails.FeeEarnerId   = _logonSettings.UserDefaultFeeMemberId;
                timeDetails.TimeTypeId    = new Guid(GetValueOnIndexFromArray(_ddlTimeType.SelectedValue.Trim(), 0));
                timeDetails.TimeTypeCatId = Convert.ToInt32(GetValueOnIndexFromArray(_ddlTimeType.SelectedValue.Trim(), 1));
                timeDetails.Units         = Convert.ToInt32(_txtUnits.Text.Trim());
                timeDetails.Notes         = _txtNotes.Text.Trim();
                timeDetails.Date          = DateTime.Now.Date;
                // No validation for limits from the web
                timeDetails.CanProceed = true;
                if (ViewState["TimeId"] == null)
                {
                    timeDetails.Id = 0;
                }
                else
                {
                    timeDetails.Id = Convert.ToInt32(ViewState["TimeId"]);
                }

                if (IsAdditionalDetailTimeExists(timeDetails))
                {
                    Session[SessionName.TimeDetails] = timeDetails;
                    Response.Redirect("~/Pages/Time/AdditionalTimeDetails.aspx", true);
                }
                else
                {
                    TimeServiceClient timeService = null;
                    TimeReturnValue   returnValue = null;
                    try
                    {
                        timeService = new TimeServiceClient();
                        IRIS.Law.WebServiceInterfaces.Time.Time time = new IRIS.Law.WebServiceInterfaces.Time.Time();

                        time.ProjectId   = (Guid)Session[SessionName.ProjectId];
                        time.FeeEarnerId = _logonSettings.UserDefaultFeeMemberId;
                        time.TimeTypeId  = timeDetails.TimeTypeId;
                        time.Units       = timeDetails.Units;
                        time.Notes       = timeDetails.Notes;
                        time.Date        = DateTime.Now.Date;
                        //No validation for limits from the web
                        time.DontCheckLimits = true;
                        time.BillingCodeID   = 1; // Default to "Default - None Selected"

                        if (timeDetails.Id == 0)
                        {
                            //No timeId present. Add a new time entry
                            returnValue = timeService.AddTime(_logonSettings.LogonId, time, null, false);
                        }
                        else
                        {
                            //If a timeId is present then we are updating an existing time entry
                            time.Id     = timeDetails.Id;
                            returnValue = timeService.UpdateTime(_logonSettings.LogonId, time, null);
                        }

                        if (returnValue.Success)
                        {
                            Session[SessionName.TimeDetails] = null;
                            //Redirect the user to the timesheet where entry would be listed
                            Response.Redirect("ViewTimesheet.aspx", true);
                        }
                        else
                        {
                            throw new Exception(returnValue.Message);
                        }
                    }
                    catch (System.ServiceModel.EndpointNotFoundException)
                    {
                        _lblMessage.Text     = DataConstants.WSEndPointErrorMessage;
                        _lblMessage.CssClass = "errorMessage";
                    }
                    catch (Exception ex)
                    {
                        _lblMessage.CssClass = "errorMessage";
                        _lblMessage.Text     = ex.Message;
                    }
                    finally
                    {
                        if (timeService != null)
                        {
                            if (timeService.State != System.ServiceModel.CommunicationState.Faulted)
                            {
                                timeService.Close();
                            }
                        }
                    }
                }
            }
        }