// PUT api/pushdata/5 //public void Put(int id, [FromBody]string value) { //} // DELETE api/pushdata/5 public void Delete(DeviceVM myDevice) { bool continuometodo = true; if (string.IsNullOrEmpty(myDevice.UUID)) { continuometodo = false; } PushNotificationRecord devicetostore = new PushNotificationRecord(); devicetostore.DataModifica = DateTime.Now; switch (myDevice.Device) { case "Apple": if (myDevice.Token.Length > 100) { devicetostore.Device = TipoDispositivo.AppleFCM; } else { devicetostore.Device = TipoDispositivo.Apple; } break; case "Android": devicetostore.Device = TipoDispositivo.Android; break; case "WindowsMobile": devicetostore.Device = TipoDispositivo.WindowsMobile; break; default: continuometodo = false; break; } if (continuometodo) { try { devicetostore.Validated = false; devicetostore.Language = myDevice.Language; devicetostore.Produzione = myDevice.Produzione; devicetostore.Token = myDevice.Token; devicetostore.UUIdentifier = myDevice.UUID; _pushNotificationService.StorePushNotification(devicetostore); } catch (Exception ex) { HttpResponseMessage message = new HttpResponseMessage(System.Net.HttpStatusCode.InternalServerError); message.Content = new StringContent(ex.Message); throw new HttpResponseException(message); } } else { HttpResponseMessage message = new HttpResponseMessage(System.Net.HttpStatusCode.InternalServerError); message.Content = new StringContent("No Device type or UUID specified."); throw new HttpResponseException(message); } }
public HttpResponseMessage Put(DeviceVM myDevice) { bool continuometodo = true; if (string.IsNullOrEmpty(myDevice.UUID)) { continuometodo = false; } PushNotificationRecord devicetostore = new PushNotificationRecord(); devicetostore.DataModifica = DateTime.Now; switch (myDevice.Device) { case "Apple": devicetostore.Device = TipoDispositivo.Apple; break; case "Android": devicetostore.Device = TipoDispositivo.Android; break; case "WindowsMobile": devicetostore.Device = TipoDispositivo.WindowsMobile; break; default: continuometodo = false; break; } if (continuometodo) { try { string host = HttpContext.Current.Request.Url.Host; devicetostore.Validated = true; devicetostore.Language = myDevice.Language; devicetostore.Produzione = myDevice.Produzione; devicetostore.Token = myDevice.Token; devicetostore.UUIdentifier = myDevice.UUID; _pushNotificationService.StorePushNotification(devicetostore); HttpResponseMessage message = new HttpResponseMessage(System.Net.HttpStatusCode.OK); //// response.Headers.Location = new Uri(Request.RequestUri.ToString()); // message.Content = new StringContent( "OK"); // throw new HttpResponseException( return(message); } catch (Exception ex) { HttpResponseMessage message = new HttpResponseMessage(System.Net.HttpStatusCode.InternalServerError); message.Content = new StringContent(ex.Message); throw new HttpResponseException(message); } } else { HttpResponseMessage message = new HttpResponseMessage(System.Net.HttpStatusCode.InternalServerError); message.Content = new StringContent("No Device type or UUID specified."); throw new HttpResponseException(message); } }
public void Crea() { PushNotificationRecord test = new PushNotificationRecord(); test.DataInserimento = DateTime.Today; test.DataModifica = DateTime.Today; test.Device = TipoDispositivo.Apple; //test.Id = 0; test.Validated = true; test.Language = "ITA"; test.Produzione = true; test.Token = "awerwqdasfafsa"; test.UUIdentifier = "iosonounid"; _pushNotificationService.StorePushNotification(test); }
public void StorePushNotification(PushNotificationRecord pushElement) { PushNotificationRecord oldPush = _pushNotificationRepository.Fetch(x => (x.UUIdentifier == pushElement.UUIdentifier || x.Token == pushElement.Token) && x.Produzione == pushElement.Produzione && x.Device == pushElement.Device).FirstOrDefault(); DateTime adesso = DateTime.Now; string oldUUId = ""; if (oldPush != null) // se dispositivo già registrato sovrascrivo lo stesso record { oldUUId = oldPush.UUIdentifier; oldPush.Device = pushElement.Device; oldPush.UUIdentifier = pushElement.UUIdentifier; oldPush.Token = pushElement.Token; oldPush.Validated = pushElement.Validated; oldPush.DataModifica = adesso; oldPush.Produzione = pushElement.Produzione; oldPush.Language = pushElement.Language; // anche se il dispositivo è già esistente, registra host, prefix e machineName dell'ambiente corrente // Rif: https://lasergroup.teamwork.com/index.cfm#tasks/18521520 oldPush.RegistrationUrlHost = _shellSetting.RequestUrlHost ?? ""; oldPush.RegistrationUrlPrefix = _shellSetting.RequestUrlPrefix ?? ""; oldPush.RegistrationMachineName = System.Environment.MachineName ?? ""; oldPush.MobileContactPartRecord_Id = EnsureContactId(oldPush.UUIdentifier); _pushNotificationRepository.Update(oldPush); } else { pushElement.Id = 0; pushElement.DataInserimento = adesso; pushElement.DataModifica = adesso; pushElement.MobileContactPartRecord_Id = EnsureContactId(pushElement.UUIdentifier); // se è un nuovo dispositivo, registra anche host, prefix e machineName dell'ambiente corrente pushElement.RegistrationUrlHost = _shellSetting.RequestUrlHost ?? ""; pushElement.RegistrationUrlPrefix = _shellSetting.RequestUrlPrefix ?? ""; pushElement.RegistrationMachineName = System.Environment.MachineName ?? ""; _pushNotificationRepository.Create(pushElement); } // cerca eventuali record corrispondenti in UserDevice e fa sì che ce ne sia uno solo relativo al nuovo UUIdentifier (quello con l'Id più recente) // eliminando eventualmente i duplicati e i record riferiti al vecchio UUIdentifier; UserDeviceRecord my_disp = null; var elencoNuovi = _userDeviceRecord.Fetch(x => x.UUIdentifier == pushElement.UUIdentifier).OrderByDescending(y => y.Id).ToList(); foreach (var record in elencoNuovi) { if (my_disp == null) { my_disp = record; } else { _userDeviceRecord.Delete(record); } } if (oldPush != null && oldUUId != pushElement.UUIdentifier) { var elencoVecchi = _userDeviceRecord.Fetch(x => x.UUIdentifier == oldUUId).OrderByDescending(y => y.Id).ToList(); foreach (var record in elencoVecchi) { if (my_disp == null) { // aggiorna uno dei record che aveva il vecchio UUIdentifier, quello con l'Id più recente my_disp = record; my_disp.UUIdentifier = pushElement.UUIdentifier; _userDeviceRecord.Update(my_disp); } else { _userDeviceRecord.Delete(record); } } } }