public Location MoveRecord(RobotMovementUi req)
        {
            Location newLocation = new Location(new Coordinate(req.CurrentLocation.Coordinate.XCoordinate, req.CurrentLocation.Coordinate.YCoordinate + 1), !req.CurrentLocation.DirectionFace.HasValue ? Enums.Direction.East : req.CurrentLocation.DirectionFace.Value);

            base.ValidateNewLocationForBoundariesThrowIfExceeded(newLocation, req.GridLength, req.GridWidth);

            newLocation = GetNewLocationIfObstacleFound(req, newLocation);

            return(newLocation);
        }
        public IHttpActionResult MoveRecord(RobotMovementUi model)
        {
            try
            {
                if (!IoC.IsRegistered <IRobotMovementProvider>(model.MoveDirection))
                {
                    throw new ApplicationException(model.MoveDirection + " implementation not found");
                }

                var newLocation = IoC.Resolve <IRobotMovementProvider>(model.MoveDirection).MoveRecord(model);

                return(Ok(new { NewLocation = newLocation }));
            }
            catch (Exception ex)
            {
                _log.Error("Error in MoveRecord() ", ex);
                return(BadRequest(ex.Message));
            }
        }
        public Location GetNewLocationIfObstacleFound(RobotMovementUi req, Location newLocation)
        {
            var key = new Tuple <int, int>(newLocation.Coordinate.XCoordinate, newLocation.Coordinate.YCoordinate);

            if (req.Obstacledic != null && req.Obstacledic.ContainsKey(key))
            {
                var behaviourLink = GetObstacleBehaviourForRobot(req.RobotCode, req.Obstacledic[key].Obstacle.Code);

                if (!IoC.IsRegistered <IObstacleBehaviourProvider>(behaviourLink.ObstacleBehaviourCode))
                {
                    throw new ApplicationException("Obstacle Bheaviour " + behaviourLink.ObstacleBehaviourDescription + " not implemented for obstacle " + behaviourLink.ObstacleName);
                }

                newLocation = IoC.Resolve <IObstacleBehaviourProvider>(behaviourLink.ObstacleBehaviourCode).GetNewLocation(new ObstacleBehaviourRequest()
                {
                    RobotCurrentLocation = newLocation, RobotInitialLocation = req.InitialLocation
                });
            }

            return(newLocation);
        }