Exemple #1
0
        public ActionResult TripsWork(TripViewModel tripVm, string submitButton)
        {
            TripsViewModel model;

            if (ModelState.IsValid)
            {
                var tripModel   = modelBuilder.BuildTripModel(tripVm);
                var userMessage = "";

                try
                {
                    switch (submitButton)
                    {
                    case "Create":
                        userMessage = adminService.CreateTrip(tripModel).Message;
                        break;

                    case "Update":
                        userMessage = adminService.UpdateTrip(tripModel).Message;
                        break;

                    case "Delete":
                        userMessage = adminService.DeleteTrip(tripModel).Message;
                        break;

                    default:
                        throw new NotSupportedException();
                    }
                    TempData["message"] = userMessage;
                }
                catch (PassengersCarriageValidationException e)
                {
                    ModelState.AddModelError(String.Empty, e.Message);
                }

                model = GetAllTrips();
            }
            else
            {
                model = GetAllTrips();

                if (tripVm.Id == 0)
                {
                    modelBuilder.RebuildNewInvalidViewModel(model, tripVm);
                }
                else
                {
                    modelBuilder.RebuildOldItemsInvalidViewModel(model, tripVm);
                }
            }

            return(View(model));
        }