/// <summary>
        /// DeleteDirect
        /// </summary>
        /// <param name="serviceId">serviceId</param>
        /// <param name="unitType">unitType</param>
        /// <param name="companyId">companyId</param>
        public void DeleteDirect(int serviceId, string unitType, int unitId, int companyId)
        {
            // Delete service
            Services services = new Services(null);
            services.DeleteDirect(serviceId, unitType, companyId);

            UpdateUnitState(unitId, "Active", companyId);
        }
        /// <summary>
        /// Save services
        /// </summary>
        /// <param name="dateTime_">dateTime_</param>
        /// <param name="employeeId">employeeId</param>
        /// <param name="companyId">companyId</param>
        /// <param name="checklistState">checklistState</param>
        public int? Save(DateTime dateTime_, int employeeId, int companyId)
        {
            int? newServiceId = null;

            ServicesAddRequestTDS servicesAddRequestSelfAsignedChanges = (ServicesAddRequestTDS)Data.GetChanges();
            if (servicesAddRequestSelfAsignedChanges.BasicInformation.Rows.Count > 0)
            {
                ServicesGateway servicesGateway = new ServicesGateway(servicesAddRequestSelfAsignedChanges);

                foreach (ServicesAddRequestTDS.BasicInformationRow row in (ServicesAddRequestTDS.BasicInformationDataTable)servicesAddRequestSelfAsignedChanges.BasicInformation)
                {
                    DateTime? assignmentDeadlineDate = null; if (!row.IsAssignedDeadlineDateNull()) assignmentDeadlineDate = row.AssignedDeadlineDate;
                    DateTime? assignDateTime = null; if(row.IsAssignDateTimeNull()) row.AssignDateTime = DateTime.Now;
                    DateTime? acceptDatetime = null; if (!row.IsAcceptDatetimeNull()) acceptDatetime = row.AcceptDatetime;
                    DateTime? unitOutOfServiceDate = null; if (!row.IsUnitOutOfServiceDateNull()) unitOutOfServiceDate = row.UnitOutOfServiceDate;
                    string unitOutOfServiceTime = ""; if (!row.IsUnitOutOfServiceTimeNull()) unitOutOfServiceTime = row.UnitOutOfServiceTime;
                    DateTime? completeWorkDateTime = null; if (!row.IsCompleteWorkDateTimeNull()) completeWorkDateTime = row.CompleteWorkDateTime;
                    DateTime? unitBackInServiceDate = null; if (!row.IsUnitBackInServiceDateNull()) unitBackInServiceDate = row.UnitBackInServiceDate;
                    string unitBackInServiceTime = ""; if (!row.IsUnitBackInServiceTimeNull()) unitBackInServiceTime = row.UnitBackInServiceTime;
                    string completeWorkDetailDescription = ""; if (!row.IsCompleteWorkDetailDescriptionNull()) completeWorkDetailDescription = row.CompleteWorkDetailDescription;
                    bool completeWorkDetailPreventable = row.CompleteWorkDetailPreventable;
                    Decimal? completeWorkDetailTMLabourHours = null; if (!row.IsCompleteWorkDetailTMLabourHoursNull()) completeWorkDetailTMLabourHours = row.CompleteWorkDetailTMLabourHours;
                    Decimal? completeWorkDetailTMCost = null; if (!row.IsCompleteWorkDetailTMCostNull()) completeWorkDetailTMCost = row.CompleteWorkDetailTMCost;
                    string completeWorkDetaildTPVInvoiceNumber = ""; if (!row.IsCompleteWorkInvoiceNumberNull()) completeWorkDetaildTPVInvoiceNumber = row.CompleteWorkInvoiceNumber;
                    Decimal? completeWorkDetaildTPVInvoiceAmount = null; if (!row.IsCompleteWorkInvoiceAmountNull()) completeWorkDetaildTPVInvoiceAmount = row.CompleteWorkInvoiceAmount;
                    string mileage = ""; if (!row.IsMileageNull()) mileage = row.Mileage;
                    string startWorkMileage = ""; if (!row.IsStartWorkMileageNull()) startWorkMileage = row.StartWorkMileage;
                    string completeWorkMileage = ""; if (!row.IsCompleteWorkMileageNull()) completeWorkMileage = row.CompleteWorkMileage;
                    bool assignTeamMember = row.AssignTeamMember;
                    int? assignTeamMemberId = null; if (!row.IsAssignTeamMemberIdNull()) assignTeamMemberId = row.AssignTeamMemberId;
                    string assignThirdPartyVendor = ""; if (!row.IsAssignThirdPartyVendorNull()) assignThirdPartyVendor = row.AssignThirdPartyVendor;
                    DateTime? startWorkDateTime = null; if (!row.IsUnitOutOfServiceDateNull()) startWorkDateTime =  DateTime.Now;
                    int? ruleId = null; if (!row.IsRuleIDNull()) ruleId = row.RuleID;
                    string type = ""; if (ruleId.HasValue) type = "Checklist"; else type = "Normal";
                    int? libraryCategoriesId = 3736;//Fleet Maintence Invoices folder

                    Services services = new Services(null);
                    newServiceId = services.InsertDirect(dateTime_, row.MtoDot, row.ServiceDescription, row.UnitID, type, row.ServiceState, employeeId, assignDateTime, assignmentDeadlineDate, assignTeamMember, assignTeamMemberId, assignThirdPartyVendor, acceptDatetime, null, "", startWorkDateTime, unitOutOfServiceDate, unitOutOfServiceTime, completeWorkDateTime, unitBackInServiceDate, unitBackInServiceTime, completeWorkDetailDescription, completeWorkDetailPreventable, completeWorkDetailTMLabourHours, completeWorkDetailTMCost, completeWorkDetaildTPVInvoiceNumber, completeWorkDetaildTPVInvoiceAmount, "", ruleId, mileage, startWorkMileage, completeWorkMileage, row.Deleted, row.COMPANY_ID, libraryCategoriesId);

                    // modify checklist state
                    if (ruleId.HasValue)
                    {
                        string newChecklistState = "In Progress";

                        if (row.ServiceState == "Completed")
                        {
                            RuleGateway ruleGateway = new RuleGateway();
                            ruleGateway.LoadAllByRuleId(row.RuleID, row.COMPANY_ID);

                            DateTime? newLastService = null; newLastService = DateTime.Now;
                            DateTime? newNextDue = null;
                            bool newDone = true;
                            newChecklistState = "Healthy";

                            if (newLastService.HasValue)
                            {
                                ChecklistGateway checklistGateway = new ChecklistGateway();
                                checklistGateway.LoadByUnitIdRuleId(row.UnitID, row.RuleID, companyId);

                                // ... Original values
                                DateTime? originalLastService = checklistGateway.GetLastService(row.UnitID, row.RuleID);
                                DateTime? originalNextDue = checklistGateway.GetNextDue(row.UnitID, row.RuleID);
                                bool originalDone = checklistGateway.GetDone(row.UnitID, row.RuleID);
                                string originalState = checklistGateway.GetState(row.UnitID, row.RuleID);

                                string frecuency = ruleGateway.GetFrequency(row.RuleID);

                                if (frecuency != "Only once")
                                {
                                    // Get next due
                                    DateTime timeToAdded = new DateTime(((DateTime)newLastService).Year, ((DateTime)newLastService).Month, ((DateTime)newLastService).Day);

                                    if (frecuency == "Monthly") newNextDue = timeToAdded.AddMonths(1);
                                    if (frecuency == "Every 2 months") newNextDue = timeToAdded.AddMonths(2);
                                    if (frecuency == "Every 3 months") newNextDue = timeToAdded.AddMonths(3);
                                    if (frecuency == "Every 4 months") newNextDue = timeToAdded.AddMonths(4);
                                    if (frecuency == "Every 6 months") newNextDue = timeToAdded.AddMonths(6);
                                    if (frecuency == "Yearly") newNextDue = timeToAdded.AddYears(1);

                                    newDone = false;
                                }

                                Checklist checklist = new Checklist();
                                checklist.UpdateDirect(row.UnitID, row.RuleID, originalLastService, originalNextDue, originalDone, originalState, false, companyId, row.UnitID, row.RuleID, newLastService, newNextDue, newDone, newChecklistState, false, companyId);
                            }
                        }
                        else
                        {
                            Checklist checklist = new Checklist(null);
                            checklist.UpdateStateDirect(ruleId.Value, row.UnitID, companyId, newChecklistState);
                        }
                    }
                }
            }

            return newServiceId;
        }
        // ////////////////////////////////////////////////////////////////////////
        // PRIVATE METHODS
        //
        /// <summary>
        /// UpdateService
        /// </summary>
        /// <param name="serviceId">serviceId</param>
        /// <param name="originalNumber">originalNumber</param>
        /// <param name="originalDateTime">originalDateTime</param>
        /// <param name="originalMtoDto">originalMtoDto</param>
        /// <param name="originalDescription">originalDescription</param>
        /// <param name="originalUnitId">originalUnitId</param>
        /// <param name="originalType">originalType</param>
        /// <param name="originalState">originalState</param>
        /// <param name="originalOwnerId">originalOwnerId</param>
        /// <param name="originalAssignDateTime">originalAssignDateTime</param>
        /// <param name="originalAssignDeadlineDate">originalAssignDeadlineDate</param>
        /// <param name="originalAssignTeamMember">originalAssignTeamMember</param>
        /// <param name="originalAssignTeamMemberID">originalAssignTeamMemberID</param>
        /// <param name="originalAssignThirdPartyVendor">originalAssignThirdPartyVendor</param>
        /// <param name="originalAcceptDateTime">originalAcceptDateTime</param>
        /// <param name="originalRejectDateTime">originalRejectDateTime</param>
        /// <param name="originalRejectReason">originalRejectReason</param>
        /// <param name="originalStartWorkDateTime">originalStartWorkDateTime</param>
        /// <param name="originalStartWorkOutOfServiceDate">originalStartWorkOutOfServiceDate</param>
        /// <param name="originalStartWorkOutOfServiceTime">originalStartWorkOutOfServiceTime</param>
        /// <param name="originalCompleteWorkDateTime">originalCompleteWorkDateTime</param>
        /// <param name="originalCompleteWorkBackToServiceDate">originalCompleteWorkBackToServiceDate</param>
        /// <param name="originalCompleteWorkBackToServiceTime">originalCompleteWorkBackToServiceTime</param>
        /// <param name="originalCompleteWorkDetailDescription">originalCompleteWorkDetailDescription</param>
        /// <param name="originalCompleteWorkDetailPreventable">originalCompleteWorkDetailPreventable</param>
        /// <param name="originalCompleteWorkDetailTMLabourHours">originalCompleteWorkDetailTMLabourHours</param>
        /// <param name="originalCompleteWorkDetailTMCost">originalCompleteWorkDetailTMCost</param>
        /// <param name="originalCompleteWorkDetailTPVInvoiceNumber">originalCompleteWorkDetailTPVInvoiceNumber</param>
        /// <param name="originalCompleteWorkDetailTPVInvoiceAmout">originalCompleteWorkDetailTPVInvoiceAmout</param>
        /// <param name="originalDeleted">originalDeleted</param>
        /// <param name="originalCompanyId">originalCompanyId</param>
        /// <param name="originalNotes">originalNotes</param>
        /// <param name="originalRuleId">originalRuleId</param>
        /// <param name="originalMileage">originalMileage</param>
        /// <param name="originalStartWorkMileage">originalStartWorkMileage</param>
        /// <param name="originalCompleteWorkMileage">originalCompleteWorkMileage</param>
        /// <param name="originalLibraryCategoriesId">originalLibraryCategoriesId</param>
        /// 
        /// <param name="newNumber">newNumber</param>
        /// <param name="newDateTime">newDateTime</param>
        /// <param name="newMtoDto">newMtoDto</param>
        /// <param name="newDescription">newDescription</param>
        /// <param name="newUnitId">newUnitId</param>
        /// <param name="newType">newType</param>
        /// <param name="newState">newState</param>
        /// <param name="newOwnerId">newOwnerId</param>
        /// <param name="newAssignDateTime">newAssignDateTime</param>
        /// <param name="newAssignDeadlineDate">newAssignDeadlineDate</param>
        /// <param name="newAssignTeamMember">newAssignTeamMember</param>
        /// <param name="newAssignTeamMemberID">newAssignTeamMemberID</param>
        /// <param name="newAssignThirdPartyVendor">newAssignThirdPartyVendor</param>
        /// <param name="newAcceptDateTime">newAcceptDateTime</param>
        /// <param name="newRejectDateTime">newRejectDateTime</param>
        /// <param name="newRejectReason">newRejectReason</param>
        /// <param name="newStartWorkDateTime">newStartWorkDateTime</param>
        /// <param name="newStartWorkOutOfServiceDate">newStartWorkOutOfServiceDate</param>
        /// <param name="newStartWorkOutOfServiceTime">newStartWorkOutOfServiceTime</param>
        /// <param name="newCompleteWorkDateTime">newCompleteWorkDateTime</param>
        /// <param name="newCompleteWorkBackToServiceDate">newCompleteWorkBackToServiceDate</param>
        /// <param name="newCompleteWorkBackToServiceTime">newCompleteWorkBackToServiceTime</param>
        /// <param name="newCompleteWorkDetailDescription">newCompleteWorkDetailDescription</param>
        /// <param name="newCompleteWorkDetailPreventable">newCompleteWorkDetailPreventable</param>
        /// <param name="newCompleteWorkDetailTMLabourHours">newCompleteWorkDetailTMLabourHours</param>
        /// <param name="newCompleteWorkDetailTMCost">newCompleteWorkDetailTMCost</param>
        /// <param name="newCompleteWorkDetailTPVInvoiceNumber">newCompleteWorkDetailTPVInvoiceNumber</param>
        /// <param name="newCompleteWorkDetailTPVInvoiceAmout">newCompleteWorkDetailTPVInvoiceAmout</param>
        /// <param name="newDeleted">newDeleted</param>
        /// <param name="newCompanyId">newCompanyId</param>
        /// <param name="newNotes">newNotes</param>
        /// <param name="newRuleId">newRuleId</param>
        /// <param name="newMileage">newMileage</param> 
        /// <param name="newStartWorkMileage">newStartWorkMileage</param>
        /// <param name="newCompleteWorkMileage">newCompleteWorkMileage</param>
        /// <param name="newLibraryCategoriesId">newLibraryCategoriesId</param>
        private void UpdateService(int serviceId, string originalNumber, DateTime originalDateTime, bool originalMtoDto, string originalDescription, int? originalUnitId, string originalType, string originalState, int originalOwnerId, DateTime? originalAssignDateTime, DateTime? originalAssignDeadlineDate, bool originalAssignTeamMember, int? originalAssignTeamMemberID, string originalAssignThirdPartyVendor, DateTime? originalAcceptDateTime, DateTime? originalRejectDateTime, string originalRejectReason, DateTime? originalStartWorkDateTime, DateTime? originalStartWorkOutOfServiceDate, string originalStartWorkOutOfServiceTime, DateTime? originalCompleteWorkDateTime, DateTime? originalCompleteWorkBackToServiceDate, string originalCompleteWorkBackToServiceTime, string originalCompleteWorkDetailDescription, bool originalCompleteWorkDetailPreventable, decimal? originalCompleteWorkDetailTMLabourHours, decimal? originalCompleteWorkDetailTMCost, string originalCompleteWorkDetailTPVInvoiceNumber, decimal? originalCompleteWorkDetailTPVInvoiceAmout, bool originalDeleted, int originalCompanyId, string originalNotes, int? originalRuleId, string originalMileage, string originalStartWorkMileage, string originalCompleteWorkMileage, int? originalLibraryCategoriesId, string newNumber, DateTime? newDateTime, bool newMtoDto, string newDescription, int? newUnitId, string newType, string newState, int newOwnerId, DateTime? newAssignDateTime, DateTime? newAssignDeadlineDate, bool newAssignTeamMember, int? newAssignTeamMemberID, string newAssignThirdPartyVendor, DateTime? newAcceptDateTime, DateTime? newRejectDateTime, string newRejectReason, DateTime? newStartWorkDateTime, DateTime? newStartWorkOutOfServiceDate, string newStartWorkOutOfServiceTime, DateTime? newCompleteWorkDateTime, DateTime? newCompleteWorkBackToServiceDate, string newCompleteWorkBackToServiceTime, string newCompleteWorkDetailDescription, bool newCompleteWorkDetailPreventable, decimal? newCompleteWorkDetailTMLabourHours, decimal? newCompleteWorkDetailTMCost, string newCompleteWorkDetailTPVInvoiceNumber, decimal? newCompleteWorkDetailTPVInvoiceAmout, bool newDeleted, int newCompanyId, string newNotes, int? newRuleId, string newMileage, string newStartWorkMileage, string newCompleteWorkMileage, int? newLibraryCategoriesId)
        {
            Services services = new Services(null);
            services.UpdateDirect(serviceId, originalNumber, originalDateTime, originalMtoDto, originalDescription, originalUnitId, originalType, originalState, originalOwnerId, originalAssignDateTime, originalAssignDeadlineDate, originalAssignTeamMember, originalAssignTeamMemberID, originalAssignThirdPartyVendor, originalAcceptDateTime, originalRejectDateTime, originalRejectReason, originalStartWorkDateTime, originalStartWorkOutOfServiceDate, originalStartWorkOutOfServiceTime, originalCompleteWorkDateTime, originalCompleteWorkBackToServiceDate, originalCompleteWorkBackToServiceTime, originalCompleteWorkDetailDescription, originalCompleteWorkDetailPreventable, originalCompleteWorkDetailTMLabourHours, originalCompleteWorkDetailTMCost, originalCompleteWorkDetailTPVInvoiceNumber, originalCompleteWorkDetailTPVInvoiceAmout, originalDeleted, originalCompanyId, originalNotes, originalRuleId, originalMileage, originalStartWorkMileage, originalCompleteWorkMileage, originalLibraryCategoriesId, newNumber, newDateTime, newMtoDto, newDescription, newUnitId, newType, newState, newOwnerId, newAssignDateTime, newAssignDeadlineDate, newAssignTeamMember, newAssignTeamMemberID, newAssignThirdPartyVendor, newAcceptDateTime, newRejectDateTime, newRejectReason, newStartWorkDateTime, newStartWorkOutOfServiceDate, newStartWorkOutOfServiceTime, newCompleteWorkDateTime, newCompleteWorkBackToServiceDate, newCompleteWorkBackToServiceTime, newCompleteWorkDetailDescription, newCompleteWorkDetailPreventable, newCompleteWorkDetailTMLabourHours, newCompleteWorkDetailTMCost, newCompleteWorkDetailTPVInvoiceNumber, newCompleteWorkDetailTPVInvoiceAmout, newDeleted, newCompanyId, newNotes, newRuleId, newMileage, newStartWorkMileage, newCompleteWorkMileage, newLibraryCategoriesId);

            if (originalUnitId.HasValue)
            {
                if (newState == "In Progress")
                {
                    UpdateUnitState((int)originalUnitId, "Out Of Service", originalCompanyId);
                }

                if (newState == "Completed")
                {
                    UpdateUnitState((int)originalUnitId, "Active", originalCompanyId);
                }
            }
        }
        /// <summary>
        /// Save services
        /// </summary>        
        /// <param name="companyId">companyId</param>
        public void Save(int companyId)
        {
            ServiceRequestsManagerToolTDS serviceRequestsManagerToolChanges = (ServiceRequestsManagerToolTDS)Data.GetChanges();

            if (serviceRequestsManagerToolChanges.BasicInformation.Rows.Count > 0)
            {
                ServiceRequestsManagerToolBasicInformationGateway srManagerToolBasicInformationGateway = new ServiceRequestsManagerToolBasicInformationGateway(serviceRequestsManagerToolChanges);

                foreach (ServiceRequestsManagerToolTDS.BasicInformationRow row in (ServiceRequestsManagerToolTDS.BasicInformationDataTable)serviceRequestsManagerToolChanges.BasicInformation)
                {
                    // Unchanged values
                    int serviceId = row.ServiceID;
                    string type = srManagerToolBasicInformationGateway.GetTypeOriginal(serviceId);
                    string serviceNumber = srManagerToolBasicInformationGateway.GetServiceNumberOriginal(serviceId);
                    DateTime dateTime_ = srManagerToolBasicInformationGateway.GetDateTime_Original(serviceId);
                    int? unitID = srManagerToolBasicInformationGateway.GetUnitIdOriginal(serviceId);
                    int ownerId = srManagerToolBasicInformationGateway.GetOwnerIdOriginal(serviceId);
                    string serviceDescription = srManagerToolBasicInformationGateway.GetServiceDescriptionOriginal(serviceId);
                    DateTime? rejectDateTime = srManagerToolBasicInformationGateway.GetRejectDateTimeOriginal(serviceId);
                    string rejectReason = srManagerToolBasicInformationGateway.GetRejectReasonOriginal(serviceId);
                    string notes = srManagerToolBasicInformationGateway.GetNotesOriginal(serviceId);
                    int? ruleId = srManagerToolBasicInformationGateway.GetRuleIdOriginal(serviceId);
                    bool deleted = srManagerToolBasicInformationGateway.GetDeletedOriginal(serviceId);
                    bool mto = srManagerToolBasicInformationGateway.GetMtoOriginal(serviceId);

                    // Original values
                    string originalState = srManagerToolBasicInformationGateway.GetServiceStateOriginal(serviceId);
                    DateTime? originalDateTime_ = srManagerToolBasicInformationGateway.GetAssignmentDateTimeOriginal(serviceId);
                    DateTime? originalAssignmentDeadlineDate = srManagerToolBasicInformationGateway.GetAssignedDeadlineDateOriginal(serviceId);
                    bool originalAssignTeamMember = srManagerToolBasicInformationGateway.GetAssignTeamMemberOriginal(serviceId);
                    int? originalAssignTeamMemberId = srManagerToolBasicInformationGateway.GetAssignTeamMemberIdOriginal(serviceId);
                    string originalAssignThirdPartyVendor = srManagerToolBasicInformationGateway.GetAssignedThirdPartyVendorOriginal(serviceId);
                    DateTime? originalAcceptDatetime = srManagerToolBasicInformationGateway.GetAcceptedDateTimeOriginal(serviceId);
                    DateTime? originalStartWorkDateTime = srManagerToolBasicInformationGateway.GetStartWorkDateTimeOriginal(serviceId);
                    DateTime? originalUnitOutOfServiceDate = srManagerToolBasicInformationGateway.GetUnitOutOfServiceDateOriginal(serviceId);
                    string originalUnitOutOfServiceTime = srManagerToolBasicInformationGateway.GetUnitOutOfServiceTimeOriginal(serviceId);
                    DateTime? originalCompleteWorkDateTime = srManagerToolBasicInformationGateway.GetCompleteWorkDateTimeOriginal(serviceId);
                    DateTime? originalUnitBackInServiceDate = srManagerToolBasicInformationGateway.GetUnitBackInServiceDateOriginal(serviceId);
                    string originalUnitBackInServiceTime = srManagerToolBasicInformationGateway.GetUnitBackInServiceTimeOriginal(serviceId);
                    string originalCompleteWorkDetailDescription = srManagerToolBasicInformationGateway.GetCompleteWorkDetailDescriptionOriginal(serviceId);
                    bool originalCompleteWorkDetailPreventable = srManagerToolBasicInformationGateway.GetCompleteWorkDetailPreventableOriginal(serviceId);
                    Decimal? originalCompleteWorkDetailTMLabourHours = srManagerToolBasicInformationGateway.GetCompleteWorkDetailTMLabourHoursOriginal(serviceId);
                    Decimal? originalCompleteWorkDetailTMCost = srManagerToolBasicInformationGateway.GetCompleteWorkDetailTMCostOriginal(serviceId);
                    string originalCompleteWorkDetailTPVInvoiceNumber = srManagerToolBasicInformationGateway.GetCompleteWorkDetailTPVInvoiceNumberOriginal(serviceId);
                    Decimal? originalCompleteWorkDetailTPVInvoiceAmount = srManagerToolBasicInformationGateway.GetCompleteWorkDetailTPVInvoiceAmoutOriginal(serviceId);
                    string originalMileage = srManagerToolBasicInformationGateway.GetMileageOriginal(serviceId);
                    string originalStartWorkMileage = srManagerToolBasicInformationGateway.GetStartWorkMileageOriginal(serviceId);
                    string originalCompleteWorkMileage = srManagerToolBasicInformationGateway.GetCompleteWorkMileageOriginal(serviceId);
                    int? originalLibraryCategoriesId = null; if (srManagerToolBasicInformationGateway.GetLibraryCategoriesIdOriginal(serviceId).HasValue) originalLibraryCategoriesId = srManagerToolBasicInformationGateway.GetLibraryCategoriesIdOriginal(serviceId).Value;

                    // New values
                    string newState = srManagerToolBasicInformationGateway.GetServiceState(serviceId);
                    DateTime? newDateTime_ = srManagerToolBasicInformationGateway.GetAssignmentDateTime(serviceId);
                    DateTime? newAssignmentDeadlineDate = srManagerToolBasicInformationGateway.GetAssignedDeadlineDate(serviceId);
                    bool newAssignTeamMember = srManagerToolBasicInformationGateway.GetAssignTeamMember(serviceId);
                    int? newAssignTeamMemberId = srManagerToolBasicInformationGateway.GetAssignTeamMemberId(serviceId);
                    string newAssignThirdPartyVendor = srManagerToolBasicInformationGateway.GetAssignedThirdPartyVendor(serviceId);
                    DateTime? newAcceptDatetime = srManagerToolBasicInformationGateway.GetAcceptedDateTime(serviceId);
                    DateTime? newStartWorkDateTime = srManagerToolBasicInformationGateway.GetStartWorkDateTime(serviceId);
                    DateTime? newUnitOutOfServiceDate = srManagerToolBasicInformationGateway.GetUnitOutOfServiceDate(serviceId);
                    string newUnitOutOfServiceTime = srManagerToolBasicInformationGateway.GetUnitOutOfServiceTime(serviceId);
                    DateTime? newCompleteWorkDateTime = srManagerToolBasicInformationGateway.GetCompleteWorkDateTime(serviceId);
                    DateTime? newUnitBackInServiceDate = srManagerToolBasicInformationGateway.GetUnitBackInServiceDate(serviceId);
                    string newUnitBackInServiceTime = srManagerToolBasicInformationGateway.GetUnitBackInServiceTime(serviceId);
                    string newCompleteWorkDetailDescription = srManagerToolBasicInformationGateway.GetCompleteWorkDetailDescription(serviceId);
                    bool newCompleteWorkDetailPreventable = srManagerToolBasicInformationGateway.GetCompleteWorkDetailPreventable(serviceId);
                    Decimal? newCompleteWorkDetailTMLabourHours = srManagerToolBasicInformationGateway.GetCompleteWorkDetailTMLabourHours(serviceId);
                    Decimal? newCompleteWorkDetailTMCost = srManagerToolBasicInformationGateway.GetCompleteWorkDetailTMCost(serviceId);
                    string newCompleteWorkDetailTPVInvoiceNumber = srManagerToolBasicInformationGateway.GetCompleteWorkDetailTPVInvoiceNumber(serviceId);
                    Decimal? newCompleteWorkDetailTPVInvoiceAmount = srManagerToolBasicInformationGateway.GetCompleteWorkDetailTPVInvoiceAmout(serviceId);
                    string newMileage = srManagerToolBasicInformationGateway.GetMileage(serviceId);
                    string newStartWorkMileage = srManagerToolBasicInformationGateway.GetStartWorkMileage(serviceId);
                    string newCompleteWorkMileage = srManagerToolBasicInformationGateway.GetCompleteWorkMileage(serviceId);
                    int? newLibraryCategoriesId = null; if (srManagerToolBasicInformationGateway.GetLibraryCategoriesId(serviceId).HasValue) newLibraryCategoriesId = srManagerToolBasicInformationGateway.GetLibraryCategoriesId(serviceId).Value;

                    Services services = new Services(null);
                    services.UpdateDirect(serviceId, serviceNumber, dateTime_, mto, serviceDescription, unitID, type, originalState, ownerId, originalDateTime_, originalAssignmentDeadlineDate, originalAssignTeamMember, originalAssignTeamMemberId, originalAssignThirdPartyVendor, originalAcceptDatetime, rejectDateTime, rejectReason, originalStartWorkDateTime, originalUnitOutOfServiceDate, originalUnitOutOfServiceTime, originalCompleteWorkDateTime, originalUnitBackInServiceDate, originalUnitBackInServiceTime, originalCompleteWorkDetailDescription, originalCompleteWorkDetailPreventable, originalCompleteWorkDetailTMLabourHours, originalCompleteWorkDetailTMCost, originalCompleteWorkDetailTPVInvoiceNumber, originalCompleteWorkDetailTPVInvoiceAmount, deleted, companyId, notes, ruleId, originalMileage, originalStartWorkMileage, originalCompleteWorkMileage, originalLibraryCategoriesId, serviceNumber, dateTime_, mto, serviceDescription, unitID, type, newState, ownerId, newDateTime_, newAssignmentDeadlineDate, newAssignTeamMember, newAssignTeamMemberId, newAssignThirdPartyVendor, newAcceptDatetime, rejectDateTime, rejectReason, newStartWorkDateTime, newUnitOutOfServiceDate, newUnitOutOfServiceTime, newCompleteWorkDateTime, newUnitBackInServiceDate, newUnitBackInServiceTime, newCompleteWorkDetailDescription, newCompleteWorkDetailPreventable, newCompleteWorkDetailTMLabourHours, newCompleteWorkDetailTMCost, newCompleteWorkDetailTPVInvoiceNumber, newCompleteWorkDetailTPVInvoiceAmount, deleted, companyId, notes, ruleId, newMileage, newStartWorkMileage, newCompleteWorkMileage, newLibraryCategoriesId);

                    if (unitID.HasValue)
                    {
                        if (newState == "In Progress")
                        {
                            LiquiForce.LFSLive.BL.FleetManagement.Units.Units units = new LiquiForce.LFSLive.BL.FleetManagement.Units.Units(null);
                            units.UpdateStateDirect((int)unitID, companyId, "Out Of Service");
                        }

                        if (newState == "Completed")
                        {
                            LiquiForce.LFSLive.BL.FleetManagement.Units.Units units = new LiquiForce.LFSLive.BL.FleetManagement.Units.Units(null);
                            units.UpdateStateDirect((int)unitID, companyId, "Active");
                        }
                    }

                    // Update checklist
                    if (type == "Checklist")
                    {
                        // ... Original values
                        DateTime? originalAssociatedChecklistLastService = srManagerToolBasicInformationGateway.GetAssociatedChecklistLastServiceOriginal(serviceId);
                        DateTime? originalAssociatedChecklistNextDue = srManagerToolBasicInformationGateway.GetAssociatedChecklistNextDueOriginal(serviceId);
                        bool originalAssociatedChecklistDone = srManagerToolBasicInformationGateway.GetAssociatedChecklistDoneOriginal(serviceId);
                        bool originalAssociatedChecklistDeleted = srManagerToolBasicInformationGateway.GetAssociatedChecklistDeletedOriginal(serviceId);
                        int originalAssociatedChecklistCompanyId = srManagerToolBasicInformationGateway.GetAssociatedChecklistCompanyIdOriginal(serviceId);
                        string originalAssociatedChecklistRuleState = srManagerToolBasicInformationGateway.GetAssociatedChecklistRuleStateOriginal(serviceId);

                        // ... New values
                        DateTime? newAssociatedChecklistLastService = srManagerToolBasicInformationGateway.GetAssociatedChecklistLastService(serviceId);
                        DateTime? newAssociatedChecklistNextDue = srManagerToolBasicInformationGateway.GetAssociatedChecklistNextDue(serviceId);
                        bool newAssociatedChecklistDone = srManagerToolBasicInformationGateway.GetAssociatedChecklistDone(serviceId);
                        bool newAssociatedChecklistDeleted = srManagerToolBasicInformationGateway.GetAssociatedChecklistDeleted(serviceId);
                        int newAssociatedChecklistCompanyId = srManagerToolBasicInformationGateway.GetAssociatedChecklistCompanyId(serviceId);
                        string newAssociatedChecklistRuleState = srManagerToolBasicInformationGateway.GetAssociatedChecklistRuleState(serviceId);

                        // ... Update
                        Checklist checklist = new Checklist();
                        checklist.UpdateDirect((int)unitID, (int)ruleId, originalAssociatedChecklistLastService, originalAssociatedChecklistNextDue, originalAssociatedChecklistDone, originalAssociatedChecklistRuleState, originalAssociatedChecklistDeleted, originalAssociatedChecklistCompanyId, (int)unitID, (int)ruleId, newAssociatedChecklistLastService, newAssociatedChecklistNextDue, newAssociatedChecklistDone, newAssociatedChecklistRuleState, originalAssociatedChecklistDeleted, originalAssociatedChecklistCompanyId);
                    }
                }
            }
        }