public static List <HistorySearch> GetAllRecords(string jsonString) { List <HistorySearch> records = new List <HistorySearch>(); HistorySearch itemHis = null; try { var jObject = JObject.Parse(jsonString); JArray itemArrary = (JArray)jObject["Histories"]; if (itemArrary != null) { foreach (var item in itemArrary) { itemHis = new HistorySearch() { coord = new Coord() { lat = Double.Parse(item["latitude"].ToString()), lon = Double.Parse(item["longtitude"].ToString()) }, nameLocation = item["nameLocation"].ToString() }; records.Add(itemHis); } } }catch (Exception ex) { throw ex; } return(records); }
public ActionResult <ReturnObject> GetWalletHistory([FromBody] HistorySearch walletSearch) { try { // var _history = _walletBusiness.GetHistory(walletSearch.wallet, 1, 3, new string[] { nameof(BlockchainTransaction.CreatedAt) }); var userModel = (User)RouteData.Values[ParseDataKeyApi.KEY_PASS_DATA_USER_MODEL]; int numberData; var history = _walletBusiness.GetHistory(out numberData, userModel.Id, walletSearch.NetworkName, walletSearch.Offset, walletSearch.Limit, walletSearch.OrderBy, walletSearch.Search); return(new ReturnObject() { Status = Status.STATUS_SUCCESS, Data = numberData.ToString(), Message = JsonHelper.SerializeObject(history) }); } catch (Exception e) { return(new ReturnObject() { Status = Status.STATUS_ERROR, Message = e.Message }); } // return null; }
public static void SaveSearch(HistorySearch obj) { FileStream f; if (!System.IO.File.Exists(path)) { f = System.IO.File.Create(path); System.IO.File.WriteAllText(path, "'Histories':[]"); } try { if (!checkItemExisting(obj)) { var newRecord = parseToString(obj); var json = File.ReadAllText(path); var jsonObj = JObject.Parse(json); var itemArrary = jsonObj.GetValue("Histories") as JArray; var newItem = JObject.Parse(json); itemArrary.Add(newItem); jsonObj["Histories"] = itemArrary; string newJsonResult = Newtonsoft.Json.JsonConvert.SerializeObject(jsonObj, Newtonsoft.Json.Formatting.Indented); File.WriteAllText(path, newJsonResult); } } catch (Exception ex) { Console.WriteLine("Add Error : " + ex.Message.ToString()); } }
public static bool checkItemExisting(HistorySearch obj) { var json = File.ReadAllText(path); bool isExisting = false; try { var jObject = JObject.Parse(json); JArray itemArrary = (JArray)jObject["Histories"]; isExisting = itemArrary.Select(x => x["latitude"].Equals(obj.coord.lat.ToString()) && x["longtitude"].Equals(obj.coord.lat.ToString())).First(); } catch (Exception ex) { throw ex; } return(isExisting); }
private void LoadHistorySearch() { string query = "select * from HistorySearch"; connection.Open(); SqlCommand cmd = new SqlCommand(query, connection); SqlDataReader reader = cmd.ExecuteReader(); HistorySearches.Clear(); while (reader.Read()) { HistorySearch c = new HistorySearch() { Id = (int)reader["Id"], Name = (string)reader["Name"] }; HistorySearches.Add(c); } connection.Close(); }
//load from cookie public void retrieveInfo(HistorySearch obj) { if (Request.Cookies["HistorySearches"] != null) { //already there string cookievalue = Request.Cookies["HistorySearches"].Value.ToString(); openWeatherMap.historySearchs = JsonConvert.DeserializeObject <List <HistorySearch> >(cookievalue); } else { //create one if (openWeatherMap.historySearchs == null) { openWeatherMap.historySearchs = new List <HistorySearch>(); } } if (obj != null) { HistorySearch item = null; if (openWeatherMap.historySearchs != null) { item = openWeatherMap.historySearchs.Find(x => x.coord.lat == obj.coord.lat && x.coord.lon == obj.coord.lon); } else { openWeatherMap.historySearchs = new List <HistorySearch>(); } if (item == null) { openWeatherMap.historySearchs.Add(obj); } else { openWeatherMap.historySearchs.Find(x => x.coord.lat == obj.coord.lat && x.coord.lon == obj.coord.lon).count++; } } }
public ActionResult Index(string curlat, string curlon, string requestString) { Coord currentLocation = null; int type = 0; // navigating search criteria if (!String.IsNullOrEmpty(requestString) || (!String.IsNullOrEmpty(curlat) && !String.IsNullOrEmpty(curlon))) { ResponseWeather rootObjectt = new ResponseWeather(); List <Forecastday> weekInfo = new List <Forecastday>(); requestString = requestString.Trim(); if (Regex.Match(requestString, @"^\d{5}$", RegexOptions.IgnoreCase).Success) {//search by zip code type = 2; openWeatherMap.apiResponse = ""; } else if (Regex.Match(requestString, @"^\w+\,\w+$", RegexOptions.IgnoreCase).Success) {//search by city (Lacey,us), (danang,vn) type = 1; openWeatherMap.apiResponse = ""; } else if (String.IsNullOrEmpty(curlat) == false && String.IsNullOrEmpty(curlon) == false) {//current location currentLocation = new Coord() { lat = Double.Parse(curlat), lon = Double.Parse(curlon) }; type = 3; } else { openWeatherMap.apiResponse = "Invalid zipcode or city"; return(View(openWeatherMap)); } if (type == 0) { openWeatherMap.apiResponse = "Nothing to render"; return(View(openWeatherMap)); } myService.getResponseWeather(searchText: requestString, cor: currentLocation, type: type, rootObject: ref rootObjectt, weekData: ref weekInfo ); openWeatherMap.rootObject = rootObjectt; if (rootObjectt != null) { var recent = new HistorySearch() { coord = rootObjectt.coord, nameLocation = rootObjectt.name }; retrieveInfo(recent); saveToCookie(openWeatherMap.historySearchs); weekInfo.ForEach(x => x.date = DateTime.Parse(x.date).Month.ToString() + "/" + DateTime.Parse(x.date).Day.ToString()); openWeatherMap.forecastResponse = weekInfo; } else { openWeatherMap.apiResponse = "Info you are searching is not found"; return(View(openWeatherMap)); } } else if (Request.Form["submit"] != null) { openWeatherMap.apiResponse = "Put in city or zip code"; } return(View(openWeatherMap)); }
public static string parseToString(HistorySearch obj) { return("{ 'latitude': " + obj.coord.lat + ", 'longtitude': '" + obj.coord.lon + ", 'nameLocation': '" + obj.nameLocation + "'}"); }
private bool HistoryFilter(TabVM tab) { return(HistorySearch.IsNullOrEmpty() || Regex.IsMatch(tab.File, Regex.Escape(HistorySearch), RegexOptions.IgnoreCase)); }
private IQueryable <DocEntityHistory> _ExecSearch(HistorySearch request, DocQuery query) { request = InitSearch <History, HistorySearch>(request); IQueryable <DocEntityHistory> entities = null; query.Run(session => { entities = query.SelectAll <DocEntityHistory>(); if (!DocTools.IsNullOrEmpty(request.FullTextSearch)) { var fts = new HistoryFullTextSearch(request); entities = GetFullTextSearch <DocEntityHistory, HistoryFullTextSearch>(fts, entities); } if (null != request.Ids && request.Ids.Any()) { entities = entities.Where(en => en.Id.In(request.Ids)); } if (!DocTools.IsNullOrEmpty(request.Updated)) { entities = entities.Where(e => null != e.Updated && e.Updated.Value.Date == request.Updated.Value.Date); } if (!DocTools.IsNullOrEmpty(request.UpdatedBefore)) { entities = entities.Where(e => null != e.Updated && e.Updated <= request.UpdatedBefore); } if (!DocTools.IsNullOrEmpty(request.UpdatedAfter)) { entities = entities.Where(e => null != e.Updated && e.Updated >= request.UpdatedAfter); } if (!DocTools.IsNullOrEmpty(request.Created)) { entities = entities.Where(e => null != e.Created && e.Created.Value.Date == request.Created.Value.Date); } if (!DocTools.IsNullOrEmpty(request.CreatedBefore)) { entities = entities.Where(e => null != e.Created && e.Created <= request.CreatedBefore); } if (!DocTools.IsNullOrEmpty(request.CreatedAfter)) { entities = entities.Where(e => null != e.Created && e.Created >= request.CreatedAfter); } if (true == request.Archived?.Any() && currentUser.HasProperty(DocConstantModelName.HISTORY, nameof(Reference.Archived), DocConstantPermission.VIEW)) { entities = entities.Where(en => en.Archived.In(request.Archived)); } else { entities = entities.Where(en => !en.Archived); } if (true == request.Locked?.Any()) { entities = entities.Where(en => en.Locked.In(request.Locked)); } if (!DocTools.IsNullOrEmpty(request.App) && !DocTools.IsNullOrEmpty(request.App.Id)) { entities = entities.Where(en => en.App.Id == request.App.Id); } if (true == request.AppIds?.Any()) { entities = entities.Where(en => en.App.Id.In(request.AppIds)); } if (!DocTools.IsNullOrEmpty(request.DocumentSet) && !DocTools.IsNullOrEmpty(request.DocumentSet.Id)) { entities = entities.Where(en => en.DocumentSet.Id == request.DocumentSet.Id); } if (true == request.DocumentSetIds?.Any()) { entities = entities.Where(en => en.DocumentSet.Id.In(request.DocumentSetIds)); } if (!DocTools.IsNullOrEmpty(request.Impersonation) && !DocTools.IsNullOrEmpty(request.Impersonation.Id)) { entities = entities.Where(en => en.Impersonation.Id == request.Impersonation.Id); } if (true == request.ImpersonationIds?.Any()) { entities = entities.Where(en => en.Impersonation.Id.In(request.ImpersonationIds)); } if (!DocTools.IsNullOrEmpty(request.Page) && !DocTools.IsNullOrEmpty(request.Page.Id)) { entities = entities.Where(en => en.Page.Id == request.Page.Id); } if (true == request.PageIds?.Any()) { entities = entities.Where(en => en.Page.Id.In(request.PageIds)); } if (!DocTools.IsNullOrEmpty(request.URL)) { entities = entities.Where(en => en.URL.Contains(request.URL)); } if (!DocTools.IsNullOrEmpty(request.URLs)) { entities = entities.Where(en => en.URL.In(request.URLs)); } if (!DocTools.IsNullOrEmpty(request.User) && !DocTools.IsNullOrEmpty(request.User.Id)) { entities = entities.Where(en => en.User.Id == request.User.Id); } if (true == request.UserIds?.Any()) { entities = entities.Where(en => en.User.Id.In(request.UserIds)); } if (!DocTools.IsNullOrEmpty(request.UserSession) && !DocTools.IsNullOrEmpty(request.UserSession.Id)) { entities = entities.Where(en => en.UserSession.Id == request.UserSession.Id); } if (true == request.UserSessionIds?.Any()) { entities = entities.Where(en => en.UserSession.Id.In(request.UserSessionIds)); } if (!DocTools.IsNullOrEmpty(request.Workflow) && !DocTools.IsNullOrEmpty(request.Workflow.Id)) { entities = entities.Where(en => en.Workflow.Id == request.Workflow.Id); } if (true == request.WorkflowIds?.Any()) { entities = entities.Where(en => en.Workflow.Id.In(request.WorkflowIds)); } entities = ApplyFilters <DocEntityHistory, HistorySearch>(request, entities); if (request.Skip > 0) { entities = entities.Skip(request.Skip.Value); } if (request.Take > 0) { entities = entities.Take(request.Take.Value); } if (true == request?.OrderBy?.Any()) { entities = entities.OrderBy(request.OrderBy); } if (true == request?.OrderByDesc?.Any()) { entities = entities.OrderByDescending(request.OrderByDesc); } }); return(entities); }
public object Get(HistorySearch request) => GetSearchResultWithCache <History, DocEntityHistory, HistorySearch>(DocConstantModelName.HISTORY, request, _ExecSearch);
public object Post(HistorySearch request) => Get(request);