Example #1
0
        private void PopulateComboBoxes()
        {
            _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);
            var regions = _regionRepo.All().OrderBy(x => x.Name).ToList();
            var states = _stateRepo.All().OrderBy(x => x.Name).ToList();
            var brands = _brandRepo.All().OrderBy(x => x.Name).ToList();
            _unitOfWork.Dispose();

            // Create default dummy selections.
            APLBackendDB.Region region = new APLBackendDB.Region();
            region.Id = Guid.Empty;
            region.Name = "ALL";
            regions.Insert(0, region);

            cbxRegion.DataSource = regions;
            cbxRegion.DisplayMember = "name";
            cbxRegion.ValueMember = "id";

            APLBackendDB.State state = new APLBackendDB.State();
            state.Id = Guid.Empty;
            state.Name = "ALL";
            states.Insert(0, state);

            cbxState.DataSource = states;
            cbxState.DisplayMember = "name";
            cbxState.ValueMember = "id";

            APLBackendDB.Brand brand = new APLBackendDB.Brand();
            brand.Id = Guid.Empty;
            brand.Name = "ALL";
            brands.Insert(0, brand);

            cbxBrand.DataSource = brands;
            cbxBrand.DisplayMember = "name";
            cbxBrand.ValueMember = "id";
        }
Example #2
0
        private void PopulateRegionCBX(string defaultRegion)
        {
            _unitOfWork = new UnitOfWork(_sessionHelper.GetSessionFactory("APL"));
            Repository<Guid, APLBackendDB.Region> _regionRepo = new Repository<Guid, APLBackendDB.Region>(_unitOfWork.Session);
            var x = _regionRepo.All().OrderBy(v => v.Name).ToList();
            _unitOfWork.Dispose();

            // Create default dummy selection.
            APLBackendDB.Region region = new APLBackendDB.Region();
            region.Id = Guid.Empty;
            region.Name = "Select...";
            x.Insert(0, region);

            cbxRegion.DataSource = x;
            cbxRegion.DisplayMember = "name";
            cbxRegion.ValueMember = "id";
            cbxRegion.SelectedIndex = 0;
        }
Example #3
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
            {

            }
        }
Example #4
0
        private void PopulateComboBox(string defaultVenue)
        {
            _unitOfWork = new UnitOfWork(_sessionHelper.GetSessionFactory("APL"));
            _venueRepo = new Repository<Guid, Venue>(_unitOfWork.Session);
            var x = _venueRepo.All().OrderBy(v=>v.Name).ToList();
            _unitOfWork.Dispose();

            // Create default dummy selection.
            Venue venue = new Venue();
            venue.Id = Guid.Empty;
            venue.Name = "";
            x.Insert(0, venue);

            cbxVenueSelect.DataSource = x;
            cbxVenueSelect.DisplayMember = "name";
            cbxVenueSelect.ValueMember = "id";
            cbxVenueSelect.SelectedIndex = 0;
        }