private void ValidationSuccess(WorkPacket workPacket, WorkRequest workRequest)
        {
            //add to tracking
            AddStormsTracking(workRequest, workPacket, "FOBATCH", "FODATCHK", "Forestry data validation Passed");

            //convert STORMS into forestry model
            Forestry.Models.ForestryRequest forestry = MapToForestry(workRequest, workPacket);

            //add to tracking
            AddStormsTracking(workRequest, workPacket, "FOBATCH", "FOCREATE", "Forestry order creation request sent");

            //send to Forestry to MQ
            ProcessForestry(workRequest, workPacket, forestry);
        }
        public ForestryRequest MapToForestry(Models.DTO.WorkRequest workRequest, Models.DTO.WorkPacket workPacket)
        {
            Console.WriteLine("[WR:" + workPacket.WorkRequestId + " " + "WP:" + workPacket.WorkPacketId + "][BEGIN--]-converting WorkRequest into Forestry Job");

            Forestry.Models.ForestryRequest forestry = new Forestry.Models.ForestryRequest();

            forestry.CorellationId = Guid.NewGuid().ToString();
            //REQUIRED
            forestry.Timestamp = DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ssZ");
            //REQUIRED
            forestry.Origin       = new CodeModel();
            forestry.Origin.Value = "STORMS";
            //REQUIRED
            forestry.Method = "POST";

            //REQUIRED
            forestry.Model    = new Models.Forestry();
            forestry.Model.Id = ((long)workRequest.Id).ToString();
            DateTime dateValue;

            if (DateTime.TryParse(workRequest.RequiredDate, out dateValue))
            {
                forestry.Model.WantedDate = DateTime.Parse(workRequest.RequiredDate).ToString("yyyy-MM-ddTHH:mm:ssZ");
            }
            forestry.Model.FinancialDetails          = new FinancialDetails();
            forestry.Model.FinancialDetails.IoNumber = Convert.ToInt32(workRequest.IoInstallation);

            forestry.Model.GeographicDetails      = new GeographicDetails();
            forestry.Model.GeographicDetails.Area = workRequest.CrewHeadquarter;

            forestry.Model.Type       = new Models.Type();
            forestry.Model.Type.Value = workRequest.JobType;

            forestry.Model.Contact              = new Contact();
            forestry.Model.Contact.Name         = workRequest.ContactName;
            forestry.Model.Contact.PhoneNumbers = new List <PhoneNumber>();
            long contactPhoneResult;

            forestry.Model.Contact.PhoneNumbers.Add(new PhoneNumber
            {
                Number    = (long.TryParse(workRequest.ContactPhone, out contactPhoneResult) == true) ? contactPhoneResult : 0,
                IsDefault = true,
            });

            if (workRequest.Customers != null && workRequest.Customers.Count > 0)
            {
                forestry.Model.Customer      = new Models.Customer();
                forestry.Model.Customer.Name = workRequest.Customers[0].Name;

                if (!string.IsNullOrEmpty(workRequest.Customers[0].Phones.Number))
                {
                    forestry.Model.Customer.PhoneNumbers = new List <PhoneNumber>();
                    long extentionRemoved = 0;
                    if (workRequest.Customers[0].Phones.Number.IndexOf(" ") > 0)
                    {
                        extentionRemoved =
                            Convert.ToInt64(
                                ((string)workRequest.Customers[0].Phones.Number).Substring(
                                    0,
                                    workRequest.Customers[0].Phones.Number.IndexOf(" ")
                                    )
                                );
                    }
                    else
                    {
                        extentionRemoved = Convert.ToInt64(workRequest.Customers[0].Phones.Number);
                    }

                    string extention = string.Empty;
                    if (workRequest.Customers[0].Phones.Number.IndexOf(" ") > 0)
                    {
                        extention =
                            ((string)workRequest.Customers[0].Phones.Number).Substring(
                                workRequest.Customers[0].Phones.Number.IndexOf(" "),
                                workRequest.Customers[0].Phones.Number.Length - workRequest.Customers[0].Phones.Number.IndexOf(" ")
                                );
                    }

                    forestry.Model.Customer.PhoneNumbers.Add(new PhoneNumber
                    {
                        Number                = extentionRemoved,
                        IsDefault             = true,
                        AdditionalInformation = extention
                    });
                }
            }

            forestry.Model.Location         = new Location();
            forestry.Model.Location.Address = new Models.Address();
            forestry.Model.Location.Address.StreetNumber  = workRequest.Address.StreetNumber != null ? workRequest.Address.StreetNumber : string.Empty;
            forestry.Model.Location.Address.StreetAddress = workRequest.Address.StreetPrefix != null ? workRequest.Address.StreetPrefix : string.Empty;
            forestry.Model.Location.Address.StreetAddress =
                workRequest.Address.StreetName != null
                    ? forestry.Model.Location.Address.StreetAddress + " " + workRequest.Address.StreetName
                    : forestry.Model.Location.Address.StreetAddress;
            forestry.Model.Location.Address.StreetAddress =
                workRequest.Address.StreetType != null
                    ? forestry.Model.Location.Address.StreetAddress + " " + workRequest.Address.StreetType
                    : forestry.Model.Location.Address.StreetAddress;
            forestry.Model.Location.Address.StreetAddress =
                workRequest.Address.StreetSuffix != null
                    ? forestry.Model.Location.Address.StreetAddress + " " + workRequest.Address.StreetSuffix
                    : forestry.Model.Location.Address.StreetAddress;
            forestry.Model.Location.Address.City             = workRequest.Address.City;
            forestry.Model.Location.Address.State            = workRequest.Address.State;
            forestry.Model.Location.Address.County           = workRequest.Address.County;
            forestry.Model.Location.Address.PostalCode       = workRequest.Address.Zip;
            forestry.Model.Location.Address.FormattedAddress = workRequest.Address.FreeFormat;

            forestry.Model.GeographicDetails             = new GeographicDetails();
            forestry.Model.GeographicDetails.XCoordinate = workRequest?.Geo?.XCoordinate;
            forestry.Model.GeographicDetails.YCoordinate = workRequest?.Geo?.YCoordinate;

            if (workRequest.Geo != null)
            {
                forestry.Model.GeographicDetails.Area = workRequest?.Geo?.Zone;
            }

            forestry.Model.Origin = new Origin();
            //REQUIRED
            forestry.Model.Origin.Company       = new Company();
            forestry.Model.Origin.Company.Value = "30";
            //REQUIRED
            forestry.Model.Origin.OriginOrderTimestamp = DateTime.Parse(workRequest.RequiredDate).ToString("yyyy-MM-ddTHH:mm:ssZ");
            //REQUIRED
            //forestry.Model.Origin.OriginSystem = "STORMS";
            forestry.Model.Origin.OriginSystem = GetOrigin(workRequest);

            //REQUIRED
            forestry.Model.Origin.OriginSystemId = ((long)workRequest.Id).ToString();

            if (workRequest.Premises != null && workRequest.Premises.Count > 0)
            {
                forestry.Model.Origin.PremiseId = workRequest.Premises[0].PremiseId;
            }

            if (workRequest.ExtraDetails != null)
            {
                forestry.Model.Origin.FeederNumber = workRequest.ExtraDetails.FeederId;
                forestry.Model.Origin.Voltage      = workRequest.ExtraDetails.ServiceVoltageCode;
            }

            if (workRequest.Remarks != null && workRequest.Remarks.Count > 0)
            {
                foreach (var item in workRequest.Remarks)
                {
                    forestry.Model.Comments += item.Type + " " + item.RemarkText;
                }
            }

            Console.WriteLine("[WR:" + workPacket.WorkRequestId + " " + "WP:" + workPacket.WorkPacketId + "][SUCCESS]-converted WorkRequest into Forestry Job");

            return(forestry);
        }