// GET: IoT public async Task <ActionResult> Index() { List <Incident> incidents; using (var client = IncidentApiHelper.GetIncidentAPIClient()) { int CACHE_EXPIRATION_SECONDS = 60; //Check Cache string cachedData = string.Empty; if (RedisCacheHelper.UseCachedDataSet(Settings.REDISCCACHE_KEY_INCIDENTDATA, out cachedData)) { incidents = JsonConvert.DeserializeObject <List <Incident> >(cachedData); } else { //If stale refresh var results = await client.IncidentOperations.GetAllIncidentsAsync(); Newtonsoft.Json.Linq.JArray ja = (Newtonsoft.Json.Linq.JArray)results; incidents = ja.ToObject <List <Incident> >(); RedisCacheHelper.AddtoCache(Settings.REDISCCACHE_KEY_INCIDENTDATA, incidents, CACHE_EXPIRATION_SECONDS); } } return(View(incidents)); }
public async Task <ActionResult> Index() { //##### API DATA HERE ##### List <Incident> incidents; using (var client = IncidentApiHelper.GetIncidentAPIClient()) { //##### Add caching here ##### int CACHE_EXPIRATION_SECONDS = 60; //Check Cache string cachedData = string.Empty; if (RedisCacheHelper.UseCachedDataSet(Settings.REDISCCACHE_KEY_INCIDENTDATA, out cachedData)) { incidents = JsonConvert.DeserializeObject <List <Incident> >(cachedData); } else { //If stale refresh var results = await client.Incident.GetAllIncidentsAsync(); incidents = JsonConvert.DeserializeObject <List <Incident> >(results); RedisCacheHelper.AddtoCache(Settings.REDISCCACHE_KEY_INCIDENTDATA, incidents, CACHE_EXPIRATION_SECONDS); } //##### Add caching here ##### } //##### API DATA HERE ##### return(View(incidents)); }
public async Task <ActionResult> Create([Bind(Include = "City,Created,Description,FirstName,ImageUri,IsEmergency,LastModified,LastName,OutageType,PhoneNumber,Resolved,State,Street,ZipCode")] IncidentViewModel incident, HttpPostedFileBase imageFile) { try { if (ModelState.IsValid) { Incident incidentToSave = IncidentMapper.MapIncidentViewModel(incident); using (IncidentAPIClient client = IncidentApiHelper.GetIncidentAPIClient()) { var result = client.IncidentOperations.CreateIncident(incidentToSave); Newtonsoft.Json.Linq.JObject jobj = (Newtonsoft.Json.Linq.JObject)result; incidentToSave = jobj.ToObject <Incident>(); } //TODO: ADD CODE TO UPLOAD THE BLOB //Now upload the file if there is one if (imageFile != null && imageFile.ContentLength > 0) { //### Add Blob Upload code here ##### //Give the image a unique name based on the incident id var imageUrl = await StorageHelper.UploadFileToBlobStorage(incidentToSave.Id, imageFile); //### Add Blob Upload code here ##### //### Add Queue code here ##### //Add a message to the queue to process this image await StorageHelper.AddMessageToQueue(incidentToSave.Id, imageFile.FileName); //### Add Queue code here ##### } ////##### CLEAR CACHE #### //RedisCacheHelper.ClearCache(Settings.REDISCCACHE_KEY_INCIDENTDATA); //##### CLEAR CACHE #### //##### SEND EMAIL ##### await SendIncidentEmail(incidentToSave); //##### SEND EMAIL ##### await CreateEvent(incidentToSave); return(RedirectToAction("Index", "Dashboard")); } } catch { return(View()); } return(View(incident)); }
public async Task <ActionResult> Create([Bind(Include = "City,Created,Description,FirstName,ImageUri,IsEmergency,LastModified,LastName,OutageType,PhoneNumber,Resolved,State,Street,ZipCode")] IncidentViewModel incident, HttpPostedFileBase imageFile) { try { if (ModelState.IsValid) { Incident incidentToSave = IncidentMappers.MapIncidentViewModel(incident); using (IncidentAPIClient client = IncidentApiHelper.GetIncidentAPIClient()) { var result = client.Incident.CreateIncident(incidentToSave); if (!string.IsNullOrEmpty(result)) { incidentToSave = JsonConvert.DeserializeObject <Incident>(result); } } //Now upload the file if there is one if (imageFile != null && imageFile.ContentLength > 0) { //### Add Blob Upload code here ##### //Give the image a unique name based on the incident id var imageUrl = await StorageHelper.UploadFileToBlobStorage(incidentToSave.ID, imageFile); //### Add Blob Upload code here ##### //### Add Queue code here ##### //Add a message to the queue to process this image await StorageHelper.AddMessageToQueue(incidentToSave.ID, imageFile.FileName); //### Add Queue code here ##### } //##### CLEAR CACHE #### RedisCacheHelper.ClearCache(Settings.REDISCCACHE_KEY_INCIDENTDATA); //##### CLEAR CACHE #### //##### SEND EMAIL ##### await SendIncidentEmail(incidentToSave, Url.Action("Index", "Dashboard", null, Request.Url.Scheme)); //##### SEND EMAIL ##### return(RedirectToAction("Index", "Dashboard")); } } catch { return(View()); } return(View(incident)); }
public ActionResult Details(string Id) { IncidentViewModel incidentView = null; using (IncidentAPIClient client = IncidentApiHelper.GetIncidentAPIClient()) { var result = client.IncidentOperations.GetById(Id); Newtonsoft.Json.Linq.JObject jobj = (Newtonsoft.Json.Linq.JObject)result; Incident incident = jobj.ToObject <Incident>(); incidentView = IncidentMapper.MapIncidentModelToView(incident); } return(View(incidentView)); }
public ActionResult Details(string Id) { IncidentViewModel incidentView = null; using (IncidentAPIClient client = IncidentApiHelper.GetIncidentAPIClient()) { var result = client.Incident.GetById(Id); if (!string.IsNullOrEmpty(result)) { Incident incident = JsonConvert.DeserializeObject <Incident>(result); incidentView = IncidentMappers.MapIncidentModelToView(incident); } } return(View(incidentView)); }