private void UpdateReviewMessageDetails(NotificationMessage message)
 {
     if (message.ReviewMessage.ReviewMessageId == 0)
     {
         _notificationMessageService.InsertReviewMessage(message.ReviewMessage);
         _unitOfWorkAsync.SaveChanges();
         message.ProductReviewId = message.ReviewMessage.ReviewMessageId;
     }
     else
     {
         var oldReview = _notificationMessageService.FindReviewMessage(message.ProductReviewId.GetValueOrDefault(0));
         var review    = message.ReviewMessage;
         oldReview.MessageHeader           = review.MessageHeader;
         oldReview.MessageDescription      = review.MessageDescription;
         oldReview.MessageShortDescription = review.MessageShortDescription;
         oldReview.MessageImage            = review.MessageImage;
         oldReview.ScreenName = review.ScreenName;
         oldReview.State      = review.State;
         oldReview.City       = review.City;
         _notificationMessageService.UpdateReviewMessage(oldReview);
     }
 }
        public IHttpActionResult ByBeaconId(string beaconId, int rssi)
        {
            Enums.ProximityRange proximity = 0;
            rssi = Math.Abs(rssi);
            var beacon = _beaconService.GetByBeaconNum(beaconId);

            if (beacon.CompanyID == null)
            {
                //if beacon not assigned to company no messages can be scheduled
                return(Ok(new List <NotificationMessage>()));
            }

            var settings = _settingsService.ByCompany((long)beacon.CompanyID);

            if (rssi > settings.FarMinRSSI && rssi < settings.FarMaxRSSI)
            {
                proximity = Enums.ProximityRange.Far;
            }
            if (rssi > settings.NearMinRSSI && rssi < settings.NearMaxRSSI)
            {
                proximity = Enums.ProximityRange.Near;
            }
            if (rssi > settings.CloseMinRSSI && rssi < settings.CloseMaxRSSI)
            {
                proximity = Enums.ProximityRange.Close;
            }

            logging.Info("ByBeaconId: tring to get notifications for beacon ID - " + beaconId);

            var messages = _notificationMessageService.GetByBeaconNum(beaconId).ToList();

            logging.Info(String.Format("ByBeaconId: {0} notifications found", messages.Count()));

            var filteredMessages = messages.ToList();

            filteredMessages.RemoveAll(m => m.Disabled || (m.ProximityRange != 0 && m.ProximityRange != (int)proximity));

            foreach (var message in filteredMessages)
            {
                if (message.OfferId != null)
                {
                    message.OfferMessage = _notificationMessageService.FindOfferMessage((long)message.OfferId);
                }
                if (message.ProductRatingId != null)
                {
                    message.RatingMessage = _notificationMessageService.FindRatingMessage((long)message.ProductRatingId);
                }
                if (message.ProductReviewId != null)
                {
                    message.ReviewMessage = _notificationMessageService.FindReviewMessage((long)message.ProductReviewId);
                }
                if (message.VideoId != null)
                {
                    message.VideoMessage = new VideoMessage
                    {
                        VideoMessageId          = 1,
                        MessageHeader           = "Video message title",
                        MessageDescription      = "This is video message",
                        MessageShortDescription = "This is video message",
                        MessageImage            = "http://livekart.altumsoft.com/Content/notificationimages/220420141023166565.jpg",
                        VideoUrl = "https://www.youtube.com/watch?v=aiVByOBGBjA"
                    };
                }
                if (message.GameId != null)
                {
                    message.GameMessage = new GameMessage
                    {
                        GameMessageId           = 1,
                        MessageHeader           = "Game message title",
                        MessageDescription      = "This is game message",
                        MessageShortDescription = "This is game message",
                        MessageImage            = "http://livekart.altumsoft.com/Content/notificationimages/220420141023166565.jpg",
                        GameUrl = "http://google.com"
                    };
                }
            }
            return(Ok(filteredMessages));
        }