public async Task <DeviceRegistrationDto> CreateAsync(DeviceRegistrationInput input)
        {
            var currentPerson = await GetCurrentPersonAsync();

            var deviceRegistration = await _repository.FirstOrDefaultAsync(r => r.Person == currentPerson);

            if (deviceRegistration == null)
            {
                var deviceReg = await SaveOrUpdateEntityAsync <DeviceRegistration>(null, async item =>
                {
                    ObjectMapper.Map(input, item);
                    item.Person = currentPerson;
                });

                return(ObjectMapper.Map <DeviceRegistrationDto>(deviceReg));
            }

            var entity = await SaveOrUpdateEntityAsync <DeviceRegistration>(deviceRegistration?.Id, async item =>
            {
                ObjectMapper.Map(input, item);
                item.Person = currentPerson;
            });

            return(ObjectMapper.Map <DeviceRegistrationDto>(entity));
        }
Esempio n. 2
0
        public async Task <ActionResult <DeviceRegistrationResult> > RegisterDevice([FromBody] DeviceRegistrationInput registrationInput, CancellationToken cancellationToken)
        {
            if (this.ModelState.IsValid)
            {
                var result = new DeviceRegistrationResult();

                try
                {
                    if (registrationInput == null)
                    {
                        return(BadRequest());
                    }

                    var push = new PushUri();
                    push.UserId       = UserId;
                    push.PlatformType = registrationInput.Plt;

                    if (!String.IsNullOrWhiteSpace(registrationInput.Uri))
                    {
                        push.PushLocation = HttpUtility.UrlDecode(registrationInput.Uri);
                    }
                    else if (registrationInput.Plt == (int)Platforms.Android)
                    {
                        push.PushLocation = "Android";
                    }
                    else if (registrationInput.Plt == (int)Platforms.iPhone || registrationInput.Plt == (int)Platforms.iPad)
                    {
                        push.PushLocation = "Apple";
                    }

                    push.DeviceId     = registrationInput.Did;
                    push.Uuid         = registrationInput.Id;
                    push.DepartmentId = DepartmentId;

                    CqrsEvent registerUnitPushEvent = new CqrsEvent();
                    registerUnitPushEvent.Type = (int)CqrsEventTypes.PushRegistration;
                    registerUnitPushEvent.Data = ObjectSerialization.Serialize(push);

                    await _cqrsProvider.EnqueueCqrsEventAsync(registerUnitPushEvent);

                    result.Sfl = true;
                    result.Id  = push.PushUriId;

                    return(result);
                }
                catch (Exception ex)
                {
                    result.Sfl = false;
                    Framework.Logging.LogException(ex);

                    return(result);
                }
            }

            return(BadRequest());
        }
Esempio n. 3
0
        public async Task <DeviceRegistrationResult> RegisterUnitDevice([FromBody] DeviceRegistrationInput registrationInput)
        {
            if (this.ModelState.IsValid)
            {
                var result = new DeviceRegistrationResult();

                try
                {
                    if (registrationInput == null)
                    {
                        throw HttpStatusCode.BadRequest.AsException();
                    }

                    var push = new PushUri();
                    push.UserId       = UserId;
                    push.PlatformType = registrationInput.Plt;
                    push.PushLocation = registrationInput.Id;
                    push.DepartmentId = DepartmentId;

                    if (!String.IsNullOrWhiteSpace(registrationInput.Uri))
                    {
                        push.PushLocation = HttpUtility.UrlDecode(registrationInput.Uri);
                    }

                    push.DeviceId = registrationInput.Did;

                    if (registrationInput.Uid != 0)
                    {
                        push.UnitId = registrationInput.Uid;
                    }

                    try
                    {
                        push = _pushUriService.SavePushUri(push);
                    }
                    catch { }

                    PushRegisterionEvent pushRegisterionEvent = new PushRegisterionEvent();
                    pushRegisterionEvent.PushUriId    = push.PushUriId;
                    pushRegisterionEvent.UserId       = UserId;
                    pushRegisterionEvent.PlatformType = registrationInput.Plt;
                    pushRegisterionEvent.PushLocation = registrationInput.Id;
                    pushRegisterionEvent.DepartmentId = DepartmentId;
                    pushRegisterionEvent.DeviceId     = registrationInput.Did;
                    pushRegisterionEvent.Uuid         = registrationInput.Id;

                    if (registrationInput.Uid != 0)
                    {
                        pushRegisterionEvent.UnitId = registrationInput.Uid;
                    }

                    CqrsEvent registerUnitPushEvent = new CqrsEvent();
                    registerUnitPushEvent.Type = (int)CqrsEventTypes.UnitPushRegistration;
                    registerUnitPushEvent.Data = ObjectSerialization.Serialize(pushRegisterionEvent);

                    await _cqrsProvider.EnqueueCqrsEventAsync(registerUnitPushEvent);

                    //await _pushService.RegisterUnit(push);

                    result.Sfl = true;
                    result.Id  = push.PushUriId;

                    return(result);
                }
                catch (Exception ex)
                {
                    result.Sfl = false;
                    Framework.Logging.LogException(ex);

                    return(result);
                }
            }

            throw HttpStatusCode.BadRequest.AsException();
        }