public JsonResult AddAirport(AirportData airportData) { try { var result = DashboardBusiness.PostAirportData(airportData); if (result != null) { return(new JsonResult { Data = result }); } else { return(new JsonResult { Data = "Error!!" }); } } catch (Exception ex) { return(new JsonResult { Data = ex.Message }); } }
public static IForm <LuggageQuery> BuildForm() { OnCompletionAsyncDelegate <LuggageQuery> processOrder = async(context, state) => { await Task.Run(() => { state.QueryDate = DateTime.Now; var data = AirportData.GetLuggages(state.Airline, state.FlightNo); if (data != null && data.Count > 0) { state.Results = data; } else { state.Results = null; } } ); }; var builder = new FormBuilder <LuggageQuery>(false); var form = builder .Field(nameof(Airline)) .Field(nameof(FlightNo)) .OnCompletion(processOrder) .Build(); return(form); }
internal static List <AirportData> PostAirportData(AirportData airportData) { using (var context = new AirportInventoryEntities()) { Airport newAirport = new Airport() { AirportName = airportData.airport_name, Fuel_Capacity_Available = airportData.fuel_capacity_available }; context.Airports.Add(newAirport); context.SaveChanges(); var airportList = context.Airports. Where(h => 1 == 1) .Select(x => new AirportData { airport_id = x.AirportId, airport_name = x.AirportName, fuel_capacity_available = x.Fuel_Capacity_Available, }).ToList(); if (airportList != null) { return(airportList); } else { return(null); } } }
public static IForm <FacilityQuery> BuildForm() { OnCompletionAsyncDelegate <FacilityQuery> processOrder = async(context, state) => { await Task.Run(() => { state.QueryDate = DateTime.Now; var data = AirportData.GetFacilityByCategory(state.FacilityType.ToString(), string.IsNullOrEmpty(state.Name)? null : state.Name); if (data != null && data.Count > 0) { state.Results = data; } else { state.Results = null; } } ); }; var builder = new FormBuilder <FacilityQuery>(false); var form = builder .Field(nameof(FacilityType)) .Field(nameof(Name)) .OnCompletion(processOrder) .Build(); return(form); }
public static IForm <ReportAPQuery> BuildForm() { OnCompletionAsyncDelegate <ReportAPQuery> processOrder = async(context, state) => { await Task.Run(() => { state.QueryDate = DateTime.Now; var data = AirportData.GetReportByDate(state.StartDate, state.EndDate); if (data != null && data.Count > 0) { state.Results = data; } else { state.Results = null; } } ); }; var builder = new FormBuilder <ReportAPQuery>(false); var form = builder .Field(nameof(StartDate)) .Field(nameof(EndDate)) .OnCompletion(processOrder) .Build(); return(form); }
private static void Aeroportos() { Console.WriteLine("Digite o nome do pais (em ingles) :\n"); string pais = Console.ReadLine(); FlightStatsIntegrationClient client = new FlightStatsIntegrationClient(); AirportData airport = client.GetAirportsData(pais); if (airport.HasError) { Console.WriteLine("Ocorreu um erro: " + airport.Message); } else { foreach (var item in airport.Airports) { Console.WriteLine("::::::::::::::::::::::::::" + "\n Nome: " + item?.name + "\n Iata: " + item?.iata + "\n Pais: " + item?.countryName + "\n Cidade: " + item?.city + "\n Latitude: " + item?.latitude.ToString("N2") + "\n Longitude: " + item?.longitude.ToString("N2")); } } client.Close(); }
/// <summary> /// Lista de aviones /// </summary> /// <returns></returns> public List <object> GetAirports() { List <Object> dataList = new List <object>(); using (tecAirlinesEntities entities = new tecAirlinesEntities()) { try { var airshipList = entities.airports.ToList(); int n = airshipList.Count; if (n == 0) { dataList = null; return(dataList); } else { for (int i = 0; i < airshipList.Count; ++i) { AirportData data = new AirportData(); data.Nombre = airshipList.ElementAt(i).Nombre; data.Codigo = airshipList.ElementAt(i).Codigo; data.N_Pais = airshipList.ElementAt(i).N_Pais; dataList.Add(data); } return(dataList); } } catch { dataList = null; return(dataList); } } }
public static IForm <FlightQuery2> BuildForm() { OnCompletionAsyncDelegate <FlightQuery2> processOrder = async(context, state) => { await Task.Run(() => { state.QueryDate = DateTime.Now; var data = AirportData.GetFlightByAirline(state.Airline); if (data == null || data.Count > 0) { var item = data[0]; state.Result = $"AFSKEY:{item.AFSKEY}, FLIGHT_NO : {item.FLIGHT_NO}, LEG:{item.LEG}, LEG_DESCRIPTION:{item.LEG_DESCRIPTION}, SCHEDULED:{item.SCHEDULED}, ESTIMATED :{item.ESTIMATED}, ACTUAL:{item.ACTUAL}, CATEGORY_CODE :{item.CATEGORY_CODE}, CATEGORY_NAME : {item.CATEGORY_NAME}, REMARK_CODE:{item.REMARK_CODE}, REMARK_DESC_ENG:{item.REMARK_DESC_ENG}, REMARK_DESC_IND:{item.REMARK_DESC_IND},TERMINAL_ID:{item.TERMINAL_ID}, GATE_CODE : {item.GATE_CODE}, GATE_OPEN_TIME : {item.GATE_OPEN_TIME}, GATE_CLOSE_TIME : {item.GATE_CLOSE_TIME}, STATION1 :{item.STATION1}, STATION1_DESC : {item.STATION1_DESC}, STATION2 :{item.STATION2}, STATION2_DESC : {item.STATION2_DESC}"; } else { state.Result = $"Data is not found. Please try again.."; } }); }; var builder = new FormBuilder <FlightQuery2>(false); var form = builder .Field(nameof(Airline)) .OnCompletion(processOrder) .Build(); return(form); }
internal void SelectAirport(AirportData airport) { WorldData.SelectedAirport = airport; var str = string.Format("{0}\r\n{1,1}\r\n{2,1}\r\n{3}\r\nRunways:{5}\r\nPopulation:{4}", airport.Name, airport.Latitude, airport.Longitude, airport.Region, airport.Population, airport.Runways); TextPanel.GetComponent <UnityEngine.UI.Text>().text = str; }
public static Domain.Airport.Airport Create(AirportView view) { var d = new AirportData(); Copy.Members(view, d); return(new Domain.Airport.Airport(d)); }
/// <summary> /// Convert to dto <see cref="AirportDataDto"/> /// </summary> /// <param name="airportData"></param> /// <returns></returns> public static AirportDataDto ConvertToDto(this AirportData airportData) { return(new AirportDataDto() { Longitude = airportData.Location.Lon, Latitude = airportData.Location.Lat, AirportCode = airportData.Iata }); }
//-------------------------------------------------------------------------------------------------------------------------------- private void buttonAdd_Click(object sender, System.EventArgs e) { AirportData from = AirportData.Airports[comboBoxFrom.Text]; AirportData to = AirportData.Airports[comboBoxTo.Text]; Route newRoute = new Route(from, to, (int)numericUpDownCargo.Value, (int)numericUpDownPassenger.Value); checkedListBoxRoutes.Items.Add(newRoute, true); comboBoxFrom.Focus(); }
public AirportData GetAirportsData(string country) { AirportData rs = new AirportData(); rs.HasError = false; rs.Message = string.Empty; rs.Airports = new List <AirportCustom>(); try { if (!string.IsNullOrEmpty(country)) { string code = service.getCodeCountry(country); if (!string.IsNullOrEmpty(code)) { var airports = service.getAirports(code); if (airports.airports.Count() > 0) { foreach (var item in airports.airports) { AirportCustom a = new AirportCustom(); a.iata = string.IsNullOrEmpty(item.iata) == true ? string.Empty : item.iata; a.name = item.name; a.countryName = item.countryName; a.city = item.city; a.latitude = item.latitude; a.longitude = item.longitude; rs.Airports.Add(a); } } } else { rs.HasError = true; rs.Message = "Country not found."; } } else { rs.HasError = true; rs.Message = "Send a country."; } } catch (Exception e) { rs.HasError = true; rs.Message = e.Message; } return(rs); }
//-------------------------------------------------------------------------------------------------------------------------------- private void AddNewRoute(AirportData from, AirportData to, int cargo, int passenger) { Route newRoute = new Route(from, to, cargo, passenger); checkedListBoxRoutes.Items.Add(newRoute, true); RefreshTotalDistance(); ValidateInputs(); RefreshCostScale(); }
private static void DeriveMapCoordinatesFor(MapData target, AirportData airport) { double lat, lon; if (double.TryParse(airport.Latitude, out lat) && double.TryParse(airport.Longitude, out lon)) { int x, y; MapData.LatLonToDataXY(lat, lon, target.Height, target.LLCornerLongitude, target.LLCornerLatitude, target.MapCellSize, out x, out y); airport.MapX = x; airport.MapY = y; } else { Console.WriteLine($"Unable to ascertain the map location of {airport.Name}."); } }
//-------------------------------------------------------------------------------------------------------------------------------- private bool ValidateAirport(ComboBox comboBox, out AirportData airportData) { airportData = null; if (comboBox.SelectedItem == null) { return(false); } if (!AirportData.Airports.TryGetValue(comboBox.Text, out airportData)) { return(false); } return(true); }
// nouveau vol qui a un aéroport de départ et un aéroport de destination public ActionResult Create() { AirportData airport = new AirportData(); AirplaneData airplane = new AirplaneData(); IEnumerable <SelectListItem> airportitems = airport.getAllAirport().Select(c => new SelectListItem { Value = c.AirportId.ToString(), Text = c.Name }); IEnumerable <SelectListItem> airplaneitems = airplane.getAllAirplane().Select(c => new SelectListItem { Value = c.AirplaneId.ToString(), Text = c.Title }); ViewBag.Airports = airportitems; ViewBag.Airplanes = airplaneitems; return(View()); }
private static AirportData MappingAirportData(string[] cols) { var data = new AirportData { AirportId = Convert.ToInt32(cols[0]), Name = CheckValueIsNullValue(cols[1]) ? string.Empty : cols[1], City = CheckValueIsNullValue(cols[2]) ? string.Empty : cols[2], Country = CheckValueIsNullValue(cols[3]) ? string.Empty : cols[3], IATA = CheckValueIsNullValue(cols[4]) ? string.Empty : cols[4], ICAO = CheckValueIsNullValue(cols[5]) ? string.Empty : cols[5], Latitude = CheckValueIsNullValue(cols[6]) ? (double?)null : Convert.ToDouble(cols[6]), Longitude = CheckValueIsNullValue(cols[7]) ? (double?)null : Convert.ToDouble(cols[7]), Altitude = CheckValueIsNullValue(cols[8]) ? (double?)null : Convert.ToDouble(cols[8]), Timezone = CheckValueIsNullValue(cols[9]) ? (double?)null : Convert.ToDouble(cols[9]), DST = CheckValueIsNullValue(cols[10]) ? string.Empty : cols[10], TzDatabaseTimezone = CheckValueIsNullValue(cols[11]) ? string.Empty : cols[11], Type = CheckValueIsNullValue(cols[12]) ? string.Empty : cols[12], Source = CheckValueIsNullValue(cols[13]) ? string.Empty : cols[13] }; return(data); }
void GetAirportsData(string fromIcao, string toIcao, out AirportData fromAirportData, out AirportData toAirportData) { //check aircode is icao if (fromIcao.Length != 4 || toIcao.Length != 4 || fromIcao == toIcao) { throw new ArgumentException(); } // try find airport AirportsInfoRetriever airports = App.GetMencoApp().IcaoAirports; AirportData?fromAirport = airports.GetAirportByIcaoCode(fromIcao); AirportData?toAirport = airports.GetAirportByIcaoCode(toIcao); if (fromAirport == null || toAirport == null) { // todo check online if offline check returned false. throw new ArgumentException(); } fromAirportData = (AirportData)fromAirport; toAirportData = (AirportData)toAirport; }
public Route(string from, string to, int cargo, int passenger) { this.from = AirportData.Airports[from]; this.to = AirportData.Airports[to]; this.cargo = cargo; this.passenger = passenger; }
private static void CreateRouteData(MapData target, string airportDataFile, string routeDataFile, string equipmentDataFile, string equipmentLoadingDataFile) { Encoding csvEncoding = new UTF8Encoding(false); // MYSQL requires UTF-8 WITHOUT a BOM. int airportRankCutoff = 250; List <AirportData> airports; List <RouteData> routes; Configuration configuration = new Configuration() { HasHeaderRecord = false, MissingFieldFound = null, DetectColumnCountChanges = true }; using (var reader = new StreamReader(airportDataFile)) using (var csv = new CsvReader(reader, configuration)) { airports = new List <AirportData>(csv.GetRecords <AirportData>()); } Dictionary <string, AirportData> airportData = new Dictionary <string, AirportData>(); airports.ForEach( n => { n.Name = n.Name.Replace(",", " -"); n.City = n.City.Replace(",", " -"); n.Country = n.Country.Replace(",", " -"); if (!String.IsNullOrEmpty(n.AirportID) && !airportData.ContainsKey(n.AirportID)) { airportData.Add(n.AirportID, n); } } ); target.Airports = airportData; using (var reader = new StreamReader(routeDataFile)) using (var csv = new CsvReader(reader, configuration)) { routes = new List <RouteData>(csv.GetRecords <RouteData>()); } RouteData.Airports = airportData; List <RouteData> fubarRoutes = new List <RouteData>(routes.Where( n => string.Equals("\\N", n.SourceAirportID) || string.Equals("\\N", n.DestinationAirportID) || !airportData.ContainsKey(n.SourceAirportID) || !airportData.ContainsKey(n.DestinationAirportID))); fubarRoutes.ForEach(n => routes.Remove(n)); Dictionary <string, int> airportUsage = new Dictionary <string, int>(); foreach (RouteData rd in routes) { if (!airportUsage.ContainsKey(rd.SourceAirportID)) { airportUsage.Add(rd.SourceAirportID, 0); } if (!airportUsage.ContainsKey(rd.DestinationAirportID)) { airportUsage.Add(rd.DestinationAirportID, 0); } airportUsage[rd.SourceAirportID]++; airportUsage[rd.SourceAirportID]++; } SortedList <int, string> sorted = new SortedList <int, string>(new Ranker()); foreach (var v in airportUsage) { sorted.Add(v.Value, v.Key); } int rank = 1; foreach (KeyValuePair <int, string> pair in sorted.Reverse()) { airportData[pair.Value].IsBusy = true; if (rank++ > airportRankCutoff) { break; } } foreach (var airportDatum in airportData) { DeriveMapCoordinatesFor(target, airportDatum.Value); } int ndx = 0; List <EquipmentData> equipment; Dictionary <string, EquipmentData> equipmentData = new Dictionary <string, EquipmentData>(); using (var reader = new StreamReader(equipmentDataFile)) using (var csv = new CsvReader(reader, configuration)) { equipment = new List <EquipmentData>(csv.GetRecords <EquipmentData>()); } equipment.ForEach(n => n.EquipmentID = ndx++); List <EquipmentLoadingData> equipmentLoading; using (var reader = new StreamReader(equipmentLoadingDataFile)) using (var csv = new CsvReader(reader, configuration)) { equipmentLoading = new List <EquipmentLoadingData>(csv.GetRecords <EquipmentLoadingData>()); } Dictionary <string, int> equipmentLoadingData = new Dictionary <string, int>(); equipmentLoading.ForEach(n => equipmentLoadingData.Add(n.Type, n.PaxCapacity)); equipment.ForEach(n => { if (!equipmentData.ContainsKey(n.IATACode)) { equipmentData.Add(n.IATACode, n); } }); target.BusyRoutes = new List <RouteData>(); ndx = 0; foreach (RouteData routeData in routes) { AirportData src, dest; EquipmentData equipt; airportData.TryGetValue(routeData.SourceAirportID, out src); airportData.TryGetValue(routeData.DestinationAirportID, out dest); equipmentData.TryGetValue(routeData.Equipment, out equipt); if (src != null && src.IsBusy && dest != null && dest.IsBusy) { target.BusyRoutes.Add(routeData); routeData.RouteID = ndx++; } if (equipt != null) { routeData.Using = equipt; } } int undefinedEquipment = 0; foreach (RouteData busyRoute in target.BusyRoutes) { if (busyRoute.Equipment == null) { undefinedEquipment++; } else { string[] allEquipment = busyRoute.Equipment.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); if (allEquipment.Length > 0) { int paxCap = 0; foreach (string s in allEquipment) { paxCap += equipmentLoadingData[s]; } busyRoute.MaxPassengers = paxCap / allEquipment.Length; // Average. } } } if (undefinedEquipment > 0) { Console.WriteLine($"There were {undefinedEquipment} routes defined that had no assigned equipment."); } #if GENERATE_PLANES_IN_USE List <string> planesInUseList = new List <string>(); int undefinedEquipment = 0; foreach (RouteData busyRoute in m_busyRoutes) { if (busyRoute.Equipment == null) { undefinedEquipment++; } else { string[] allequipt = busyRoute.Equipment.Split(new[] { ' ' }); foreach (string equipt in allequipt) { if (!planesInUseList.Contains(equipt)) { planesInUseList.Add(equipt); //busyRoute.Using.Name); } } } } planesInUseList.ForEach(n => file.WriteLine(n)); file.Close(); #endif Dictionary <string, int> paxTravel = new Dictionary <string, int>(); // Consolidate Busy routes foreach (RouteData busyRoute in target.BusyRoutes) { string key = $"{busyRoute.From.AirportID}|{busyRoute.To.AirportID}"; if (!paxTravel.ContainsKey(key)) { paxTravel.Add(key, 0); } paxTravel[key] += busyRoute.MaxPassengers; } List <PaxMovementData> paxMovement = new List <PaxMovementData>(); foreach (KeyValuePair <string, int> pair in paxTravel) { string[] icaoCodes = pair.Key.Split('|'); AirportData from = airportData[icaoCodes[0]]; AirportData to = airportData[icaoCodes[1]]; paxMovement.Add(new PaxMovementData() { FromAirportID = from.AirportID, FromLat = double.Parse(from.Latitude), FromLon = double.Parse(from.Longitude), FromMapX = from.MapX, FromMapY = from.MapY, ToAirportID = to.AirportID, ToLat = double.Parse(to.Latitude), ToLon = double.Parse(to.Longitude), ToMapX = to.MapX, ToMapY = to.MapY, NumberOfPassengers = pair.Value }); } foreach (string fn in Directory.GetFiles("../../Data/DBStaging/", "*.csv")) { new FileInfo(fn).Delete(); } using (TextWriter writer = new StreamWriter("../../Data/DBStaging/paxMovement.csv", false, csvEncoding)) { var csv = new CsvWriter(writer, configuration); csv.WriteRecords(paxMovement); // where values implements IEnumerable } using ( TextWriter writer = new StreamWriter("../../Data/DBStaging/airports.csv", false, csvEncoding)) { foreach (AirportData data in airportData.Values) { writer.WriteLine( $"{data.AirportID},{data.Name},{data.City},{data.Country},{(string.Equals(data.IATACode, AirportData.UNKNOWN) ? "" : data.IATACode)},{(string.Equals(data.ICAOCode, AirportData.UNKNOWN) ? "" : data.ICAOCode)},{data.Latitude},{data.Longitude},{(string.Equals(data.Altitude, "N") ? "-1" : data.Altitude)},{(string.Equals(data.Timezone, AirportData.UNKNOWN) ? "" : data.Timezone)},{(string.Equals(data.DST, AirportData.UNKNOWN) ? "" : data.DST)},{(string.Equals(data.Tz, AirportData.UNKNOWN) ? "" : data.Tz)},{data.Type},{data.Source},{(data.IsBusy ? "1" : "0")},{data.MapX},{data.MapY}"); } } using ( TextWriter writer = new StreamWriter("../../Data/DBStaging/equipment.csv", false, csvEncoding)) { foreach (EquipmentData data in equipmentData.Values) { int load; if (!equipmentLoadingData.TryGetValue(data.IATACode, out load)) { load = -1; } string iataCode = data.IATACode; if (string.Equals("\\N", iataCode)) { iataCode = null; } string icaoCode = data.ICAOCode; if (string.Equals("\\N", icaoCode)) { icaoCode = null; } writer.WriteLine($"{data.EquipmentID},{data.Name},{iataCode},{icaoCode},{load}"); } } using ( TextWriter writer = new StreamWriter("../../Data/DBStaging/routes.csv", false, csvEncoding)) { foreach (RouteData data in target.BusyRoutes) { //writer.WriteLine($"{data.RouteID},{(string.Equals(data.AirlineID, AirportData.UNKNOWN) ? "" : data.AirlineID)},{data.SourceAirportID},{data.DestinationAirportID}"); writer.WriteLine($"{data.RouteID},{data.SourceAirportID},{data.DestinationAirportID}"); } } List <string> missing = new List <string>(); using ( TextWriter writer = new StreamWriter("../../Data/DBStaging/map_route_equipment.csv", false, csvEncoding) ) { foreach (RouteData data in target.BusyRoutes) { string[] allequipt = data.Equipment.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); if (allequipt.Length > 0) { foreach (var equipt in allequipt) { if (!equipmentData.ContainsKey(equipt)) { if (!missing.Contains(equipt)) { missing.Add(equipt); } } else { int equipmentID = equipmentData[equipt].EquipmentID; writer.WriteLine($"{data.RouteID},{equipmentID}"); } } } } } using (TextWriter writer = new StreamWriter("../../Data/DBStaging/pax_travel.csv", false, csvEncoding)) { foreach (KeyValuePair <string, int> keyValuePair in paxTravel) { string[] fromTo = keyValuePair.Key.Split('|'); writer.WriteLine($"{keyValuePair.Value}, {fromTo[0]}, {fromTo[1]}"); } } }
public static GameObject InstantiateMe(GameObject prototype, Vector3 pos, Quaternion rotation, AirportData airportData) { var newObject = Instantiate(prototype, pos, rotation); var airportScript = newObject.GetComponent <Airport>(); //var x = newObject. airportScript.data = airportData; var child = newObject.transform.Find("nameLabel").gameObject; var text = child.GetComponent("TextMeshPro") as TextMeshPro; text.text = airportData.ICAO; if (airportData.ICAO.StartsWith("C")) { text.color = new Color(1, 0, 0); } return(newObject); }
public async Task StartAsync(IDialogContext context) { try { var hasil = AirportData.GetAPTV(); if (hasil != null) { Activity replyToConversation = context.MakeMessage() as Activity; //message.CreateReply("Should go to conversation, in list format"); replyToConversation.AttachmentLayout = AttachmentLayoutTypes.List; replyToConversation.Attachments = new List <Attachment>(); //replyToConversation.ReplyToId = context.Activity.ReplyToId; Dictionary <string, string> cardContentList = new Dictionary <string, string>(); foreach (var item in hasil) { List <CardImage> cardImages = new List <CardImage>(); cardImages.Add(new CardImage(url: item.potrait)); List <CardAction> cardButtons = new List <CardAction>(); CardAction plButton = new CardAction() { Value = $"{item.content}", Type = "playVideo", Title = "Play Video" }; cardButtons.Add(plButton); ThumbnailCard plCard = new ThumbnailCard() { Title = $"{Tools.StripHTML(item.TITTLE)}", Text = $"{Tools.StripHTML(item.DESCRIPTION)}", Images = cardImages, Buttons = cardButtons }; Attachment plAttachment = plCard.ToAttachment(); replyToConversation.Attachments.Add(plAttachment); } await context.PostAsync(replyToConversation); } else { await context.PostAsync("No result.."); } } catch (FormCanceledException ex) { string reply; if (ex.InnerException == null) { reply = MESSAGESINFO.CANCEL_DIALOG; } else { reply = $"{MESSAGESINFO.ERROR_INFO} Detail: {ex.InnerException.Message}"; } await context.PostAsync(reply); } finally { context.Done <object>(null); } }
public static IForm <ShoppingQuery> BuildForm() { OnCompletionAsyncDelegate <ShoppingQuery> processShopping = async(context, state) => { await Task.Run(async() => { state.NoShopping = $"SP-{DateTime.Now.ToString("dd_MM_yyyy_HH_mm_ss")}"; state.TanggalShopping = DateTime.Now; StateClient stateClient = context.Activity.GetStateClient(); BotData botData = await stateClient.BotState.GetUserDataAsync(context.Activity.ChannelId, context.Activity.From.Id); var myUserData = botData.GetProperty <Cart>("MyCart"); if (myUserData == null) { myUserData = new Cart(); myUserData.Nama = state.Nama; myUserData.NoShopping = state.NoShopping; myUserData.TanggalShopping = state.TanggalShopping; myUserData.Telpon = state.Telpon; myUserData.Total = 0; myUserData.Tax = 0; } if (myUserData.Items == null) { myUserData.Items = new List <CartItem>(); } myUserData.Items.Add(new CartItem() { KodeProduk = state.KodeProduk, Price = state.Price, ProductName = state.ProductName, Qty = state.Qty, Total = state.Qty *state.Price }); double TotAll = 0; //calculate total and tax foreach (var item in myUserData.Items) { TotAll += item.Total; } myUserData.Total = TotAll; myUserData.Tax = TotAll * 0.1; botData.SetProperty <Cart>("MyCart", myUserData); await stateClient.BotState.SetUserDataAsync(context.Activity.ChannelId, context.Activity.From.Id, botData); await AirportData.InsertShoppingOrder(myUserData); } ); }; var builder = new FormBuilder <ShoppingQuery>(false); var form = builder .Field(nameof(Nama)) .Field(nameof(Alamat)) .Field(nameof(Telpon)) .Field(nameof(Email)) .Field(nameof(KodeProduk), validate: async(state, value) => { var result = new ValidateResult { IsValid = true, Value = value, Feedback = "product ready" }; var p = AirportProduct.GetItemByID(value.ToString()); if (p != null) { state.Price = p.Harga; state.ProductName = p.Name; state.Stock = p.Stock; result.Feedback = $"product is available."; result.IsValid = true; } else { result.Feedback = $"product is not available."; result.IsValid = false; } return(result); }) .Field(nameof(Qty), validate: async(state, value) => { var result = new ValidateResult { IsValid = true, Value = value, Feedback = "product ready" }; var ok = int.TryParse(value.ToString(), out int Request); /* * if (ok && Request >= state.Stock && Request > 0) * { * result.Feedback = $"quantity is ok."; * result.IsValid = true; * * } * else * { * result.Feedback = $"stock is not ready, fill with lower quantity."; * result.IsValid = false; * * }*/ return(result); }) .Confirm(async(state) => { var pesan = $"your order is {state.Qty} items of {state.ProductName}, is it pk ?"; return(new PromptAttribute(pesan)); }) .Message("Thanks, we will proceed your order!") .OnCompletion(processShopping) .Build(); return(form); }
//-------------------------------------------------------------------------------------------------------------------------------- public FlightPlanLeg(AirportData airportData, ulong loaded) { this.airportData = airportData; this.loaded = loaded; }
//----------------------------------------------------------------------------------------------------------------------------- public AStarNode(AStarNode parent, AirportData airportData) { this.parent = parent; this.airportData = airportData; }
/// <summary> /// Convert to GeoPoint <see cref="GeoPoint"/> /// </summary> /// <returns></returns> public static GeoPoint ConvertToGeoPoint(this AirportData airportData) { return(new GeoPoint(airportData.Location.Lon, airportData.Location.Lat)); }
//-------------------------------------------------------------------------------------------------------------------------------- public bool Equals(AirportData from, AirportData to, int cargo, int passenger) { return(this.from == from && this.to == to && this.cargo == cargo && this.passenger == passenger); }
public async Task StartAsync(IDialogContext context) { try { var hasil = AirportData.GetLatestNews(); if (hasil != null) { Activity replyToConversation = context.MakeMessage() as Activity; //message.CreateReply("Should go to conversation, in list format"); replyToConversation.Attachments = new List <Attachment>(); foreach (var item in hasil) { AdaptiveCard card = new AdaptiveCard(); // Specify speech for the card. card.Speak = $"<s>{Tools.StripHTML( item.CONTENT_ENG)}</s>"; // Add text to the card. card.Body.Add(new TextBlock() { Text = $"{item.TITLE_ENG}", Size = TextSize.Medium, Weight = TextWeight.Normal, Wrap = true }); card.Body.Add(new TextBlock() { Text = $"published at {item.DATE_PUBLISH.Replace(":00:000AM",string.Empty).Replace(":00:000PM", string.Empty)} by {item.CREATED_BY}", Size = TextSize.Normal, Weight = TextWeight.Lighter }); card.Body.Add(new Image() { Url = $"{item.IMAGES}", Size = ImageSize.Auto }); // Add text to the card. card.Body.Add(new TextBlock() { Wrap = true, Text = $"{Tools.StripHTML(item.CONTENT_ENG)}" }); card.Actions.Add(new HttpAction() { Url = $"{item.ATTACHMENT}", Title = "Open" }); // Create the attachment. Attachment attachment = new Attachment() { ContentType = AdaptiveCard.ContentType, Content = card }; replyToConversation.Attachments.Add(attachment); } await context.PostAsync(replyToConversation); } else { await context.PostAsync("No result.."); } } catch (FormCanceledException ex) { string reply; if (ex.InnerException == null) { reply = MESSAGESINFO.CANCEL_DIALOG; } else { reply = $"{MESSAGESINFO.ERROR_INFO} Detail: {ex.InnerException.Message}"; } await context.PostAsync(reply); } finally { context.Done <object>(null); } }
public static IForm <Laporan> BuildForm() { OnCompletionAsyncDelegate <Laporan> processReport = async(context, state) => { await Task.Run(() => { state.NoLaporan = $"LP-{DateTime.Now.ToString("dd_MM_yyyy_HH_mm_ss")}"; state.TglLaporan = DateTime.Now; Complain com = new Complain() { Email = state.Email, Keterangan = state.Keterangan, Lokasi = state.Lokasi, Nama = state.Nama, NoLaporan = state.NoLaporan, SkalaPrioritas = state.SkalaPrioritas, Telpon = state.Telpon, TglLaporan = state.TglLaporan, TipeLaporan = state.TipeLaporan, Waktu = state.Waktu }; AirportData.InsertComplain(com); } ); }; var builder = new FormBuilder <Laporan>(false); var form = builder .Field(nameof(Nama)) .Field(nameof(Telpon)) .Field(nameof(Email)) .Field(nameof(TipeLaporan)) .Field(nameof(Keterangan)) .Field(nameof(Lokasi)) .Field(nameof(Waktu)) .Field(nameof(SkalaPrioritas), validate: async(state, value) => { var result = new ValidateResult { IsValid = true, Value = value, Feedback = "ok, skala valid" }; bool res = int.TryParse(value.ToString(), out int jml); if (res) { if (jml <= 0) { result.Feedback = "please input with correct number, minimum value is 1"; result.IsValid = false; } else if (jml > 10) { result.Feedback = "please input the correct number, maximum value is 10"; result.IsValid = false; } } else { result.Feedback = "please input with number"; result.IsValid = false; } return(result); }) .Confirm(async(state) => { var pesan = $"We have received report from {state.Nama} about {state.TipeLaporan.ToString()}, is it valid ?"; return(new PromptAttribute(pesan)); }) .Message($"Thanks for your report.") .OnCompletion(processReport) .Build(); return(form); }