public bool EditDeviceRegistration(DeviceRegistrationModel device)
        {
            try
            {
                using (var dataContext = new BrownBagDataEntities())
                {
                    var selectedDevice = dataContext.DeviceRegistrations.Where(a => a.IMEI_Number == device.IMEINumber).FirstOrDefault();
                    if (selectedDevice != null)
                    {
                        selectedDevice.AccessToken = device.AccessToken.Trim();

                        selectedDevice.UpdatedOnUtc = DateTime.Now.ToUniversalTime();
                        return(dataContext.SaveChanges() > 0 ? true : false);
                    }
                    else
                    {
                        return(false);
                    }
                }
            }
            catch
            {
                throw;
            }
        }
        public bool AddDeviceRegistration(DeviceRegistrationModel device)
        {
            try
            {
                using (var dataContext = new BrownBagDataEntities())
                {
                    var deviceRegistration = new DeviceRegistration
                    {
                        AccessToken = device.AccessToken.Trim(),

                        CreatedOnUtc    = DateTime.Now.ToUniversalTime(),
                        IMEI_Number     = device.IMEINumber.Trim(),
                        IsActive        = true,
                        RefCustomerGuid = string.IsNullOrEmpty(device.CustomerGuid) ? (Guid?)null : Guid.Parse(device.CustomerGuid),
                        UpdatedOnUtc    = DateTime.Now.ToUniversalTime()
                    };
                    dataContext.DeviceRegistrations.Add(deviceRegistration);
                    return(dataContext.SaveChanges() > 0 ? true : false);
                }
            }
            catch
            {
                throw;
            }
        }
        public async Task <IHttpActionResult> PutRegisterDeviceAsync(string id, DeviceRegistrationModel model)
        {
            try
            {
                if (string.IsNullOrEmpty(id))
                {
                    return(BadRequest());
                }
                if (model == null)
                {
                    return(BadRequest());
                }

                var registrationResponse = await PushNotificationFacade.Instance.Service.RegisterDeviceAsync(id, new DeviceRegistration
                {
                    DeviceToken = model.Handle,
                    Platform    = (Platform)Enum.Parse(typeof(Platform), model.Platform)
                }, "test" + DateTime.UtcNow.Ticks, model.DeviceIds);

                if (registrationResponse.IsSuccess == false)
                {
                    return(BadRequest(registrationResponse.Message));
                }
                return(Ok(registrationResponse));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
Ejemplo n.º 4
0
        public async Task <DeviceMobileModel> RegisterForNotifications(DeviceRegistrationModel deviceRegistrationModel)
        {
            var deviceMobileModel = await notificationRestService.Register(deviceRegistrationModel);

            DeviceId = deviceMobileModel?.DeviceId ?? DeviceId;

            return(deviceMobileModel);
        }
 public bool EditDeviceRegistration(DeviceRegistrationModel device)
 {
     try
     {
         using (var dataContract = new DeviceRegisterContract())
         {
             return(dataContract.EditDeviceRegistration(device));
         }
     }
     catch
     {
         throw;
     }
 }
Ejemplo n.º 6
0
        public async Task <DeviceMobileModel> Register(DeviceRegistrationModel registrationModel)
        {
            var request     = PrepareRequest("Notifications/Register", Method.POST, registrationModel);
            var queryResult = await client.ExecutePostTaskAsync <DeviceMobileModel>(request);

            if (queryResult.IsSuccessful)
            {
                return(queryResult.Data);
            }

            logger.Log($"Error registering device for notifications: {queryResult.ResponseStatus}, Error Message: {queryResult.ErrorMessage}");

            return(null);
        }
Ejemplo n.º 7
0
        public ActionResult Add(DeviceRegistrationModel model)
        {
            if (ModelState.IsValid)
            {
                Tracker newTracker = TrackerLogic.CreateTracker(model.IMEI, model.DeviceName, model.Description);
                User currentUser = UserLogic.GetUser(User.Identity.Name);
                LicenceLogic.CreateLicence(currentUser, newTracker, DateTime.Now.AddYears(100));

                return RedirectToAction("Index", "Devices");
                //ModelState.AddModelError("", "The user name or password provided is incorrect.");
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }
        public async Task <DeviceMobileModel> RegisterDevice(DeviceRegistrationModel deviceRegistration)
        {
            RestRequest request = await PrepareQuery("Notifications/Register", Method.POST);

            request.AddParameter("application/json", JsonConvert.SerializeObject(deviceRegistration), ParameterType.RequestBody);
            var queryResult = await _client.ExecuteTaskAsync <DeviceMobileModel>(request);

            if (queryResult.IsSuccessful)
            {
                return(queryResult.Data);
            }
            else
            {
                _logger.LogError($"RegisterDevice: Error: {queryResult.StatusCode}");
            }
            return(null);
        }
Ejemplo n.º 9
0
 public Task <DeviceMobileModel> RegisterForNotifications(DeviceRegistrationModel deviceRegistrationModel)
 {
     return(notificationRestService.Register(deviceRegistrationModel));
 }
        public async Task <IActionResult> RegisterDevice([FromBody] DeviceRegistrationModel deviceRegistration)
        {
            try
            {
                RegistrationDescription registerDescription = null;
                DeviceMobileModel       deviceModel         = null;

                switch (deviceRegistration.Platform)
                {
                case "apns":
                    registerDescription = deviceRegistration.Tags != null ?
                                          new AppleRegistrationDescription(deviceRegistration.Identifier, deviceRegistration.Tags) :
                                          new AppleRegistrationDescription(deviceRegistration.Identifier);
                    break;

                case "gcm":
                    registerDescription = deviceRegistration.Tags != null ?
                                          new GcmRegistrationDescription(deviceRegistration.Identifier, deviceRegistration.Tags) :
                                          new GcmRegistrationDescription(deviceRegistration.Identifier);
                    break;

                default:
                    throw new ArgumentException("RegisterDevice: Unsupported platform registration");
                }
                try
                {
                    string newRegistrationId = null;

                    if (deviceRegistration.Identifier != null)
                    {
                        var registrations = await _hubClient.GetRegistrationsByChannelAsync(deviceRegistration.Identifier, 100);

                        foreach (RegistrationDescription registration in registrations)
                        {
                            if (newRegistrationId == null)
                            {
                                newRegistrationId = registration.RegistrationId;
                            }
                            else
                            {
                                await _hubClient.DeleteRegistrationAsync(registration);
                            }
                        }
                    }

                    if (newRegistrationId == null)
                    {
                        newRegistrationId = await _hubClient.CreateRegistrationIdAsync();
                    }
                    registerDescription.RegistrationId = newRegistrationId;
                    RegistrationDescription output = await _hubClient.CreateOrUpdateRegistrationAsync <RegistrationDescription>(registerDescription);

                    if (output != null)
                    {
                        deviceModel = await _devicesDataManager.CreateOrUpdateDevice(
                            new DeviceMobileModel()
                        {
                            DeviceType     = "Mobile",
                            Name           = string.Concat("mobile_", deviceRegistration.Platform, "_", Guid.NewGuid()),
                            Email          = deviceRegistration.UserEmail,
                            MobileId       = deviceRegistration.Identifier,
                            Platform       = deviceRegistration.Platform,
                            RegistrationId = output.RegistrationId
                        });
                    }
                    else
                    {
                        throw new Exception(string.Format("Registration creation or update failed. MobileId: {0}", deviceRegistration.Identifier));
                    }
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                return(Ok(deviceModel));
            }
            catch (Exception e)
            {
                return(StatusCode(StatusCodes.Status502BadGateway, e.Message));
            }
        }