示例#1
0
        public ActionResult CreateRoute(RouteViewModel model, List <TransitionalViewModel> modelItem)
        {
            try {
                var train = new TrainDTO
                {
                    Number           = model.Number,
                    DepartureStation = model.DepartureStation,
                    ArrivalStation   = model.ArrivalStation,
                    Departure        = model.Departure,
                    Seats            = model.Seats.Select(s => new SeatDTO {
                        Type     = s.Type,
                        Quantity = s.Quantity,
                        Price    = s.Price
                    }).Where(q => q.Quantity > 0).ToList()
                };
                var stopovers = modelItem.Select(m => new StopoverDTO {
                    StopStation = m.StopStation,
                    Departure   = m.Departure,
                    Arrival     = m.Arrival
                }).ToList();
                rs.AddRoute(train, stopovers, model.SelectedRoute);
                Unit.Save();
                Unit.Dispose();

                return(RedirectToAction("AvailableTrains"));
            }
            catch (Exception ex)
            {
                return(View(ex.Message));
            }
        }
示例#2
0
        public ResponseResult AddRoute(string loginName, string routeName, string points)
        {
            var          result       = ResponseResult.Default();
            RouteService routeservice = new RouteService();

            try
            {
                if (string.IsNullOrEmpty(routeName))
                {
                    return(ResponseResult.Error("路径名称不能为空"));
                }
                if (string.IsNullOrEmpty(points))
                {
                    return(ResponseResult.Error("点不能为空"));
                }
                if (string.IsNullOrEmpty(loginName))
                {
                    return(ResponseResult.Error("登录名称不能为空"));
                }
                if (routeservice.AddRoute(loginName, routeName, points))
                {
                    return(ResponseResult.Success("添加成功"));
                }
                else
                {
                    return(ResponseResult.Error("添加失败"));
                }
            }
            catch (System.Exception ex)
            {
                result = ResponseResult.Error(ex.Message);
            }
            return(result);
        }