/// <summary> /// Get the details of a subscription for a device. /// </summary> /// <param name="deviceId">The device id of the device being searched.</param> /// <param name="subscription">The subscription for which we want details.</param> /// <returns>Returns the details of the device subscription.</returns> public SubscriptionDataModel SelectByDeviceIdAndSubscription(string deviceId, string subscription) { try { SubscriptionDataModel sdm = this.serviceContext.SubscriptionsTable.Where(s => (s.Subscription == subscription && s.DeviceId == deviceId)).FirstOrDefault(); return(sdm); } catch (DataServiceQueryException) { return(null); } }
/// <summary> /// Signup the device to the subscription. /// </summary> /// <param name="deviceId">The device id of the device being added.</param> /// <param name="subscription">Name of the subscription being signed up.</param> /// <returns>Returns success if the signup is successful. Error otherwise.</returns> public PushMessageError AddSubscription(string deviceId, string subscription) { PushMessageError err = this.Validate(deviceId, subscription); if (err != PushMessageError.Success) { return err; } SubscriptionDataModel sdm = this.sds.SelectByDeviceIdAndSubscription(deviceId, subscription); if (sdm == null) { sdm = new SubscriptionDataModel(subscription, deviceId); this.sds.Insert(sdm); } return PushMessageError.Success; }
/// <summary> /// Update Just for completeness. /// </summary> /// This is not implemented. /// <param name="updatedItem">The subscription record to be deleted.</param> public static void Update(SubscriptionDataModel updatedItem) { // we do not update subscriptions. You create or delete throw new NotImplementedException(); }
/// <summary> /// Used to unsubscribe from a subscription. /// </summary> /// <param name="item">The subscription record to be deleted.</param> public void Delete(SubscriptionDataModel item) { this.serviceContext.DeleteObject(item); this.serviceContext.SaveChanges(); }
/// <summary> /// Add a subscription to the table. Used when a device subscribes to a subscription /// </summary> /// <param name="newItem">The new subscription record being added.</param> public void Insert(SubscriptionDataModel newItem) { this.serviceContext.AddObject(MessageServiceContext.SubscriptionsTableName, newItem); this.serviceContext.SaveChanges(); }