Exemplo n.º 1
0
        private void btnSend_Click(object sender, EventArgs e)
        {
            GoogleInteraction.GCMMessage gcmMessage = new GCMMessage();
            UnitOfWork unitOfWork = new UnitOfWork(_sessionHelper.GetSessionFactory("APL"));

            Repository<Guid, UserMobileDevice> userMobileDeviceRepo = new Repository<Guid, UserMobileDevice>(unitOfWork.Session);

            var devices = userMobileDeviceRepo.All();

            gcmMessage.Data.Add("message", tbxMessage.Text);
            gcmMessage.Data.Add("type", "broadcast");
            foreach (UserMobileDevice userMobileDevice in devices)
            {
                gcmMessage.RecipientDevices.Add(userMobileDevice.Token);
            }
            gcmMessage.CollapseKey = "broadcast";
            gcmMessage.Send();

            unitOfWork.Commit();
        }
Exemplo n.º 2
0
        private void btSave_Click(object sender, EventArgs e)
        {
            if ( ! string.IsNullOrEmpty(tbxSubject.Text)  && ! string.IsNullOrEmpty(tbxBody.Text) )
            {
                if ( dtpExpiryDate.Value < dtpPublishDate.Value )
                {
                    ShowError("Error", "Expiry date cannot be before the publish date.");
                    return;
                }
                _unitOfWork = new UnitOfWork(_sessionHelper.GetSessionFactory("APL"));
                Repository<Guid, State> _stateRepo = new Repository<Guid, State>(_unitOfWork.Session);
                Repository<Guid, APLBackendDB.Region> _regionRepo = new Repository<Guid, APLBackendDB.Region>(_unitOfWork.Session);
                Repository<Guid, Brand> _brandRepo = new Repository<Guid, Brand>(_unitOfWork.Session);
                Repository<Guid, NewsItem> _newsItemRepo = new Repository<Guid, NewsItem>(_unitOfWork.Session);
                Repository<Guid, APLBackendDB.Image> _imageRepo = new Repository<Guid, APLBackendDB.Image>(_unitOfWork.Session);

                _newsItem = _newsItemRepo.FindBy(_newsItemId);
                if ( _newsItem == null )
                {
                    _newsItem = new NewsItem();
                }

                _newsItem.Subject = tbxSubject.Text;
                _newsItem.Active = cbxActive.Checked;
                _newsItem.Author = tbxAuthor.Text;
                _newsItem.Body = tbxBody.Text;

                APLBackendDB.Brand _brand = _brandRepo.FindBy(Guid.Parse(cbxBrand.SelectedValue.ToString()));
                if ( _brand != null )
                {
                    _newsItem.Brand = _brand;
                }
                State _state = _stateRepo.FindBy(Guid.Parse(cbxState.SelectedValue.ToString()));
                if ( _state != null )
                {
                    _newsItem.State = _state;
                }
                APLBackendDB.Region _region = _regionRepo.FindBy(Guid.Parse(cbxRegion.SelectedValue.ToString()));
                if ( _region != null )
                {
                    _newsItem.Region = _region;
                }
                _newsItem.ExpiryDate = dtpExpiryDate.Value;
                _newsItem.PublishDate = dtpPublishDate.Value;
                _newsItem.Push = cbxPush.Checked;

                //_imageRepo.AddOrUpdate(_images);
                _newsItem.Images = _images;

                if (_newsItem.Id == Guid.Empty)
                {
                    _newsItemRepo.Add(_newsItem);
                }
                else
                {
                    _newsItemRepo.Update(_newsItem);
                }

                _unitOfWork.Commit();
                _unitOfWork.Dispose();

                if ( cbxPush.Checked )
                {
                    GoogleInteraction.GCMMessage gcmMessage = new GCMMessage();
                    UnitOfWork unitOfWork = new UnitOfWork(_sessionHelper.GetSessionFactory("APL"));

                    Repository<Guid, UserMobileDevice> userMobileDeviceRepo = new Repository<Guid, UserMobileDevice>(unitOfWork.Session);

                    var devices = userMobileDeviceRepo.FilterBy(x => x.EnablePushNotifications == true);

                    gcmMessage.Data.Add("message", tbxSubject.Text);
                    gcmMessage.Data.Add("type", "news="+_newsItem.Id.ToString());
                    foreach (UserMobileDevice userMobileDevice in devices)
                    {
                        gcmMessage.RecipientDevices.Add(userMobileDevice.Token);
                    }
                    gcmMessage.CollapseKey = "broadcast";
                    gcmMessage.Send();

                }
            } else
            {

            }
        }