public IActionResult AddTrip() { var model = new AddTripViewModel(); model.StartDate = DateTime.Now; return(View(model)); }
protected override void OnAppearing() { _viewModel.IsBusy = true; base.OnAppearing(); AddTripViewModel.GetNamesPreferredGendersEnum(); _viewModel.IsBusy = false; }
public HttpResponse Add(AddTripViewModel trip) { if (!this.IsUserLoggedIn()) { return(this.Redirect("/Users/Login")); } if (string.IsNullOrWhiteSpace(trip.StartPoint) || string.IsNullOrWhiteSpace(trip.EndPoint) || trip.DepartureTime == null) { return(this.Redirect("/Trips/Add")); } if (trip.Seats < MinSeatsCapacity || trip.Seats > MaxSeatsCapacity) { return(this.Redirect("/Trips/Add")); } if (trip.Description.Length > MaxDescriptionLength) { return(this.Redirect("/Trips/Add")); } this.tripsService.Add(trip.StartPoint, trip.EndPoint, trip.DepartureTime, trip.Seats, trip.Description, trip.ImagePath); return(this.Redirect("/Trips/All")); }
public HttpResponse Add(AddTripViewModel model) { var modelErrors = this.validator.ValidateTripCreation(model); if (modelErrors.Any()) { return(Error(modelErrors)); } var parsedDate = DateTime.Parse(model.DepartureTime); var trip = new Trip { StartPoint = model.StartPoint, EndPoint = model.EndPoint, DepartureTime = parsedDate, Seats = model.Seats, Description = model.Description, ImagePath = model.ImagePath }; this.data.Trips.Add(trip); this.data.SaveChanges(); return(Redirect("/Trips/All")); }
public ICollection <string> ValidateTripCreation(AddTripViewModel model) { var errors = new List <string>(); if (string.IsNullOrWhiteSpace(model.StartPoint)) { errors.Add("Invalid start point"); } if (string.IsNullOrWhiteSpace(model.EndPoint)) { errors.Add("Invalid start point"); } if (string.IsNullOrWhiteSpace(model.DepartureTime)) { errors.Add("Invalid departure time"); } if (model.Seats < 2 || model.Seats > 6) { errors.Add("Seats must be between 2 and 6."); } if (string.IsNullOrWhiteSpace(model.Description) || model.Description.Length > 80) { errors.Add("Description is required and can be up to 80 characters long."); } return(errors); }
public HttpResponse Add(AddTripViewModel input) { if (!this.IsUserSignedIn()) { return(this.Redirect("/Users/Login")); } if (string.IsNullOrEmpty(input.StartPoint)) { return(this.Error("Invalid start point.")); } if (string.IsNullOrEmpty(input.EndPoint)) { return(this.Error("Invalid end point.")); } if (input.Seats < 2 || input.Seats > 6) { return(this.Error("Invalid count seats.")); } if (string.IsNullOrEmpty(input.Description) || input.Description.Length > 80) { return(this.Error("Invalid description")); } this.tripsService.Add(input); return(this.Redirect("/Trips/All")); }
public IEnumerable <string> TripsValidator(AddTripViewModel input) { if (input.StartPoint == null) { this.errorMessage.Add(string.Format(REQUIRED, "model")); } if (input.EndPoint == null) { this.errorMessage.Add(string.Format(REQUIRED, "model")); } if (input.Description == null) { this.errorMessage.Add(string.Format(REQUIRED, "model")); } if (input.DepartureTime == null) { this.errorMessage.Add(string.Format(REQUIRED, "model")); } if (input.Seats < 2 || input.Seats > 6) { this.errorMessage.Add(string.Format(REQUIRED, "model")); } if (input.Description.Length > 80) { this.errorMessage.Add(string.Format(REQUIRED, "model")); } return(this.errorMessage); }
public IActionResult Index() { AddTripViewModel addTripViewModel = new AddTripViewModel(); return(View(addTripViewModel)); }
public AddTripPage() { InitializeComponent(); _network = App.Container.Resolve <INetwork>(); _viewModel = new AddTripViewModel(); BindingContext = _viewModel; }
public IActionResult AddTrip() { //List<State> statelist = new List<State>(); AddTripViewModel trip = new AddTripViewModel(); return(View(trip)); }
public async Task <IActionResult> AddTrip(AddTripViewModel vm) { if (!ModelState.IsValid) { return(View(vm)); } try { var user = await UserManager.GetUserAsync(HttpContext.User); String userId = user?.Email; if (!dal.CheckTripDate(vm.StartDate, vm.EndDate, userId)) { return(View(vm)); } var client = new HttpClient(); StringBuilder sb = new StringBuilder(); sb.Append("https://maps.googleapis.com/maps/api/geocode/json?address="); sb.Append(vm.City); sb.Append(','); sb.Append(vm.Country); sb.Append("&key=AIzaSyA_Pvo7XDp6VZt8NTSZ_URxxqpUKaypOtY"); var uri = new Uri(sb.ToString()); var response = await client.GetStringAsync(uri); RootObject content = JsonConvert.DeserializeObject <RootObject>(response); if (content.results.Count == 0) { return(View(vm)); } else { int countryid = 0; for (int i = 0; i < content.results[0].address_components.Count(); i++) { if (content.results[0].address_components[i].types[0].Equals("country")) { countryid = i; break; } } if (!vm.Country.ToUpper().Equals((content.results[0].address_components[countryid].long_name).ToUpper()) || !vm.City.ToUpper().Equals((help.TranslateAccent(content.results[0].address_components[0].long_name)).ToUpper())) { return(View(vm)); } else { int locationid = dal.AddTravelLocation(content.results[0].geometry.location.lat, content.results[0].geometry.location.lng, content.results[0].address_components[0].long_name, content.results[0].address_components[countryid].long_name); dal.AddUserTrip(locationid, vm.TripName, userId, vm.StartDate, vm.EndDate, vm.Budget); } } }catch (Exception ex) { return(View(vm)); } return(RedirectToAction("Index", "Home")); }
public HttpResponse Add(AddTripViewModel input) { if (!this.IsUserLoggedIn()) { return(this.Redirect("/Users/Login")); } tripsService.Add(input); return(this.Redirect("/Trips/All")); }
private async void AddTrip(object sender, RoutedEventArgs e) { if (Validate()) { if (await AddTripViewModel.AddTrip(AddTripName.Text, AddTripLocation.Text, AddTripStartDate.Date.Value.DateTime, AddTripEndDate.Date.Value.DateTime) != null) { ToastService.MakeToast(string.Format(ResourceLoader.GetString("AddTripCreated"), AddTripName.Text)); Frame.Navigate(typeof(TripOverview)); } } }
public IActionResult AddTrip([FromForm] AddTripViewModel model) { if (!ModelState.IsValid) { return(BadRequest()); } tripsService.AddTrip(model.Destination, model.Arrival, model.ArrivalTime, model.DestinationTime); return(Redirect(Url.Action("Index", "SearchTrip"))); }
public HttpResponse Add(AddTripViewModel model) { var errors = this.validatorService.TripsValidator(model); if (errors.Any()) { return(this.Error(errors)); } this.tripService.CreateTrip(model); return(this.Redirect("/Trips/All")); }
public void Add(AddTripViewModel tripViewModel) { this.db.Trips.Add(new Trip { StartPoint = tripViewModel.StartPoint, EndPoint = tripViewModel.EndPoint, ImagePath = tripViewModel.ImagePath, Description = tripViewModel.Description, Seats = tripViewModel.Seats, DepartureTime = DateTime.ParseExact(tripViewModel.DepartureTime, "dd.MM.yyyy HH:mm", CultureInfo.InvariantCulture, DateTimeStyles.None) }); this.db.SaveChanges(); }
public void Add(AddTripViewModel model) { var trip = new Trip() { StartPoint = model.StartPoint, EndPoint = model.EndPoint, Seats = model.Seats, DepartureTime = DateTime.ParseExact(model.DepartureTime, "dd.MM.yyyy HH:mm", CultureInfo.InvariantCulture), ImagePath = model.ImagePath, Description = model.Description }; this.db.Trips.Add(trip); this.db.SaveChanges(); }
public void Add(AddTripViewModel input) { var trip = new Trip() { StartPoint = input.StartPoint, EndPoint = input.EndPoint, DepartureTime = input.DepartureTime, ImagePath = input.ImagePath, Seats = input.Seats, Description = input.Description, }; this.db.Trips.Add(trip); db.SaveChanges(); }
public AddTripPage() { this.InitializeComponent(); AddTripViewModel = new AddTripViewModel(); this.AddTripViewModel.Trip.PropertyChanged += (sender, e) => { this.AddTripViewModel.CheckAreFieldValid(); }; this.AddTripViewModel.Trip.Route.PropertyChanged += (sender, e) => { this.AddTripViewModel.CheckAreFieldValid(); }; TripStart.MinDate = DateTime.Now; this.DataContext = AddTripViewModel; }
public IActionResult Add(AddTripViewModel addTripViewModel) { if (ModelState.IsValid) { State ChooseState = context.States.Single(s => s.ID == addTripViewModel.State); ApplicationUser User = context.Users.Single(u => u.Email == this.User.Identity.Name); Trip newTrip = AddTripViewModel.CreateTrip(addTripViewModel, ChooseState, User); context.Trips.Add(newTrip); context.SaveChanges(); return(Redirect("/User")); } return(Redirect("/Trip/Add")); }
public void CreateTrip(AddTripViewModel model) { var trip = new Trip() { StartPoint = model.StartPoint, EndPoint = model.EndPoint, DepartureTime = model.DepartureTime, Description = model.Description, Seats = model.Seats, ImagePath = model.ImagePath }; this.db.Trips.Add(trip); this.db.SaveChanges(); }
public IActionResult AddTrip(AddTripViewModel model) { if (ModelState.IsValid) { var trip = new Trip() { Name = model.Name, StartDate = model.StartDate, StartPlace = model.StartPlace, FinishPlace = model.FinishPlace, Distance = model.Distance, Days = model.Days }; _context.Trip.Add(trip); _context.SaveChanges(); return(RedirectToAction("Index")); } return(View(model)); }
public IEnumerable <string> TripsValidation(AddTripViewModel model) { this.Reuired(model.StartPoint, StartPoint); this.Reuired(model.EndPoint, EndPoint); this.Reuired(model.Description, Description); this.Reuired(model.DepartureTime.ToString(), DepartureTime); if (model.Seats < MinSeats || model.Seats > MaxSeats) { this.errorMessage.Add(string.Format(Seats, MinSeats, MaxSeats)); } if (model.Description.Length > MaxDescriptionLength) { this.errorMessage.Add(string.Format(DescriptionLength, MaxDescriptionLength)); } return(this.errorMessage); }
public HttpResponse Add(AddTripViewModel trip) { if (!this.IsUserLoggedIn()) { return(this.Redirect("/Users/Login")); } if (string.IsNullOrWhiteSpace(trip.StartPoint)) { return(this.Redirect("/Trips/Add")); } if (string.IsNullOrWhiteSpace(trip.EndPoint)) { return(this.Redirect("/Trips/Add")); } if (string.IsNullOrWhiteSpace(trip.DepartureTime)) { return(this.Redirect("/Trips/Add")); } if (trip.Seats < 2 || trip.Seats > 6) { return(this.Redirect("/Trips/Add")); } if (string.IsNullOrWhiteSpace(trip.Description)) { return(this.Redirect("/Trips/Add")); } if (trip.Description.Length > 80) { return(this.Redirect("/Trips/Add")); } tripsServcie.Add(trip); return(this.Redirect("/Trips/All")); }
public IActionResult Index(AddTripViewModel addTripViewModel) { if (ModelState.IsValid) { string origin = addTripViewModel.address0; List <string> destinations = new List <string>() { addTripViewModel.address1 }; if (addTripViewModel.address2 != null) { destinations.Add(addTripViewModel.address2); } if (addTripViewModel.address3 != null) { destinations.Add(addTripViewModel.address3); } if (addTripViewModel.address4 != null) { destinations.Add(addTripViewModel.address4); } if (addTripViewModel.address5 != null) { destinations.Add(addTripViewModel.address5); } if (addTripViewModel.address6 != null) { destinations.Add(addTripViewModel.address6); } string mode = addTripViewModel.Type.ToString().ToLower(); List <DestinationValue> destinationValues = DestinationValue.GetDistancesOrdered(origin, destinations, mode); ViewBag.orderedTrips = destinationValues; TempData["destinationValues"] = JsonConvert.SerializeObject(destinationValues);//destinationValues; TempData["mode"] = mode; return(View(addTripViewModel)); } return(View(addTripViewModel)); }
public HttpResponse Add(AddTripViewModel input) { if (!this.IsUserLoggedIn()) { return(this.Redirect("/Users/Login")); } if (string.IsNullOrEmpty(input.StartPoint) || string.IsNullOrWhiteSpace(input.StartPoint) || string.IsNullOrEmpty(input.EndPoint) || string.IsNullOrWhiteSpace(input.EndPoint)) { //return this.Error("Invalid Data!"); return(this.Redirect("/Trips/Add")); } //TODO: Add DateTime Validation for input.DepartureTime if (input.Seats < 2 || input.Seats > 6) { //return this.Error("Number of seats must be between 2 and 6."); return(this.Redirect("/Trips/Add")); } if (string.IsNullOrEmpty(input.Description) || string.IsNullOrWhiteSpace(input.Description)) { //return this.Error("Description cannot be empty!"); return(this.Redirect("/Trips/Add")); } if (input.Description.Length > 80) { //return this.Error("Description's max length is 80 characters."); return(this.Redirect("/Trips/Add")); } this.tripsService.Add(input); return(this.Redirect("/Trips/All")); }
public AddTrip() { InitializeComponent(); DataContext = new AddTripViewModel(); }
public AddTripPage() { this.InitializeComponent(); _addTripVM = new AddTripViewModel(); this.DataContext = _addTripVM; }
public IActionResult Add() { AddTripViewModel addTripViewModel = new AddTripViewModel(context.States.ToList()); return(View(addTripViewModel)); }