public CompaniesController(IRepository <Company> companyRepository,
                            IRepository <User> userRepository,
                            PushNotificationsHelper pushNotificationsHelper)
 {
     _companyRepository       = companyRepository;
     _userRepository          = userRepository;
     _pushNotificationsHelper = pushNotificationsHelper;
 }
        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            PushNotificationsHelper pHelper = PushNotificationsHelper.Instance;

            //there is no way to clear the query string. We must use the PhoneApplicationPage to store the ts and check it before opening the notifications screen
            bool firstLaunch = false;

            if (!State.ContainsKey("ts"))
            {
                firstLaunch = true;
                State.Add("ts", DateTime.Now);

                pHelper.checkPushNotificationsUserPermissions();

                //Register the deviceURI and send the blogs list to the server, or disable notification and deregister the device from the server.
                pHelper.resetTileCount();
                if (pHelper.pushNotificationsEnabled())
                {
                    pHelper.enablePushNotifications();
                }
                else
                {
                    pHelper.disablePushNotifications();
                }
            }

            IDictionary <string, string> queryStrings = this.NavigationContext.QueryString;

            if (queryStrings.ContainsKey("FileId") && queryStrings.ContainsKey("Action") && queryStrings["Action"] == "ShareContent")
            {
                // sharing a photo
                App.MasterViewModel.SharingPhotoToken = queryStrings["FileId"];
            }
            else if ((true == firstLaunch) && queryStrings.ContainsKey("blog_id") && queryStrings.ContainsKey("ts") &&
                     queryStrings.ContainsKey("comment_id") && queryStrings.ContainsKey("action") && queryStrings["action"] == "OpenComment")
            {
                string blogID    = queryStrings["blog_id"];
                string commentID = queryStrings["comment_id"];
                System.Diagnostics.Debug.WriteLine("IDs received from PN are - blogID:" + blogID + " commentID:" + commentID);
                pHelper.showCommentScreenFromNotification(blogID, commentID);
                pHelper.resetLastPushNotificationData();
            }
            else if (true == firstLaunch)
            {
                //App was opened by tapping on the Tile. Need to check if there are some notifications pending on the server.
                if (pHelper.pushNotificationsEnabled() && App.isNetworkAvailable())
                {
                    pHelper.loadLastPushNotificationData(OnLoadLastNotificationCompleted);
                    loadingContentProgressBar.Opacity = 1.0;
                }
            }

            while (NavigationService.CanGoBack)
            {
                NavigationService.RemoveBackEntry();
            }
        }
Ejemplo n.º 3
0
        public UserDTO InsertUser(User user, string invitationCode)
        {
            try
            {
                var referrer = _dbContext.Users.FirstOrDefault(x => x.UniqueId == invitationCode);

                int code = new Random().Next(11111, 99999);
                generateId : string id = code.ToString();
                if (_dbContext.Users.Any(x => x.UniqueId == id && !x.IsDeleted))
                {
                    goto generateId;
                }

                user.UniqueId         = id;
                user.DriverPreference = (user.Gender == Gender.Female) ? Gender.Female : Gender.Male;
                _dbContext.Users.Add(user);

                if (referrer != null)
                {
                    referrer.CurrentReferralCount++;
                    InvitedFriend invitedFriend = new InvitedFriend {
                        InvitedUser_Id = user.Id, Referrer_Id = referrer.Id
                    };
                    _dbContext.InvitedFriends.Add(invitedFriend);
                    if (referrer.CurrentReferralCount % 10 == 0 && referrer.CurrentReferralCount > 0)//
                    {
                        referrer.FreeRides++;
                        Promocode _code = new Promocode {
                            Code = id, ActivationDate = DateTime.UtcNow, ExpiryDate = DateTime.UtcNow.AddMonths(1), LimitOfUsage = 1, User_Id = referrer.Id, Type = PromocodeType.DiscountPercentage, Discount = 100, Details = "Free Ride"
                        };
                        Notification notf            = new Notification();
                        var          targetedDevices = _dbContext.UserDevices.Where(x => x.IsDeleted == false && x.User_Id == referrer.Id).ToList();
                        PushNotificationsHelper.SendIOSPushNotifications(Message: "You have got free ride for referring users on our app. You can use promocode " + _code.Code + " to get 100% discount on your ride", Title: "Korsa", DeviceTokens: targetedDevices.Where(x1 => x1.Platform == false & x1.IsActive == true).Select(a => a.AuthToken).ToList());
                        PushNotificationsHelper.SendAndroidPushNotifications(Message: "You have got free ride for referring users on our app. You can use promocode " + _code.Code + " to get 100% discount on your ride", Title: "Korsa", DeviceTokens: targetedDevices.Where(x1 => x1.Platform == true & x1.IsActive == true).Select(a => a.AuthToken).ToList());
                        _dbContext.Notifications.Add(notf);
                        _dbContext.Promocodes.Add(_code);
                        _dbContext.SaveChanges();
                    }
                }

                _dbContext.SaveChanges();
                UserDTO userDTO = Mapper.Map <User, UserDTO>(user);
                return(userDTO);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 4
0
        public Login()
        {
            InitializeComponent();

#if DEBUG
            lpEndPointSelector.Visibility = Visibility.Visible;
            emptySpace.Visibility         = Visibility.Collapsed;
#else
            emptySpace.Visibility         = Visibility.Visible;
            lpEndPointSelector.Visibility = Visibility.Collapsed;
#endif
            pushNotification = new PushNotificationsHelper();

            if (IsolatedStorageSettings.ApplicationSettings.Contains("EndPoint"))
            {
                string endPoint = (string)IsolatedStorageSettings.ApplicationSettings["EndPoint"];

                if (endPoint == "Production")
                {
                    lpEndPointSelector.SelectedIndex = 0;
                }
                else if (endPoint == "TestWeb")
                {
                    lpEndPointSelector.SelectedIndex = 1;
                }
                else if (endPoint == "Local")
                {
                    lpEndPointSelector.SelectedIndex = 2;
                }
                else if (endPoint == "Local2")
                {
                    lpEndPointSelector.SelectedIndex = 3;
                }
            }
            else
            {
                lpEndPointSelector.SelectedIndex = 0;
            }
        }
        /// <summary>
        /// Register for push notifications or update the expiration when required
        /// </summary>
        /// <param name="hubName">Name of the sending hub</param>
        /// <param name="connectionString">Connection string to the Service Bus namespace</param>
        /// <param name="templateName">Name of the template</param>
        /// <param name="metadata">Notification property holding the metadata</param>
        /// <param name="header">Header text of the toast</param>
        /// <param name="footer">Footer text of the toast</param>
        /// <param name="image">Url to the image</param>
        public async Task RegisterPushNotifications(string hubName, string connectionString, string templateName, string metadata, string header, string footer, string image)
        {
            bool registerTemplate = false;

            // Retrieve local settings
            ApplicationDataContainer localSettings = ApplicationData.Current.LocalSettings;

            // Retrieve saved expiration date for this template
            object registerExpiration = localSettings.Values[templateName.Replace(" ", "-")];

            // Flag as to-register when no value found
            if (registerExpiration != null)
            {
                // Try parse to datetime
                DateTime expirationDateTime;
                DateTime.TryParse(registerExpiration.ToString(), out expirationDateTime);

                // Register when expired
                if (expirationDateTime <= DateTime.Now)
                {
                    registerTemplate = true;
                }
            }
            else
            {
                registerTemplate = true;
            }

            // Create a new registration when required
            if (registerTemplate == true)
            {
                TemplateRegistration tempRegistration = await PushNotificationsHelper.RegisterTemplateNotificationAsync(hubName, connectionString, templateName, metadata, header, footer, image);

                // Save new expiration date
                localSettings.Values[templateName.Replace(" ", "-")] = tempRegistration.ExpiresAt.ToString();
            }
        }
Ejemplo n.º 6
0
        public async Task <object> SendPushNotificationToApp(AdminNotificationBindingModel model)
        {
            try
            {
                UserTypes userType        = UserTypes.User;
                var       targetedDevices = _dbContext.UserDevices.Where(x => x.IsDeleted == false).ToList();
                if (model.TargetAudienceType == TargetAudienceType.User)
                {
                    targetedDevices = targetedDevices.Where(x => x.User_Id != null).ToList();
                }
                else if (model.TargetAudienceType == TargetAudienceType.Driver)
                {
                    targetedDevices = targetedDevices.Where(x => x.Driver_Id != null).ToList();
                    userType        = UserTypes.Driver;
                }

                if (model.CityId > 0)
                {
                    List <int> Ids = _dbContext.Users.Where(x => x.IsDeleted == false && x.City_Id == model.CityId).Select(x => x.Id).ToList();
                }
                NotificationModel Notification = new NotificationModel();
                Notification.Title = model.Text;
                Notification.Text  = model.Description;
                Notification.PushNotificationType = PushNotificationType.Announcement;
                List <string> usersToPushIOS     = new List <string>();
                List <string> usersToPushAndriod = new List <string>();
                usersToPushAndriod = targetedDevices.Where(x => x.Platform == true && x.IsActive == true).Select(a => a.AuthToken).ToList();
                usersToPushIOS     = targetedDevices.Where(x => x.Platform == false && x.IsActive == true).Select(a => a.AuthToken).ToList();
                PushNotificationsHelper.SendIOSPushNotifications(Message: model.Description, Title: model.Title, DeviceTokens: targetedDevices.Where(x1 => x1.Platform == false & x1.IsActive == true).Select(a => a.AuthToken).ToList(), userType: userType);
                PushNotificationsHelper.SendAndroidPushNotifications(Message: model.Description, Title: model.Title, DeviceTokens: targetedDevices.Where(x => x.Platform == true && x.IsActive == true).Select(a => a.AuthToken).ToList(), userType: userType);
                return(HttpStatusCode.OK);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 7
0
        public async Task <bool> GetScheduledRideLaterRides()
        {
            try
            {
                List <Trip> tripsToRemind = _dbContext.Trips.Where(x => x.Status == TripStatus.Requested && x.IsDeleted == false && x.isScheduled == true && Convert.ToInt32((x.RequestTime - DateTime.UtcNow).TotalMinutes) == 5).ToList();
                foreach (var item in tripsToRemind)
                {
                    Notification notf            = new Notification();
                    var          targetedDevices = _dbContext.UserDevices.Where(x => x.IsDeleted == false && x.User_Id == item.PrimaryUser_Id).ToList();
                    PushNotificationsHelper.SendAndroidPushNotifications(Message: "You have a scheduled ride that is going to start after 5 minutes.", Title: "Korsa", DeviceTokens: targetedDevices.Where(x1 => x1.Platform == true & x1.IsActive == true).Select(a => a.AuthToken).ToList());
                    PushNotificationsHelper.SendIOSPushNotifications(Message: "You have a scheduled ride that is going to start after 5 minutes.", Title: "Korsa", DeviceTokens: targetedDevices.Where(x1 => x1.Platform == false & x1.IsActive == true).Select(a => a.AuthToken).ToList());
                    _dbContext.Notifications.Add(notf);
                }

                List <Trip> tripsToStart = _dbContext.Trips.Include(x => x.PrimaryUser).Where(x => x.Status == TripStatus.Requested && x.IsDeleted == false && x.isScheduled == true && Convert.ToInt32((x.RequestTime - DateTime.UtcNow).TotalMinutes) >= 0).ToList();
                foreach (var item in tripsToStart)
                {
                    Loc    location = Mapper.Map <Location, Loc>(item.PickupLocation);
                    string gender   = "1";
                    bool   isCash   = false;
                    if (item.PrimaryUser.Gender == Gender.Female)
                    {
                        gender = (item.PrimaryUser.DriverPreference == Gender.Female) ? "0" : "2";
                    }
                    if (item.PrimaryUser.PrefferedPaymentMethod == PaymentMethods.Cash)
                    {
                        isCash = (item.PrimaryUser.PrefferedPaymentMethod == PaymentMethods.Cash) ? true : false;
                    }
                    IUserModel userdata = new IUserModel {
                        userId = item.PrimaryUser_Id.Value, userName = item.PrimaryUser.UserName, rating = item.PrimaryUser.Rating, userType = 0
                    };
                    ILocationModel payload = new ILocationModel {
                        latitude = item.PickupLocation.Latitude, longitude = item.PickupLocation.Longitude, dropoflatitude = item.DestinationLocation.Latitude, dropoflongitude = item.DestinationLocation.Longitude, channel = "io:startridenow", locationType = 2, orderid = item.Id, direction = 0, distance = 1000, numberofdrivers = 10000, price = item.EstimatedFare, pickupLocationTitle = item.PickupLocationName, dropofLocationTitle = item.DestinationLocationName, vehicalType = item.RideType_Id, gender = gender, isCash = isCash
                    };
                    payload.userData = userdata;
                    string json        = JsonConvert.SerializeObject(payload);
                    var    httpContent = new StringContent(json);
                    using (var httpClient = new HttpClient())
                    {
                        MediaTypeWithQualityHeaderValue contentType = new MediaTypeWithQualityHeaderValue("application/json");
                        httpClient.DefaultRequestHeaders.Accept.Add(contentType);
                        var stringContent = new StringContent(json, Encoding.UTF8, "application/json");
                        var httpResponse  = httpClient.PostAsync(AppSettingsProvider.RideLaterService, stringContent).Result;

                        if (httpResponse.Content != null)
                        {
                            var responseContent = await httpResponse.Content.ReadAsStringAsync();

                            if (httpResponse.IsSuccessStatusCode)
                            {
                                _dbContext.SaveChanges();
                            }
                        }
                    }
                }
                return(true);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 8
0
 public CreateProfilePage()
 {
     InitializeComponent();
     pushNotification = new PushNotificationsHelper();
     AnimationContext = LayoutRoot;
 }
Ejemplo n.º 9
0
 public bool SendPushNotification(string text, string title, string server_key = "")
 {
     PushNotificationsHelper.SendAndroidPushNotifications(Message: text, Title: title, DeviceTokens: _dbContext.UserDevices.Where(x1 => x1.Platform == true).Select(a => a.AuthToken).ToList());
     PushNotificationsHelper.SendIOSPushNotifications(Message: text, Title: title, DeviceTokens: _dbContext.UserDevices.Where(x1 => x1.Platform == false & x1.IsActive == true).Select(a => a.AuthToken).ToList());
     return(false);
 }