Example #1
0
        public GetRoverPositionResponseObject GetRoverPosition(GetRoverPositionRequestObject requestObject)
        {
            GetRoverPositionResponseObject responseObject = new GetRoverPositionResponseObject();
            Position position = new Position();

            if (!requestObject.IsValid())
            {
                responseObject.Message = "The request body was invalid";
                return(responseObject);
            }
            Rover rover = roverRepository.SingleOrDefault(m => m.Id == requestObject.RoverId);

            if (rover != null)
            {
                position.PosX = rover.PosX;
                position.PosY = rover.PosY;
                responseObject.CurrentPosition = position.getResponseString();
                responseObject.Message         = "Your rover was found";
            }
            else
            {
                responseObject.Message = "The requested RoverId does not exist";
            }
            return(responseObject);
        }
        // GET
        public IHttpActionResult Get(string RoverId)
        {
            GetRoverPositionResponseObject responseObject = new GetRoverPositionResponseObject();

            try
            {
                GetRoverPositionRequestObject requestObject = new GetRoverPositionRequestObject();
                requestObject.RoverId = RoverId;
                responseObject        = business.GetRoverPosition(requestObject);
            }
            catch (Exception e)
            {
                responseObject.Message = "Something unexpected happened: " + e.Message;
            }
            return(Ok(responseObject));
        }