private void DeleteItineraryItem(object param) { ItineraryItem ii = (ItineraryItem)param; _tripRepository.DeleteItineraryItem(ii.Id); ItineraryItems.Remove(ii); }
public ActionResult DeleteItineraryItem(int id) { if (id < 0) { return(BadRequest()); } IdentityUser currentUser = GetCurrentUser(); if (currentUser == null) { return(BadRequest()); } ItineraryItem itineraryItem = _tripRepository.GetItineraryItemBy(id); if (itineraryItem == null) { return(NotFound()); } _tripRepository.DeleteItineraryItem(itineraryItem); _tripRepository.SaveChanges(); return(Ok()); }
public ActionResult DeleteConfirmed(int id) { ItineraryItem itineraryItem = db.ItineraryItems.Find(id); db.ItineraryItems.Remove(itineraryItem); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Create(ItineraryItem data) { if (ModelState.IsValid) { } else { ModelState.AddModelError("", "The data you entered was not valid"); } return(View()); }
public ActionResult Edit([Bind(Include = "ID,ItineraryID,StartTime,EndTime,Activity,GameID")] ItineraryItem itineraryItem) { if (ModelState.IsValid) { db.Entry(itineraryItem).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.GameID = new SelectList(db.Games, "ID", "GameName", itineraryItem.GameID); ViewBag.ItineraryID = new SelectList(db.Itinerary, "ID", "ID", itineraryItem.ItineraryID); return(View(itineraryItem)); }
[HttpPost] // filtro che istruisce il framework che questa azione del controller potrĂ essere chiamata solo da una POST public ActionResult Create(ItineraryItem data) { if (ModelState.IsValid) { // Handle saving the data only if the model state is valid } else { ModelState.AddModelError("", "The data you entered was not valid"); // Se l'utente inserisce dati non validi } return(View()); }
// GET: ItineraryItems/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ItineraryItem itineraryItem = db.ItineraryItems.Find(id); if (itineraryItem == null) { return(HttpNotFound()); } return(View(itineraryItem)); }
public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ItineraryItem itineraryItem = db.ItineraryItems.Find(id); if (itineraryItem == null) { return(HttpNotFound()); } ViewBag.GameID = new SelectList(db.Games, "ID", "GameName", itineraryItem.GameID); ViewBag.ItineraryID = new SelectList(db.Itinerary, "ID", "ID", itineraryItem.ItineraryID); return(View(itineraryItem)); }
public async Task <int> AddItineraryItem(int tripId, ItineraryItem itineraryItem) { _client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", TokenVault.Token); var iiJson = JsonConvert.SerializeObject(itineraryItem); var stringContent = new StringContent(iiJson, Encoding.UTF8, "application/json"); HttpResponseMessage response = await _client.PostAsync($"{_baseUrl}/{tripId}/ItineraryItem", stringContent); string iiId = await response.Content.ReadAsStringAsync(); if (response.IsSuccessStatusCode) { return(Int32.Parse(iiId)); } else { return(-1); } }
private async void AddItineraryItem() { AddItineraryItemDialog dialog = new AddItineraryItemDialog(Trip); ContentDialogResult result = await dialog.ShowAsync(); if (result == ContentDialogResult.Primary) { if (!String.IsNullOrEmpty(dialog.Description) && dialog.SelectedDate != null && dialog.SelectedTime != null) { DateTime time = dialog.SelectedDate.AddHours(dialog.SelectedTime.Hours).AddMinutes(dialog.SelectedTime.Minutes); ItineraryItem ii = new ItineraryItem(dialog.Description, time, (time.Date - DateTime.Now).Days); int id = await _tripRepository.AddItineraryItem(Trip.Id, ii); ii.Id = id; ii.Description = $"{ii.Description} at {ii.Date:H:mm}"; _itineraryItems.Add(ii); BuildItineraryList(); } } }
public ActionResult <TripItemDTO> AddItineraryItem(int id, ItineraryItem itineraryItem) { if (id < 0) { return(NotFound()); } IdentityUser currentUser = GetCurrentUser(); if (currentUser == null) { return(BadRequest()); } ItineraryItem iiToCreate = new ItineraryItem(itineraryItem.Description, itineraryItem.Date); Trip trip = _tripRepository.GetByWithItineraryItems(id); trip.ItineraryItems.Add(iiToCreate); _tripRepository.SaveChanges(); return(Ok(iiToCreate.Id)); }
public async Task <ItineraryItem> AddItineraryItem(ItineraryItem newItem, string itineraryId) { await GraphClient.ConnectAsync(); try { var resp = await GraphClient.Cypher .Match("(day:Day)") .Where((Itinerary day) => day.ItineraryId == itineraryId) .Create("(item:DayPlanItem $item)") .WithParam("item", newItem) .Create("(day)-[r:HasDayPlanItem]->(item)") .Return(day => day.As <ItineraryItem>()) .ResultsAsync; if (resp.Any()) { return(resp.First()); } else { return(null); } } catch (ClientException ce) { if (ce.Message.Contains("already exists", StringComparison.InvariantCultureIgnoreCase)) { newItem.ItineraryItemId = new Guid().ToString(); return(await AddItineraryItem(newItem, itineraryId)); } else { throw ce; } } }
public ActionResult Create() { var model = new ItineraryItem(); return(View(model)); }
public void DeleteItineraryItem(ItineraryItem itineraryItem) { _itineraryItems.Remove(itineraryItem); }
public ItineraryItemDTO(ItineraryItem itineraryItem) { Description = $"{itineraryItem.Description} at {itineraryItem.Date:H:mm}"; Date = itineraryItem.Date; DaysRemaining = (itineraryItem.Date - DateTime.Now).Days; }
public async Task InitializeDataAsync() { _context.Database.EnsureDeleted(); if (_context.Database.EnsureCreated()) { IdentityUser user1 = new IdentityUser { UserName = "******", Email = "*****@*****.**" }; IdentityUser user2 = new IdentityUser { UserName = "******", Email = "*****@*****.**" }; await _userManager.CreateAsync(user1, "Test123456789"); await _userManager.AddClaimAsync(user1, new Claim(JwtClaimTypes.Role, "user")); await _userManager.CreateAsync(user2, "Test123456789"); await _userManager.AddClaimAsync(user2, new Claim(JwtClaimTypes.Role, "user")); Trip t1 = new Trip() { Destination = "Italy, Rome 2022", DepartureDate = new DateTime(2022, 1, 10), ReturnDate = new DateTime(2022, 2, 10), User = user1, TripItems = new List <TripItem>(), TripTasks = new List <TripTask>(), ItineraryItems = new List <ItineraryItem>() }; Trip t2 = new Trip() { Destination = "France, Paris 2022", DepartureDate = new DateTime(2022, 12, 30), ReturnDate = new DateTime(2023, 1, 10), User = user1, TripItems = new List <TripItem>(), TripTasks = new List <TripTask>(), ItineraryItems = new List <ItineraryItem>() }; Trip t4 = new Trip() { Destination = "France, Paris 2021", DepartureDate = new DateTime(2021, 1, 10), ReturnDate = new DateTime(2021, 2, 10), User = user1, TripItems = new List <TripItem>(), TripTasks = new List <TripTask>(), ItineraryItems = new List <ItineraryItem>() }; Trip t3 = new Trip() { Destination = "Prague", DepartureDate = new DateTime(2021, 2, 21, 6, 15, 00), ReturnDate = new DateTime(2021, 3, 10, 23, 45, 00), User = user2, TripItems = new List <TripItem>(), TripTasks = new List <TripTask>(), ItineraryItems = new List <ItineraryItem>() }; Trip t5 = new Trip() { Destination = "Russia, Moscou 2023", DepartureDate = new DateTime(2023, 2, 21, 6, 15, 00), ReturnDate = new DateTime(2023, 3, 10, 23, 45, 00), User = user1, TripItems = new List <TripItem>(), TripTasks = new List <TripTask>(), ItineraryItems = new List <ItineraryItem>() }; GeneralCategory c1 = new GeneralCategory("Electronics", user1); GeneralCategory c2 = new GeneralCategory("Toiletries", user1); GeneralCategory c3 = new GeneralCategory("Clothes", user1); GeneralCategory c4 = new GeneralCategory("Books", user1); GeneralCategory c5 = new GeneralCategory("Trifles", user1); GeneralCategory c6 = new GeneralCategory("Legal stuff", user1); TripCategory tc1 = new TripCategory("Books for in Rome", t1); TripCategory tc2 = new TripCategory("Swimming Gear", t1); TripCategory tc3 = new TripCategory("Navigation", t1); TripCategory tc4 = new TripCategory("Clothes", t1); _context.Categories.Add(c1); _context.Categories.Add(c2); _context.Categories.Add(c3); _context.Categories.Add(c4); _context.Categories.Add(c5); _context.Categories.Add(c6); _context.TripCategories.Add(tc1); _context.TripCategories.Add(tc1); GeneralItem generalItem1 = new GeneralItem("Mobile phone", c1, user1); GeneralItem generalItem2 = new GeneralItem("Charger", c1, user1); GeneralItem generalItem3 = new GeneralItem("Camera", c1, user1); GeneralItem generalItem4 = new GeneralItem("Toothbrush", c1, user1); GeneralItem generalItem5 = new GeneralItem("Pants", c3, user1); GeneralItem generalItem6 = new GeneralItem("T-shirts", c3, user1); GeneralItem generalItem7 = new GeneralItem("Laptop", c1, user1); GeneralItem generalItem8 = new GeneralItem("Laptop charger", c1, user1); GeneralItem generalItem9 = new GeneralItem("Swimming trunks", c3, user1); GeneralItem generalItem10 = new GeneralItem("Bikini", c3, user1); GeneralItem generalItem11 = new GeneralItem("Comb", c2, user1); GeneralItem generalItem12 = new GeneralItem("Stretchers", c2, user1); GeneralItem generalItem13 = new GeneralItem("The Da Vinci Code, Dan Brown", c4, user1); GeneralItem generalItem14 = new GeneralItem("Harry Potter and the Philosopher's Stone, J.K. Rowling", c4, user1); GeneralItem generalItem15 = new GeneralItem("Twilight, Meyer Stephenie", c4, user1); GeneralItem generalItem16 = new GeneralItem("The Eye of The World, Robert Jordan", c4, user1); GeneralItem generalItem17 = new GeneralItem("Watch", c5, user1); GeneralItem generalItem18 = new GeneralItem("All Id cards", c6, user1); GeneralItem generalItem19 = new GeneralItem("Negative covid tests", c6, user1); GeneralItem generalItem20 = new GeneralItem("Drivers license", c6, user1); TripItem tripItem1 = new TripItem("Map of Rome", 1, tc3, true); TripItem tripItem2 = new TripItem("Map of Musea in Rome", 1, tc3, true); TripItem tripItem3 = new TripItem("Swimming pants", 2, tc2, true); TripItem tripItem4 = new TripItem("The history of Rome", 1, tc1, true); TripItem tripItem5 = new TripItem("100 Things to see in Rome", 1, tc1, false); TripItem tripItem6 = new TripItem("The most attractive spots in Rome", 1, tc1, false); TripItem tripItem7 = new TripItem("Must-see Restaurants in Rome", 1, tc1, false); TripItem tripItem8 = new TripItem("T-shirts", 5, tc4, false); TripItem tripItem9 = new TripItem("Pants", 3, tc4, true); TripItem tripItem10 = new TripItem("Sweater", 5, tc4, true); TripItem tripItem11 = new TripItem("Socks", 8, tc4, true); TripItem tripItem12 = new TripItem("Underwear", 8, tc4, false); TripTask tt1 = new TripTask("Charge batteries for all devices"); TripTask tt2 = new TripTask("Get covid tests done"); TripTask tt3 = new TripTask("Check website for information about covid rules"); TripTask tt4 = new TripTask("Get some maps about the city"); TripTask tt5 = new TripTask("Check if we need extra medicines"); TripTask tt6 = new TripTask("Eating a real italian pizza"); TripTask tt7 = new TripTask("Going to the beach and relax"); ItineraryItem ii1 = new ItineraryItem("Take a taxi to the airport", new DateTime(2022, 1, 10, 6, 30, 0)); ItineraryItem ii2 = new ItineraryItem("Plane to Rome", new DateTime(2022, 1, 10, 8, 30, 0)); ItineraryItem ii3 = new ItineraryItem("Take the bus to the hotel", new DateTime(2022, 1, 10, 14, 15, 0)); ItineraryItem ii4 = new ItineraryItem("Take the bus back to the airport", new DateTime(2022, 2, 10, 6, 15, 0)); ItineraryItem ii5 = new ItineraryItem("Plane back to Belgium", new DateTime(2022, 2, 10, 8, 15, 0)); ItineraryItem ii6 = new ItineraryItem("Dad drives us back home", new DateTime(2022, 2, 10, 14, 30, 0)); t1.TripItems.Add(tripItem1); t1.TripItems.Add(tripItem2); t1.TripItems.Add(tripItem3); t1.TripItems.Add(tripItem4); t1.TripItems.Add(tripItem5); t1.TripItems.Add(tripItem6); t1.TripItems.Add(tripItem7); t1.TripItems.Add(tripItem8); t1.TripItems.Add(tripItem9); t1.TripItems.Add(tripItem10); t1.TripItems.Add(tripItem11); t1.TripItems.Add(tripItem12); t1.ItineraryItems.Add(ii1); t1.ItineraryItems.Add(ii2); t1.ItineraryItems.Add(ii3); t1.ItineraryItems.Add(ii4); t1.ItineraryItems.Add(ii5); t1.ItineraryItems.Add(ii6); t1.TripTasks.Add(tt1); t1.TripTasks.Add(tt2); t1.TripTasks.Add(tt3); t1.TripTasks.Add(tt4); t1.TripTasks.Add(tt5); t1.TripTasks.Add(tt6); t1.TripTasks.Add(tt7); _context.Trips.Add(t1); _context.Trips.Add(t2); _context.Trips.Add(t3); _context.Trips.Add(t4); _context.Trips.Add(t5); _context.Items.Add(generalItem1); _context.Items.Add(generalItem2); _context.Items.Add(generalItem3); _context.Items.Add(generalItem4); _context.Items.Add(generalItem5); _context.Items.Add(generalItem6); _context.Items.Add(generalItem7); _context.Items.Add(generalItem8); _context.Items.Add(generalItem9); _context.Items.Add(generalItem10); _context.Items.Add(generalItem11); _context.Items.Add(generalItem12); _context.Items.Add(generalItem13); _context.Items.Add(generalItem14); _context.Items.Add(generalItem15); _context.Items.Add(generalItem16); _context.Items.Add(generalItem17); _context.Items.Add(generalItem18); _context.Items.Add(generalItem19); _context.Items.Add(generalItem20); _context.SaveChanges(); } }
/// <summary> /// This method has a lot of logic that is specific to the map type. /// To process a request you can easily just call the Execute method on the request. /// This will build much of the SimioMapRoute object. /// </summary> /// <param name="request"></param> public bool GetRoute(string mapsKey, string originAddress, string destinationAddress, out SimioMapRoute mapRoute, out string requestUrl, out string explanation) { explanation = ""; requestUrl = ""; mapRoute = null; try { mapRoute = new SimioMapRoute(originAddress, destinationAddress); // Build a list of our two waypoints (from and to) List <SimpleWaypoint> wpList = new List <SimpleWaypoint>(); wpList.Add(new SimpleWaypoint(originAddress)); //e.g. "Pittsburgh, PA")); wpList.Add(new SimpleWaypoint(destinationAddress)); // e.g. "Sewickley, PA")); List <RouteAttributeType> routeAttributes = new List <RouteAttributeType>(); routeAttributes.Add(RouteAttributeType.RoutePath); // Construct the request and attributes var request = new RouteRequest() { BingMapsKey = mapsKey, Waypoints = wpList }; request.RouteOptions = new RouteOptions(); request.RouteOptions.RouteAttributes = routeAttributes; requestUrl = request.ToString(); var start = DateTime.Now; // Async. Execute the request. var task = Task <Response> .Run(async() => { return(await request.Execute()); }); Response r2 = task.Result; // Check if we got a good response if (r2 != null && r2.ResourceSets != null && r2.ResourceSets.Length > 0 && r2.ResourceSets[0].Resources != null && r2.ResourceSets[0].Resources.Length > 0) { ResourceSet rs = (ResourceSet)r2.ResourceSets[0]; Route route = (Route)rs.Resources[0]; RouteLeg[] legs = route.RouteLegs; ItineraryItem[] itineraries = legs[0].ItineraryItems; ItineraryItem itinItem = itineraries[2]; string bb = route.BoundingBox.ToString(); mapRoute.SegmentList.Clear(); // We could make the bounding box from the one that Bing Maps sends us, // but we're going to do our own to match the usa 'map'. ////PointF ptLoc = new PointF((float)route.BoundingBox[1], (float)route.BoundingBox[0]); ////float width = (float)(route.BoundingBox[3] - route.BoundingBox[1]); ////float height = (float)(route.BoundingBox[2] - route.BoundingBox[0]); ////// We're going to bound according to the contiguous USA, which is appox. ////// lat 20 to 50, and lon -60 to -130 ////PointF ptLoc = transform.LonLatBoundingBox.Location; // new PointF( -130f, 20f); ////float width = lonlatBox.Width; // 70f; ////float height = lonlatBox.Height; // 30f; ////// Turning the thing on its side, since we want latitude to be 'Y' ////mapData.LonLatBoundingBox = new RectangleF(ptLoc.X, ptLoc.Y, width, height); ////mapData.Origin = new PointF(ptLoc.X + width / 2f, ptLoc.Y + height / 2f); ////mapData.SimioScaling = simioScaling; // Build something for the form's 'result textbox StringBuilder sb = new StringBuilder(); // Create segments from the itineraries, and pick up the indices // that reference the RoutePath array of lat,lon coordinates. // We are assuming a single itinerary. See Bing Maps for for info. for (var ii = 0; ii < itineraries.Length; ii++) { ItineraryItem item = itineraries[ii]; if (route.RoutePath != null) { int idxStart = item.Details[0].StartPathIndices[0]; int idxEnd = item.Details[0].EndPathIndices[0]; double lat = route.RoutePath.Line.Coordinates[idxStart][0]; double lon = route.RoutePath.Line.Coordinates[idxStart][1]; MapCoordinate mcStart = new MapCoordinate(lat, lon); lat = route.RoutePath.Line.Coordinates[idxEnd][0]; lon = route.RoutePath.Line.Coordinates[idxEnd][1]; MapCoordinate mcEnd = new MapCoordinate(lat, lon); MapSegment segment = null; if (ii == 0) { segment = mapRoute.AddFirstSegment(mcStart, mcEnd); } else { segment = mapRoute.AppendSegment(mcEnd); } // Now add Bing-specific info segment.Distance = item.TravelDistance; segment.Duration = item.TravelDuration; } sb.AppendLine($"Compass={item.CompassDirection} Distance={item.TravelDistance} >> {item.Instruction.Text}"); } // for each itinerary explanation = sb.ToString(); return(true); } else { explanation = "No results found."; return(false); } } catch (Exception ex) { explanation = $"Err={ex.Message}"; return(false); } }
private void MenuFlyoutItem_Click(object sender, RoutedEventArgs e) { ItineraryItem ii = (ItineraryItem)itineraryLv.SelectedItem; ItineraryVM.DeleteItineraryItemCommand.Execute(ii); }