Ejemplo n.º 1
0
        public HttpResponseMessage Create(HttpRequestMessage request, RouterViewModel routeVm)
        {
            return(CreateHttpResponse(request, () =>
            {
                HttpResponseMessage response = null;
                if (!ModelState.IsValid)
                {
                    response = request.CreateResponse(HttpStatusCode.BadRequest, ModelState);
                }
                else
                {
                    var newRoute = new Router();
                    newRoute.UpdateRoute(routeVm);
                    newRoute.CreatedDate = DateTime.Now;

                    _routeService.Add(newRoute);
                    _routeService.Save();

                    var responseData = Mapper.Map <Router, RouterViewModel>(newRoute);
                    response = request.CreateResponse(HttpStatusCode.Created, responseData);
                }

                return response;
            }));
        }
Ejemplo n.º 2
0
        public ActionResult Add(RouteViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            _routeService.Add(Mapper.Map <RouteModel>(model));
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 3
0
 public ActionResult <Route> AddRoute(Route route)
 {
     try
     {
         IQueryable <Route> query = _routeService.GetByTravelId(route.TravelId);
         if (query != null)
         {
             route.RouteId = query.ToList().First().RouteId + 1;
         }
         else
         {
             route.RouteId = route.TravelId * 100 + 1;
         }
         _routeService.Add(route);
     }
     catch (Exception e)
     {
         return(BadRequest(e.InnerException.Message));
     }
     return(route);
 }