Beispiel #1
0
        public void AddRoute()
        {
            StringBuilder actual = new StringBuilder();

            Delivery delivery = Delivery.CreateDelivery(Inputs.ExampleInput, 3, 10);
            Path     path     = new Path(new Cell(8, 12), delivery.Grid);

            Route currentRoute = path.MapRoute(Route.Specs.Route);

            Cell   cell       = new Cell(14, 17);
            Packet gridPacket = delivery.Grid.GetPacket(cell);

            actual.Append(delivery.Grid.GetPacket(cell).CurrentState.ToString() + ";");
            actual.Append(delivery.Grid.GetPacket(cell).Distance + "°");

            Path  newRoutePath = new Path(cell, delivery.Grid, currentRoute.ReachCell);
            Route newRoute     = newRoutePath.MapRoute(Route.Specs.Route);

            actual.Append(gridPacket.CurrentState.ToString() + ";");
            actual.Append(gridPacket.Distance + ";");

            currentRoute.AddRoute(newRoute);

            actual.Append(gridPacket.CurrentState.ToString() + ";");
            actual.Append(gridPacket.Distance + ";");
            actual.Append(currentRoute?.ToString() ?? "null");

            Write.Trace($"{actual.ToString()}");

            string expected = "Pending;0°Assigned;11;Assigned;19;StartCell:R4C16 ReachCell:R14C17 Cells:R5C16(Down);R6C16(Down);R7C16(Down);R8C16(Down);R8C15(Left);R8C14(Left);R8C13(Left);R8C12(Left);R9C12(Down);R10C12(Down);R11C12(Down);R12C12(Down);R13C12(Down);R14C12(Down);R14C13(Right);R14C14(Right);R14C15(Right);R14C16(Right);R14C17(Right) Packets:R8C12(8);R14C17(19) MaxPackets:3 Distance:19";

            Assert.AreEqual(expected, actual.ToString());
        }
        public IHttpActionResult Post([FromBody] string jsonString)
        {
            Route routeObject = JsonConvert.DeserializeObject <Route>(jsonString);

            routeObject.AddRoute(routeObject);

            return(Ok());
        }
        public IHttpActionResult LogSession(TrainingSessionModel model)
        {
            TrainingSession sessionModel = new TrainingSession();
            Route           routeModel   = new Route();
            Location        locationModel;

            #region From Json to Model (Route)
            routeModel.CityID    = Utility.GetCityID(model.CityName, Utility.GetCountryID(model.CountryName));
            routeModel.ID_Route  = model.RouteID;
            routeModel.RouteName = model.RouteName;
            routeModel.FillLocationList(model);
            #endregion

            #region From Json to Model (Training Session)
            sessionModel.AverageBPM         = model.AverageBPM;
            sessionModel.BurntCalories      = model.BurntCalories;
            sessionModel.ClimateConditionID = Utility.GetClimateConditionID(model.ClimateConditionID);
            sessionModel.Distance           = model.Distance;
            sessionModel.EndTime            = model.EndTime;
            sessionModel.RelativeHumidity   = model.RelativeHumidity;
            sessionModel.RouteID            = model.RouteID;
            sessionModel.SessionID          = model.SessionID;
            sessionModel.SessionStatusID    = Utility.GetSessionStatusID(model.SessionStatusID);
            sessionModel.StartTime          = model.StartTime;
            sessionModel.Temperature        = model.Temperature;
            sessionModel.TrainingTypeID     = Utility.GetTrainingTypeID(model.TrainingTypeID);
            sessionModel.UserID             = model.UserID;
            #endregion


            routeModel.AddRoute();
            foreach (var item in routeModel.LocationList)
            {
                locationModel              = new Location();
                locationModel.ID_Route     = item.ID_Route;
                locationModel.isEndPoint   = item.isEndPoint;
                locationModel.isStartPoint = item.isStartPoint;
                locationModel.isMilestone  = item.isMilestone;
                locationModel.Latitude     = item.Latitude;
                locationModel.Longitude    = item.Longitude;

                locationModel.AddLocation();
            }


            var response = sessionModel.AddSession();

            if (response.IsComplete())
            {
                return(Ok(response.Body));
            }
            else
            {
                return(BadRequest(response.Message));
            }
        }