Esempio n. 1
0
        public ActionResult Trips_Create([DataSourceRequest]DataSourceRequest request, TripGridInputModel trip)
        {
            var newId = 0;
            if (this.ModelState.IsValid)
            {
                var from = this.locations.GetAll().FirstOrDefault(x => x.Name == trip.From);
                var to = this.locations.GetAll().FirstOrDefault(x => x.Name == trip.To);

                var entity = new Trip
                {
                    FromId = from.Id,
                    ToId = to.Id,
                    AvailableSeats = trip.AvailableSeats,
                    StartDate = trip.StartDate,
                    Description = trip.Description
                };

                this.trips.Create(entity);
                newId = entity.Id;
            }

            var tripToDisplay = this.trips
                .GetAll()
                .To<TripGridViewModel>()
                .FirstOrDefault(x => x.Id == newId);

            return this.Json(new[] { tripToDisplay }.ToDataSourceResult(request, this.ModelState));
        }
Esempio n. 2
0
        public ActionResult Trips_Update([DataSourceRequest]DataSourceRequest request, TripGridInputModel trip)
        {
            if (this.ModelState.IsValid)
            {
                var from = this.locations.GetAll().FirstOrDefault(x => x.Name == trip.From);
                var to = this.locations.GetAll().FirstOrDefault(x => x.Name == trip.To);

                var entity = this.trips.GetAll().FirstOrDefault(x => x.Id == trip.Id);
                entity.FromId = from.Id;
                entity.ToId = to.Id;
                entity.AvailableSeats = trip.AvailableSeats;
                entity.Description = trip.Description;
                entity.StartDate = trip.StartDate;
                this.trips.Update(entity);
            }

            return this.Json(new[] { trip }.ToDataSourceResult(request, this.ModelState));
        }