示例#1
0
        public IHttpActionResult SearchBus(string busNo)
        {
            try
            {
                BusViewModel busViewModel = new BusViewModel();
                Bus buses = new Bus();
                buses = _commonData.SearchBuses(busNo).FirstOrDefault();
                if (buses != null)
                {
                    busViewModel.id = buses.ID;
                    busViewModel.busNo = buses.LicenceNo;
                    busViewModel.route = new RouteViewModel();
                    busViewModel.route.id = buses.Route.ID;
                    busViewModel.route.routeNo = buses.Route.RouteNo;
                    busViewModel.route.from = buses.Route.From;
                    busViewModel.route.to = buses.Route.To;
                }

                var messageData = new { code = Constant.SuccessMessageCode, message = Constant.MessageSuccess };
                var returnObject = new { bus = busViewModel, messageCode = messageData };
                return Ok(returnObject);
            }
            catch (Exception ex)
            {
                string errorLogId = _eventLog.WriteLogs(User.Identity.Name, ex, MethodBase.GetCurrentMethod().Name);
                var messageData = new { code = Constant.ErrorMessageCode, message = String.Format(Constant.MessageTaskmateError, errorLogId) };
                var returnObject = new { messageCode = messageData };
                return Ok(returnObject);
            }
        }