Exemplo n.º 1
0
        //Registro en el servidor de notificaciones push
        public async Task <bool> RegisterPush(UserDto user)
        {
            var tries  = 5;
            var result = false;

            for (int regTry = 0; regTry < tries && !result; regTry++)
            {
                var token = deviceService.GetToken();
                //var token = Guid.NewGuid().ToString();
                if (!string.IsNullOrEmpty(token))
                {
                    var data = new PushRegistrationDto()
                    {
                        DeviceId    = CrossDeviceInfo.Current.Id,
                        DeviceToken = token,
                        DeviceType  = deviceService.GetDeviceType(),
                        Tags        = GetTags(),
                        Username    = user.Username,
                        Password    = user.Password,
                    };
                    result = await appService.RegisterPush(data);
                }
                await Task.Delay(2000);
            }
            return(result);
        }
Exemplo n.º 2
0
        public bool RegisterPush(PushRegistrationDto push)
        {
            var result = false;

            if (IsValidPush(push) && ValidateLoginUser(push))
            {
                var pushDB = regPushRepository.GetByDeviceId(push.DeviceId);
                if (pushDB == null)
                {
                    var newPush = entityMapper.Map <PushRegistrationDto, PushRegistration>(push);
                    newPush.Id           = Guid.NewGuid();
                    newPush.User         = userRepository.GetUser(push.Username);
                    newPush.CreationDate = DateTime.Now;
                    newPush.UpdateDate   = DateTime.Now;
                    newPush.Tags         = string.Join('|', push.Tags.ToArray());
                    result = regPushRepository.AddPushReg(newPush);
                }
                else
                {
                    pushDB.User       = userRepository.GetUser(push.Username);
                    pushDB.UpdateDate = DateTime.Now;
                    pushDB.Token      = push.DeviceToken;
                    pushDB.Tags       = string.Join('|', push.Tags.ToArray());
                    result            = regPushRepository.Update(pushDB);
                }
            }
            return(result);
        }
Exemplo n.º 3
0
 private bool IsValidPush(PushRegistrationDto push)
 {
     return(push != null &&
            !string.IsNullOrEmpty(push.DeviceToken) &&
            !string.IsNullOrEmpty(push.DeviceId));
 }
Exemplo n.º 4
0
        public async Task <bool> RegisterPush(PushRegistrationDto data)
        {
            var result = await restClientService.PostAsync <PushRegistrationDto, bool>("api/User/RegisterPush", data);

            return(result.Entity);
        }
Exemplo n.º 5
0
        public IActionResult RegisterPush([FromBody] PushRegistrationDto push)
        {
            bool result = appServices.RegisterPush(push);

            return(Ok(result));
        }