private async Task GetWeather() { Http.DefaultRequestHeaders.Add("Accept", "application/vnd.noaa.dwml+json;version=1"); Http.DefaultRequestHeaders.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36"); // get location info from zip try { errorMessage = ""; var zipresultStr = await Http.GetStringAsync($"http://api.zippopotam.us/US/{zip}"); zipresultStr = zipresultStr.Replace("place name", "city").Replace("state abbreviation", "stateabbr"); ziplookup = JsonUtil.Deserialize <Models.ZipLookup>(zipresultStr); } catch { errorMessage = "Invalid zip code"; return; } // get current condition by zip currentcondition = await Http.GetJsonAsync <Models.CurrentConditions>($"http://api.openweathermap.org/data/2.5/weather?zip={zip},us&appid=93f0b74104f16e4f15a144056218b830"); imgurl = $"http://openweathermap.org/img/w/{currentcondition.weather[0].icon}.png"; // retrieve nws alerts for state alerts = await Http.GetJsonAsync <Models.Alert>($"https://api.weather.gov/alerts/active/area/{ziplookup.places[0].stateabbr}"); weatherLoaded = true; }
public static DTO.AlertDTO ToDTO(this Models.Alert priority) { return(new DTO.AlertDTO() { ID = priority.ID, TimeBeforeStart = priority.TimeBeforeStart }); }
public IViewComponentResult Invoke(string message) { Models.Alert alert = new Models.Alert() { Message = message }; return(View("Alert", alert)); }
public static Alert ToViewModel(this Models.Alert alert) { return(new Alert { Id = alert.Id, Title = alert.Description, Description = $"{alert.FloorNumber}层-{alert.RoomName}-{alert.BedNumber}床 分机号:{alert.SlaveNumber}", Status = alert.Status, AlertTime = alert.AlertTime, RespondUserName = string.IsNullOrEmpty(alert.RespondUserName)?@"无人处理":alert.RespondUserName }); }
private string GetNoteLocale(Models.Alert item) { var culture = CultureHelper.GetCurrentCulture(); var name = item.Translations[culture]?.Note; if (string.IsNullOrEmpty(name)) { name = item.Note; } return(name); }
public static void DoWork(object oParams) { try { TweetThreadParams twParams = oParams as TweetThreadParams; string sUserName = twParams.sUserName; Models.TwitterUserContext dbContext = twParams.dbContext; Models.TwitterUser myUser = twParams.myUser; TwitterUser[] mylist = null; try { mylist = Utils.TwitterUtils.GetFollowersFor(sUserName); } catch { return; } var dbFollowers = myUser.Followers; // First time for start tracking if (dbFollowers == null) { foreach (TwitterUser user in mylist) { Models.Follower follow = new Models.Follower() { TwitterUser = myUser, ID = Guid.NewGuid().ToString(), Username = user.ScreenName }; dbContext.Followers.Add(follow); } dbContext.SaveChanges(); myUser.LastPull = DateTime.Now; dbContext.Entry(myUser).State = System.Data.EntityState.Modified; dbContext.SaveChanges(); //ViewBag.UserCollection = "empty"; //return View(); } else { // Process myUser.LastPull = DateTime.Now; dbContext.Entry(myUser).State = System.Data.EntityState.Modified; // Old dbFollowers // new myList List<string> newestFollowers = new List<string>(); foreach (TwitterUser user in mylist) { newestFollowers.Add(user.ScreenName); } // Get the list of unfollowers foreach (Models.Follower follower in dbFollowers) { if (newestFollowers.Contains(follower.Username) == false) { Models.Unfollowers unfollow = new Models.Unfollowers() { TwitterUser = myUser, Username = follower.Username, ID = Guid.NewGuid().ToString(), FoundTime = DateTime.Now }; dbContext.Unfollowers.Add(unfollow); // If sign up for alerts if (myUser.DoAlert == true) { Models.Alert alert = new Models.Alert() { TwitterUser = myUser, Username = follower.Username, ID = Guid.NewGuid().ToString(), FoundTime = DateTime.Now }; dbContext.Alerts.Add(alert); } } try { dbContext.SaveChanges(); } catch { } } while (myUser.Followers.Count > 0) { Models.Follower foll = myUser.Followers.ElementAt(0); dbContext.Entry(foll).State = System.Data.EntityState.Deleted; } dbContext.SaveChanges(); // Reset the followers foreach (TwitterUser user in mylist) { Models.Follower follow = new Models.Follower() { TwitterUser = myUser, ID = Guid.NewGuid().ToString(), Username = user.ScreenName }; dbContext.Followers.Add(follow); } dbContext.SaveChanges(); } } catch { } }
public async Task <SaveResultEnvelope> Handle(Command request, CancellationToken cancellationToken) { Models.Alert alert = null; if (request.MasterId == Guid.Empty) { throw new RestException(HttpStatusCode.Unauthorized, new { Error = ErrorMessages.MasterIdDidNotBind }); } var boundFloor = await _context.Floors.SingleOrDefaultAsync(f => f.MasterId == request.MasterId, cancellationToken); if (boundFloor == null) { throw new RestException(HttpStatusCode.Unauthorized, new { Error = ErrorMessages.MasterIdDidNotBind }); } if (request.Message != AlertMessage.Time) { var masterId = request.MasterId; var floor = _context.Floors .Include(f => f.Building) .Include(f => f.Rooms) .ThenInclude(x => x.Beds) .SingleOrDefault(f => f.MasterId == masterId); var building = floor.Building; var bed = floor.Rooms.SelectMany(x => x.Beds).SingleOrDefault(b => b.SlaveNumber == request.SlaveNumber); var room = bed.Room; alert = await _context.Alerts.SingleOrDefaultAsync( a => a.BedNumber == bed.Number && a.SlaveNumber == bed.SlaveNumber && (a.Message == AlertMessage.NormalCall || a.Message == AlertMessage.UrgencyCall), cancellationToken); if (alert != null) { if (request.Message != AlertMessage.UrgencyCall && request.Message != AlertMessage.NormalCall) { alert.Status = AlertStatus.Reset; } } else { alert = new Models.Alert { Id = Guid.NewGuid(), Message = request.Message, Description = request.Description, BuildingId = building.Id, BuildingName = building.Name, FloorId = floor.Id, FloorNumber = floor.Number, FloorDescription = floor.Description, RoomId = room.Id, RoomName = room.Name, RoomNumber = room.Number, BedNumber = bed.Number, MasterId = request.MasterId, SlaveNumber = request.SlaveNumber, AlertTime = request.AlertTime, Status = AlertStatus.New }; _context.Alerts.Add(alert); } await _context.SaveChangesAsync(cancellationToken); var alertViewModel = alert.ToViewModel(); var result = new SaveResult { AlertId = alert.Id, AlertTime = alert.AlertTime, Description = alert.Description, Status = SaveAlertStatus.Saved, Message = alert.Status == AlertStatus.Reset?@"已重置报警信息":@"已添加报警信息" }; return(new SaveResultEnvelope(alertViewModel, result)); } return(new SaveResultEnvelope { Skipped = true }); }