public async Task <Guid> CreateAsync(CreateDeviceDto device)
        {
            var newDevice = new Device(device.Name, device.PhoneId);
            await _deviceRepository.Create(newDevice);

            return(newDevice.Id);
        }
示例#2
0
        public async Task <Models.DTO.Device> Create(
            string userId,
            string tenantId,
            RegisterDevice device,
            CancellationToken cancellationToken)
        {
            if (!ObjectId.TryParse(device.TypeId, out var deviceId))
            {
                throw new ArgumentException("Invalid TypeId");
            }

            var type = await _typeRepository.Get(
                deviceId,
                tenantId,
                cancellationToken)
                       ??
                       throw new ArgumentException("Type not found.");

            var newDevice = DeviceMapper.MapToDomain(
                device,
                type,
                userId,
                tenantId);

            await _deviceRepository.Create(
                newDevice,
                cancellationToken);

            return(DeviceMapper.MapToDto(newDevice));
        }
示例#3
0
        public Device Create(Device device)
        {
            var dalDevice = AutoMapper.Mapper.Map <DalDevice>(device);
            var newDevice = _deviceRepository.Create(dalDevice);

            _unit.Commit();
            return(AutoMapper.Mapper.Map <Device>(newDevice));
        }
        public DeviceVO Create(DeviceVO deviceVO)
        {
            Device device = convert.Convert(deviceVO);

            device   = _repository.Create(device);
            deviceVO = convert.Convert(device);
            return(deviceVO);
        }
示例#5
0
        public ResponseMessage <Device> Create(Device entity)
        {
            ResponseMessage <Device> response = new ResponseMessage <Device>();

            try
            {
                response.ResponseObject = _deviceRepository.Create(entity);
                response.IsSuccess      = true;
                response.ErrorMessage   = "Success";
            }
            catch (Exception ex)
            {
                response.IsSuccess    = false;
                response.ErrorMessage = ex.Message;
            }

            return(response);
        }
        public async Task <IOperationResult <string> > StoreDeviceInfoForUser(Device device)
        {
            int userId = device.UserId;

            if (!await _userRepository.Exists(u => u.Id == userId))
            {
                return(BasicOperationResult <string> .Fail("El usuario que intenta asociar a este dispositivo no existe"));
            }

            var validator = new DevicesValidator();

            var validationResult = validator.Validate(device);

            if (!validationResult.IsValid)
            {
                return(BasicOperationResult <string> .Fail(validationResult.JSONFormatErrors()));
            }

            if (await _deviceRepository.Exists(d => d.FcmToken == device.FcmToken &&
                                               d.Platform == device.Platform &&
                                               d.UserId == userId))
            {
                return(BasicOperationResult <string> .Ok("El Dispositivo ya ha sido guardado para este usuario"));
            }

            var updateDevice =
                await _deviceRepository.Find(d => d.FcmToken == device.FcmToken && d.Platform == device.Platform);

            if (updateDevice != null)
            {
                updateDevice.UserId = device.UserId;
                _deviceRepository.Update(updateDevice);
                await _deviceRepository.Save();

                return(BasicOperationResult <string> .Ok("El token del usuario ha sido actualizado"));
            }

            _deviceRepository.Create(device);

            await _deviceRepository.Save();

            return(BasicOperationResult <string> .Ok("Dispositivo guardado exitosamente"));
        }
示例#7
0
        public HttpResponseMessage PostCreate(string organizationId, string joinKey)
        {
            var org = _organizationRepository.Get(organizationId);

            if (null == org || org.JoinKey != joinKey)
            {
                return(new HttpResponseMessage(HttpStatusCode.Forbidden));
            }

            var device = _deviceRepository.Create(new DeviceEntity()
            {
                OrganizationId = org.Id
            });

            var token = _tokenService.CreateDeviceToken(device.Id);

            return(new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(token, Encoding.UTF8)
            });
        }
示例#8
0
        public async Task <ResponseInsertDevice> Handle(ParamInsertDevice request, CancellationToken cancellationToken)
        {
            try
            {
                if (!await Validations(request))
                {
                    return(new ResponseInsertDevice(
                               HttpStatusCode.BadRequest,
                               _notifications));
                }

                _deviceRepository.Create(
                    new Domain.Models.Device(request.Device.Enabled, request.Device.RegionId));
                await _unitOfWork.Commit();

                return(new ResponseInsertDevice(HttpStatusCode.Created));
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                throw new Exception(ex.Message);
            }
        }
示例#9
0
 public Device Create(Device device, string siteId)
 {
     return(deviceRepository.Create(device, siteId));
 }