Ejemplo n.º 1
0
        public async Task <HttpResponseMessage> UnRegisterDevice([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.UnRegister(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.UnRegister(pushUri);
                    }

                    return(Request.CreateResponse(HttpStatusCode.Created));
                }
                catch (Exception ex)
                {
                    Framework.Logging.LogException(ex);
                    throw HttpStatusCode.InternalServerError.AsException();
                }
            }

            throw HttpStatusCode.BadRequest.AsException();
        }
Ejemplo n.º 2
0
        public bool CanUserDeletePushUri(string userId, int pushUriId)
        {
            var pushUri = _pushUriService.GetPushUriById(pushUriId);

            if (pushUri != null)
            {
                if (pushUri.UserId == userId)
                {
                    return(true);
                }
            }

            return(false);
        }