private void UpdateSites()
        {
            _logger.Information("Updating Sites");
            SiteDal  dal        = new SiteDal(_configuration, _logger);
            DateTime?lastUpdate = dal.GetLastAdded();

            if (lastUpdate == null || lastUpdate.Value.Year == 0)
            {
                InitialiseSites();
            }
            else
            {
                IEnumerable <SiteModel> siteModels = new SOAPHelper(_autotaskApiUsername, _autotaskApiPassword, _autotaskApiIntegrationCode, _autotaskApiUrl, _logger)
                                                     .RetrieveNewSites(lastUpdate.Value);
                if (siteModels != null &&
                    siteModels.Count() > 0)
                {
                    _logger.Information($"{siteModels.Count()} new Sites found");
                }
                {
                    foreach (SiteModel site in siteModels)
                    {
                        Domain.Enums.CRUDEnums.ActionResult actionResult = dal.Put(site).GetAwaiter().GetResult();
                    }
                }
            }
        }
        private void UpdateTickets()
        {
            _logger.Information("Updating Tickets");
            TicketDal dal        = new TicketDal(_configuration, _logger);
            DateTime? lastUpdate = dal.GetLastUpdated();

            if (lastUpdate == null || lastUpdate.Value.Year == 0)
            {
                _logger.Information("No tickets found trying initalisation");
                InitialiseTickets();
            }
            else
            {
                IEnumerable <TicketModel> ticketModels = new SOAPHelper(_autotaskApiUsername, _autotaskApiPassword, _autotaskApiIntegrationCode, _autotaskApiUrl, _logger)
                                                         .RetriveUpdatedTickets(lastUpdate.Value);
                if (ticketModels != null &&
                    ticketModels.Count() > 0)
                {
                    _logger.Information($"{ticketModels.Count()} updated Tickets found");
                    Domain.Enums.CRUDEnums.ActionResult actionResult = dal.PutOrPost(ticketModels).GetAwaiter().GetResult();
                }
            }
        }
        private void InitialiseTypes()
        {
            _logger.Information("Initialising Types");
            DatabaseHelper databaseHelper = new DatabaseHelper(_remoteAutoTaskDatabaseConnection);

            Domain.Enums.CRUDEnums.ActionResult actionResult = Domain.Enums.CRUDEnums.ActionResult.Success;
            TypesDal dal = new TypesDal(_configuration);

            try
            {
                IEnumerable <PriorityTypePOCO> priorityTypePOCOs = databaseHelper.GetPriorityType();
                if (priorityTypePOCOs != null && priorityTypePOCOs.Count() > 0)
                {
                    _logger.Information($"{priorityTypePOCOs.Count()} Priority Types Found");
                    IEnumerable <PriorityTypeModel> priorityTypes = from priority in priorityTypePOCOs
                                                                    select new PriorityTypeModel()
                    {
                        Id        = priority.Priority_Id,
                        IsActive  = priority.Is_Active,
                        Name      = priority.Priority_Name,
                        SortOrder = priority.Sort_Order
                    };

                    actionResult = dal.AddOrReplacePriorityTypes(priorityTypes).GetAwaiter().GetResult();
                    _logger.Information("Priority Types Inserted");
                }
            }
            catch (Exception ex)
            {
                _logger.Error(ex, "Failed intialising Priority Types");
            }

            try
            {
                IEnumerable <TicketTypePOCO> ticketTypePOCOs = databaseHelper.GetTicketType();

                if (ticketTypePOCOs != null && ticketTypePOCOs.Count() > 0)
                {
                    _logger.Information($"{ticketTypePOCOs.Count()} Ticket Types Found");
                    IEnumerable <TicketTypeModel> ticketTypes = from ticketTypePOCO in ticketTypePOCOs
                                                                select new TicketTypeModel()
                    {
                        Id   = ticketTypePOCO.Task_Type_Id,
                        Name = ticketTypePOCO.Task_Type_Name
                    };
                    actionResult = dal.AddOrReplaceTicketType(ticketTypes).GetAwaiter().GetResult();
                    _logger.Information("Ticket Types Inserted");
                }
            }


            catch (Exception ex)
            {
                _logger.Error(ex, "Failed intialising Ticket Types");
            }


            try
            {
                IEnumerable <TaskStatusPOCO> taskStatusPOCOs = databaseHelper.GetTaskStatus();

                if (taskStatusPOCOs != null && taskStatusPOCOs.Count() > 0)
                {
                    _logger.Information($"{taskStatusPOCOs.Count()} Task Statuses Found");
                    IEnumerable <TaskStatusModel> taskStatuses = from taskStatusPOCO in taskStatusPOCOs
                                                                 select new TaskStatusModel()
                    {
                        Id       = taskStatusPOCO.Task_Status_Id,
                        IsActive = taskStatusPOCO.Is_Active,
                        IsSystem = taskStatusPOCO.Is_System,
                        ServiceLevelAgreementEventTypeCode = taskStatusPOCO.Service_Level_Agreement_Event_Type_Code,
                        SortOrder      = taskStatusPOCO.Sort_Order,
                        TaskStatusName = taskStatusPOCO.Task_Status_Name
                    };
                    actionResult = dal.AddOrReplaceTaskStatuss(taskStatuses).GetAwaiter().GetResult();
                    _logger.Information("Task Statuses Inserted");
                }
            }

            catch (Exception ex)
            {
                _logger.Error(ex, "Failed intialising Task Statuses");
            }
            databaseHelper = null;
        }