示例#1
0
        public ActionResult CreateWaypoint(NewWaypointViewModel waypoint)
        {
            var trip = tripRepository
                .Query()
                .Include(t => t.Waypoints)
                .FirstOrDefault(t => t.Id == waypoint.TripId);

            if (trip == null)
            {
                return JsonResult(new {Success = false});
            }

            if (!ModelState.IsValid) {
                return JsonResult(new {Success = false, ModelState});
            }

            var entity = new Waypoint {
                TripId = waypoint.TripId,
                City = waypoint.City,
                State = waypoint.State,
                Passengers = new List<WaypointPassenger>(),
                Order = trip.Waypoints.Max(x=>x.Order) + 1
            };

            if (waypoint.PassengerIds != null)
            {
                foreach (var passengerId in waypoint.PassengerIds)
                {
                    entity.Passengers.Add(
                        new WaypointPassenger
                        {
                            TripId = waypoint.TripId,
                            PassengerId = passengerId
                        });
                }
            }

            waypointRepository.InsertOrUpdate(entity);
            waypointRepository.CommitChanges();

            return JsonResult(new {Success = true, entity});
        }
        private static List<Waypoint> GetWaypoints()
        {
            var wp1 = new Waypoint
            {
                Id = 1,
                Order = 1,
                Arriving = null,
                Airport = "KBTR",
                City = "Baton Rouge",
                State = "LA",
                Zip = "70817",
                Fbo = "Willie's FBO",
                Notes = "This is going to be awesome",
                Departing = DateTime.Now.AddDays(6).AddHours(-5),
                SpecialRequests = new List<WaypointRequest>
                {
                    //new WaypointRequest{Type = WaypointRequestType.Catering, Description = "Make me an Omlete", Notes = "Bacon!!"}
                }
            };

            var wp2 = new Waypoint
            {
                Id = 2,
                Order = 2,
                Arriving = DateTime.Now.AddDays(6).AddHours(-3),
                Airport = "STLK",
                Appointment = DateTime.Now.AddDays(1),
                AppointmentLocation = "Go to the bar",
                City = "Salt Lake City",
                State = "Utah",
                Zip = "12345",
                Fbo = "Willie's FBO",
                Notes = "This is going to be awesome",
                Departing = DateTime.Now.AddDays(9).AddHours(-5),
                SpecialRequests = new List<WaypointRequest>
                {
                    //new WaypointRequest{Type = WaypointRequestType.Catering, Description = "Make me an Omlete", Notes = "Bacon & Cheese!!"}
                }
            };

            var wp3 = new Waypoint
            {
                Id = 3,
                Order = 3,
                Arriving = DateTime.Now.AddDays(9).AddHours(-3),
                Airport = "KBTR",
                City = "Baton Rouge",
                State = "LA",
                Zip = "70817",
                Fbo = "Willie's FBO",
                Notes = "I'm coming home",
                Departing = null,
                SpecialRequests = new List<WaypointRequest>
                {
                    //new WaypointRequest{Type = WaypointRequestType.Catering, Description = "Make me an Omlete", Notes = "Bacon!!"}
                }
            };

            var entityList = new List<Waypoint>
            {
                wp1, wp2, wp3
            };

            return entityList;
        }