private async Task <bool> UserDeviceDeleteInternal(ExPostUserDeviceDelete userDeviceData) { Logging.Log.LogInfo($"UserDeviceDelete {userDeviceData.DeviceToken}"); using (var db = new Db()) { var data = db.TblUserDevices.Where(d => d.Device.DeviceToken == userDeviceData.DeviceToken); db.TblUserDevices.RemoveRange(data); try { var service = new MobileCenterNotification(Constants.MobileCenterNotification); if (data.Any()) { await service.RemoveDevice(data.First().Device.DeviceToken, data.First().Device.Plattform); } db.SaveChanges(); } catch (Exception e) { Logging.Log.LogWarning($"UserDeviceDelete SaveChanges: {e}"); return(false); } return(true); } }
public async Task <bool> UserDeviceDeleteWeb([FromBody] ExPostUserDeviceDelete userDeviceData) { if (userDeviceData.CheckPassword != WebAppSettings.CheckPassword) { HttpContext.Response.StatusCode = Unauthorized().StatusCode; return(false); } return(await UserDeviceDeleteInternal(userDeviceData)); }
public async Task <IActionResult> Device_Destroy([DataSourceRequest] DataSourceRequest request, ExExtendedUserDeviceInfo device) { RestAccess ra = new RestAccess(Constants.ServiceClientEndPointWithApiPrefix); ExPostUserDeviceDelete model = new ExPostUserDeviceDelete(); model.UserId = device.UserId; model.DeviceToken = device.DeviceToken; model.Plattform = device.Plattform; model.CheckPassword = WebAppSettings.CheckPassword; var res = await ra.UserDeviceDeleteWeb(model); return(Json(true)); }
public async Task <bool> UserDeviceDelete([FromBody] ExPostUserDeviceDelete userDeviceData) { ClaimsIdentity identity = null; try { identity = HttpContext.User.Identity as ClaimsIdentity; } catch (Exception e) { Logging.Log.LogError("No Claims identity"); } if (identity != null) { var claims = identity.Claims; if (!identity.HasClaim(c => c.Type == "UserID")) { HttpContext.Response.StatusCode = Unauthorized().StatusCode; return(false); } var userId = identity.HasClaim(c => c.Type == "UserID") ? identity.FindFirst("UserID").Value : "a"; //BENUTZER ID if (userDeviceData.UserId.ToString() != userId) { HttpContext.Response.StatusCode = Unauthorized().StatusCode; return(false); } } else { HttpContext.Response.StatusCode = Unauthorized().StatusCode; return(false); } return(await UserDeviceDeleteInternal(userDeviceData)); }
/// <summary> /// Ein Gerät eines Benutzers aus dessen Geräteliste entfernen für WebApp /// </summary> /// <param name="userDeviceData"></param> /// <returns></returns> public async Task <ResultData <bool?> > UserDeviceDeleteWeb(ExPostUserDeviceDelete userDeviceData) { return(await _wap.Post <bool?>("UserDeviceDeleteWeb", userDeviceData)); }