public async Task <ActionResult> UnRegisterUnitDevice([FromQuery] DeviceUnRegistrationInput input) { if (input == null) { return(BadRequest()); } if (this.ModelState.IsValid) { try { if (!String.IsNullOrWhiteSpace(input.Did)) { var deviceId = HttpUtility.UrlDecode(input.Did); await _pushService.UnRegisterUnit(new PushUri() { UserId = UserId, DeviceId = deviceId, PushUriId = input.Pid }); } return(Ok()); } catch (Exception ex) { Framework.Logging.LogException(ex); return(BadRequest()); } } return(BadRequest()); }
public async Task <HttpResponseMessage> UnRegisterUnitDevice([FromUri] DeviceUnRegistrationInput input) { if (input == null) { throw HttpStatusCode.BadRequest.AsException(); } if (this.ModelState.IsValid) { try { if (!String.IsNullOrWhiteSpace(input.Did)) { var deviceId = HttpUtility.UrlDecode(input.Did); var pushUri = _pushUriService.GetPushUriByDeviceId(deviceId); // Sometimes the phone sends back info, we don't want the catch block handing this if (pushUri == null) { return(Request.CreateResponse(HttpStatusCode.OK)); } if (pushUri.UserId != UserId) { return(Request.CreateResponse(HttpStatusCode.Unauthorized)); } await _pushService.UnRegisterUnit(pushUri); } if (input.Pid > 0) { var pushUri = _pushUriService.GetPushUriById(input.Pid); // Sometimes the phone sends back info, we don't want the catch block handing this if (pushUri == null) { return(Request.CreateResponse(HttpStatusCode.OK)); } if (pushUri.UserId != UserId) { throw HttpStatusCode.Unauthorized.AsException(); } await _pushService.UnRegisterUnit(pushUri); } return(Request.CreateResponse(HttpStatusCode.Created)); } catch (Exception ex) { Framework.Logging.LogException(ex); throw HttpStatusCode.InternalServerError.AsException(); } } throw HttpStatusCode.BadRequest.AsException(); }