public HttpResponseMessage SaveHub([FromBody] Hub hub)
 {
     try
     {
         var result = sarfDao.SaveHub(hub);
         return(WrapObjectToHttpResponse(result));
     }
     catch (Exception ex)
     {
         throw new Exception("Error : " + ex.Message);
     }
 }
Example #2
0
        private int SaveHubs(List <List <decimal> > points, Polygon polygon)
        {
            List <decimal> vertex = new List <decimal>();

            pointsToReject = new List <List <decimal> >();
            hubs           = new List <Hub>();
            hubIDList      = new List <long>();
            int midIndex = points.Count / 2;

            if (points.Count == 1)
            {
                Hub    hub          = null;
                Random random       = new Random(1000);
                var    randomNumber = random.Next(9999).ToString();
                vertex = points[0];
                pointsToReject.Add(vertex);
                hub = new Hub
                {
                    SarfId      = currentSarfId,
                    Latitude    = vertex[1], // decMaxLat,
                    Longitude   = vertex[0], //decMaxLong,
                    Address     = "SITE SF-" + currentSarfId + "-0" + randomNumber,
                    DateCreated = DateTime.Now,
                    HubType     = ResourceConstants.HubType_Macro
                };
                hubs.Add(hub);
            }
            else
            {
                Hub    hub          = null;
                Random random       = new Random(1000);
                var    randomNumber = random.Next(9999).ToString();
                vertex = points[0];
                pointsToReject.Add(vertex);
                hub = new Hub
                {
                    SarfId      = currentSarfId,
                    Latitude    = vertex[1], // decMaxLat,
                    Longitude   = vertex[0], //decMaxLong,
                    Address     = "SITE SF-" + currentSarfId + "-0" + randomNumber,
                    DateCreated = DateTime.Now,
                    HubType     = ResourceConstants.HubType_Macro
                };
                hubs.Add(hub);

                randomNumber = random.Next(9999).ToString();
                vertex       = points[midIndex - 4];
                pointsToReject.Add(vertex);
                hub = new Hub
                {
                    SarfId      = currentSarfId,
                    Latitude    = vertex[1], // decMaxLat,
                    Longitude   = vertex[0], //decMaxLong,
                    Address     = "SITE SF-" + currentSarfId + "-0" + randomNumber,
                    DateCreated = DateTime.Now,
                    HubType     = ResourceConstants.HubType_Central_Office
                };
                hubs.Add(hub);

                if (midIndex > 1)
                {
                    randomNumber = random.Next(9999).ToString();
                    vertex       = points[midIndex];
                    pointsToReject.Add(vertex);
                    hub = new Hub
                    {
                        SarfId      = currentSarfId,
                        Latitude    = vertex[1], // decMaxLat,
                        Longitude   = vertex[0], //decMaxLong,
                        Address     = "SITE SF-" + currentSarfId + "-0" + randomNumber,
                        DateCreated = DateTime.Now,
                        HubType     = ResourceConstants.HubType_Macro
                    };
                    hubs.Add(hub);

                    randomNumber = random.Next(9999).ToString();
                    vertex       = points[midIndex + 4];
                    pointsToReject.Add(vertex);
                    hub = new Hub
                    {
                        SarfId      = currentSarfId,
                        Latitude    = vertex[1], // decMaxLat,
                        Longitude   = vertex[0], //decMaxLong,
                        Address     = "SITE SF-" + currentSarfId + "-0" + randomNumber,
                        DateCreated = DateTime.Now,
                        HubType     = ResourceConstants.HubType_MTSO
                    };
                    hubs.Add(hub);
                }

                randomNumber = random.Next(9999).ToString();
                vertex       = points[points.Count - 2];
                pointsToReject.Add(vertex);
                hub = new Hub
                {
                    SarfId      = currentSarfId,
                    Latitude    = vertex[1], // decMaxLat,
                    Longitude   = vertex[0], //decMaxLong,
                    Address     = "SITE SF-" + currentSarfId + "-0" + randomNumber,
                    DateCreated = DateTime.Now,
                    HubType     = ResourceConstants.HubType_Central_Office
                };
                hubs.Add(hub);

                randomNumber = random.Next(9999).ToString();
                vertex       = points[points.Count - 1];
                pointsToReject.Add(vertex);
                hub = new Hub
                {
                    SarfId      = currentSarfId,
                    Latitude    = vertex[1], // decMaxLat,
                    Longitude   = vertex[0], //decMaxLong,
                    Address     = "SITE SF-" + currentSarfId + "-0" + randomNumber,
                    DateCreated = DateTime.Now,
                    HubType     = ResourceConstants.HubType_MTSO
                };
                hubs.Add(hub);
            }
            foreach (var hubItem in hubs)
            {
                hubIDList.Add(sarfDao.SaveHub(hubItem));
            }
            hubRejectList = new List <long>();
            hubRejectList.AddRange(new List <long> {
                hubIDList[1], hubIDList[3], hubIDList[4]
            });
            hubIDList = hubIDList.Except(hubRejectList).ToList();
            if (isValidArea)
            {
                return(GenerateNodes(polygon));
            }
            return(0);
        }