Esempio n. 1
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            // Sanity cecking.

            _unitOfWork = new UnitOfWork(_sessionHelper.GetSessionFactory("APL"));
            Repository<Guid, APLBackendDB.Venue> _venueRepo = new Repository<Guid, APLBackendDB.Venue>(_unitOfWork.Session);
            Repository<Guid, APLBackendDB.Region> _regionRepo = new Repository<Guid, APLBackendDB.Region>(_unitOfWork.Session);
            _venue.Name = tbxVenueName.Text;
            _venue.Address1 = tbxAddr1.Text;
            _venue.Address2 = tbxAddr2.Text;
            _venue.Description = tbxDesc.Text;
            _venue.EmailAddress = tbxEmail.Text;
            _venue.Phone = tbxPhone.Text;
            int _pcode = 0;
            if (int.TryParse(tbxPcode.Text, out _pcode))
            {
                _venue.Postcode = (short)_pcode;
            }
            Guid _regionId = Guid.Empty;
            if (Guid.TryParse(cbxRegion.SelectedValue.ToString(), out _regionId))
            {
                _venue.Region = _regionRepo.FindBy(_regionId);
                _venue.State = _venue.Region.State;
            }
            _venue.Suburb = tbxSuburb.Text;
            _venue.Website = tbxURL.Text;
            if ( ! string.IsNullOrEmpty(tbxLat.Text) && ! String.IsNullOrEmpty(tbxLong.Text) )
            {
                _venue.Lattitude = float.Parse(tbxLat.Text);
                _venue.Longitude = float.Parse(tbxLong.Text);
            }
            _venueRepo.AddOrUpdate(_venue);
            _unitOfWork.Commit();
        }
Esempio n. 2
0
 private void PopulateForm()
 {
     DataLayer.SessionHelper _sessionHelper = new SessionHelper();
     Repository<Guid, NewsItem> _newsItemRepo = new Repository<Guid, NewsItem>(_sessionHelper.GetSession("APL"));
     UnitOfWork _unitOfWork = new UnitOfWork(_sessionHelper.GetSessionFactory("APL"));
     var newsItems = _newsItemRepo.All().ToList();
     dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
     dataGridView1.CellContentDoubleClick += DataGridView1_CellContentDoubleClick;
     dataGridView1.ReadOnly = true;
     dataGridView1.DataSource = newsItems;
 }
Esempio n. 3
0
        private System.Threading.Tasks.Task DoSync()
        {
            System.Threading.Tasks.Task t = new System.Threading.Tasks.Task(() =>
            {
                DataLayer.SessionHelper _sessionHelper = new SessionHelper();
                UnitOfWork _unitOfWork = new UnitOfWork(_sessionHelper.GetSessionFactory("APL"));
                Repository<Guid, Setting> _settingRepo = new Repository<Guid, APLBackendDB.Setting>(_unitOfWork.Session);
                Setting _settings = new Setting();

                SetStatusText("Starting sync...");

                Util.DBSync d = new Util.DBSync();
                d.ProgressUpdate += D_ProgressUpdate;

                SetStatusText("Syncing States...");
                d.SyncState();

                SetStatusText("Syncing Brands...");
                d.SyncBrand();

                SetStatusText("Syncing Regions...");
                d.SyncRegion();

                SetStatusText("Syncing Venues...");
                d.SyncVenue();

                SetStatusText("Syncing Game Types...");
                d.SyncGameType();

                SetStatusText("Syncing Games...");
                d.SyncGame();

                SetStatusText("Syncing Customers...");
                d.SyncCustomer();

                SetStatusText("Sync Completed.");
                btSync.Enabled = true;

                Setting lastSync = _settingRepo.FindBy(p => (p.Keyname == "LastCompleteSync"));
                if (lastSync == null || string.IsNullOrEmpty(lastSync.Value))
                {
                    lastSync = new Setting();
                    lastSync.Keyname = "LastCompleteSync";
                }
                lastSync.Value = DateTime.Now.ToString();

                _settingRepo.AddOrUpdate(lastSync);
                _unitOfWork.Commit();

            });
            t.Start();
            return t;
        }
Esempio n. 4
0
        public void SyncBrand()
        {
            ProgressUpdateArgs e = new ProgressUpdateArgs();
            // Sync required data from FHGLocal to DB

            _UnitOfWorkAPL = new UnitOfWork(_sessionHelper.GetSessionFactory("APL"));
            _UnitOfWorkFHG = new UnitOfWork(_sessionHelper.GetSessionFactory("FHG"));

            // State Table

            Repository<int, EvtBrand> _fhgBrandRepo = new Repository<int, EvtBrand>(_UnitOfWorkFHG.Session);
            Repository<Guid, Brand> _aplBrandRepo = new Repository<Guid, Brand>(_UnitOfWorkAPL.Session);

            var aplBrand = _aplBrandRepo.All().ToList();
            var fhgBrand = _fhgBrandRepo.All().ToList();

            int itemCount = 1;
            // Add Missing data
            foreach (EvtBrand evtBrand in fhgBrand)
            {
                e.TotalWorkItems = fhgBrand.Count();
                e.CurrentWorkItem = itemCount;
                e.StatusString = "Syncing Brands - (" + itemCount.ToString() + "/" + e.TotalWorkItems.ToString() + ")";
                this.ProgressUpdate(e);

                bool found = false;
                foreach (Brand brand in aplBrand)
                {
                    if (brand.FhgBrandId == evtBrand.Id)
                    {
                        found = true;
                        break;
                    }
                }
                if (!found)
                {
                    Brand newBrand = new Brand();
                    newBrand.FhgBrandId = evtBrand.Brandid;
                    newBrand.Name = evtBrand.Brandname;
                    _aplBrandRepo.Add(newBrand);
                }

                itemCount++;
            }

            _UnitOfWorkAPL.Commit();
            _UnitOfWorkFHG.Commit();
        }
Esempio n. 5
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();
        }
Esempio n. 6
0
        public string Authenticate(string Username, string Password)
        {
            JavaScriptSerializer js = new JavaScriptSerializer();
            JsonSerializerSettings j = new JsonSerializerSettings();
            j.TypeNameHandling = TypeNameHandling.Objects;
            j.Formatting = Newtonsoft.Json.Formatting.Indented;

            string result = "ERR - Unknown";

            string responseString = null;
            Response response = new Response();
            UnitOfWork unitOfWork = new UnitOfWork(_sessionHelper.GetSessionFactory("APL"));
            Repository<Guid, User> userRepo = new Repository<Guid, User>(unitOfWork.Session);
            Repository<Guid, UserToken> userTokenRepo = new Repository<Guid, UserToken>(unitOfWork.Session);
            user = userRepo.FilterBy(x => x.Username == Username).FirstOrDefault();

            if (user != null && user.Id != Guid.Empty)
            {
                if (Password == user.Password)
                {
                    AuthToken token = new AuthToken();

                    if (!string.IsNullOrEmpty(user.AuthToken))
                    {
                        if (CheckToken(user.AuthToken) == null)
                        {
                            user.AuthToken = null;
                        }
                    }

                    if (string.IsNullOrEmpty(user.AuthToken))
                    {
                        result = GenerateAuthToken();
                        APLBackendDB.UserToken userToken = new UserToken();
                        userToken.CreateDate = DateTime.Now;
                        userToken.ExpiryDate = DateTime.Now.AddHours(4);
                        userToken.LastUsedDate = DateTime.Now;
                        userToken.Token = result;
                        userToken.UserId = user.Id;
                        userTokenRepo.Add(userToken);

                        user.AuthToken = result;
                        userRepo.Update(user);

                        token.Token = result;
                    }
                    else
                    {
                        token.Token = user.AuthToken;
                    }

                    response.ResponseCode = "OK";
                    response.ResponseData = token;
                }
                else
                {
                    response.ResponseCode = "ERR";
                    response.ResponseData = "Authentication failed.";
                }
            }
            else
            {
                response.ResponseCode = "ERR";
                response.ResponseData = "User not found.";
            }

            js = new JavaScriptSerializer();
            responseString = JsonConvert.SerializeObject(response, j);
            unitOfWork.Commit();
            return responseString;
        }
Esempio n. 7
0
        public string RegisterDevice(string token, string deviceType, string deviceId)
        {
            UnitOfWork unitOfWork = new UnitOfWork(_sessionHelper.GetSessionFactory("APL"));

            Repository<Guid, User> userRepo = new Repository<Guid, User>(unitOfWork.Session);

            JavaScriptSerializer js = new JavaScriptSerializer();
            JsonSerializerSettings j = new JsonSerializerSettings();
            j.TypeNameHandling = TypeNameHandling.Objects;
            j.Formatting = Newtonsoft.Json.Formatting.Indented;

            string responseString = null;
            Response response = new Response();

            user = CheckToken(token);
            if (user.AuthToken == null || user.AuthToken != token)
            {
                user.AuthToken = token;
                userRepo.Update(user);
            }

            if (!string.IsNullOrEmpty(user.AuthToken))
            {
                if (CheckToken(user.AuthToken) == null)
                {
                    user.AuthToken = null;
                }
            }

            if (user != null)
            {
                if (DEVICE_TYPES.Contains(deviceType.ToLower()))
                {
                    UserMobileDevice userMobileDevice = new UserMobileDevice();
                    Repository<Guid, UserMobileDevice> userMobileDevRepo = new Repository<Guid, UserMobileDevice>(unitOfWork.Session);
                    userMobileDevice = userMobileDevRepo.FilterBy(x => x.Token == deviceId).FirstOrDefault();
                    if (userMobileDevice != null && userMobileDevice.Id != Guid.Empty)
                    {
                        if (userMobileDevice.MobileDeviceType.ToLower() == deviceType.ToLower() && userMobileDevice.User.Id == user.Id)
                        {
                            response.ResponseCode = "OK";
                            response.ResponseData = "Device registered.";
                        }
                        else
                        {
                            response.ResponseCode = "ERR";
                            response.ResponseData = "Invalid device registration";
                        }

                    }
                    else
                    {
                        userMobileDevice = new UserMobileDevice();
                        userMobileDevice.MobileDeviceType = deviceType.ToLower();
                        userMobileDevice.Token = deviceId;
                        userMobileDevice.User = user;
                        userMobileDevice.EnablePushNotifications = true;
                        user.MobileDevices.Add(userMobileDevice);
                        userMobileDevRepo.Add(userMobileDevice);
                        response.ResponseCode = "OK";
                        response.ResponseData = "Device registered.";
                    }
                }
                else
                {
                    response.ResponseCode = "ERR";
                    response.ResponseData = "Unknown DeviceType";
                }

            }
            else
            {
                response.ResponseCode = "ERR";
                response.ResponseData = "Authentication required.";
            }
            unitOfWork.Commit();

            js = new JavaScriptSerializer();
            responseString = JsonConvert.SerializeObject(response, j);
            return responseString;
        }
Esempio n. 8
0
        private User CheckToken(string token)
        {
            UnitOfWork unitOfWork = new UnitOfWork(_sessionHelper.GetSessionFactory("APL"));
            Repository<Guid, User> userRepo = new Repository<Guid, User>(unitOfWork.Session);
            User check_user = userRepo.FilterBy(x => x.AuthToken == token).FirstOrDefault();
            if (check_user != null)
            {
                UserToken currentUt = null;

                if (check_user.AuthTokens.Count > 0)
                {
                    IList<UserToken> utList = check_user.AuthTokens;
                    foreach (UserToken ut in utList)
                    {
                        if (ut.Token == token)
                        {
                            currentUt = ut;
                            break;
                        }
                    }
                }

                if (currentUt != null)
                {
                    if (currentUt.ExpiryDate < DateTime.Now)
                    {
                        check_user.AuthTokens.Remove(currentUt);
                        check_user.AuthToken = null;
                        userRepo.Update(check_user);
                    }
                    else
                    {
                        check_user.AuthTokens.Remove(currentUt);
                        currentUt.LastUsedDate = DateTime.Now;
                        check_user.AuthTokens.Add(currentUt);
                        userRepo.Update(check_user);
                    }
                }
            }
            unitOfWork.Commit();
            return check_user;
        }
Esempio n. 9
0
        public void SyncGameType()
        {
            ProgressUpdateArgs e = new ProgressUpdateArgs();
            // Sync required data from FHGLocal to DB

            _UnitOfWorkAPL = new UnitOfWork(_sessionHelper.GetSessionFactory("APL"));
            _UnitOfWorkFHG = new UnitOfWork(_sessionHelper.GetSessionFactory("FHG"));

            // State Table

            Repository<int, EvtDivision> _fhgEvtDivisionRep = new Repository<int, EvtDivision>(_UnitOfWorkFHG.Session);
            Repository<Guid, GameType> _aplGameTypeRepo = new Repository<Guid, GameType>(_UnitOfWorkAPL.Session);

            var gametypeAPLDB = _aplGameTypeRepo.All().ToList();
            var divisionFHG = _fhgEvtDivisionRep.All().ToList();

            int itemCount = 1;
            // Add Missing data
            foreach (EvtDivision c in divisionFHG)
            {
                e.TotalWorkItems = divisionFHG.Count();
                e.CurrentWorkItem = itemCount;
                e.StatusString = "Syncing Game Types - (" + itemCount.ToString() + "/" + e.TotalWorkItems.ToString() + ")";
                this.ProgressUpdate(e);

                bool found = false;
                foreach (GameType s in gametypeAPLDB)
                {
                    if (s.FhgDivisionId == c.Id)
                    {
                        found = true;
                        break;
                    }
                }
                if (!found)
                {
                    GameType s = new GameType();
                    s.FhgDivisionId = c.Id;
                    s.Gametype = c.Divisionname;
                    _aplGameTypeRepo.Add(s);
                }

                itemCount++;
            }

            // Remove extra data.
            foreach (GameType s in gametypeAPLDB)
            {
                bool found = false;
                foreach (EvtDivision c in divisionFHG)
                {
                    if (s.FhgDivisionId == c.Id)
                    {
                        found = true;
                        break;
                    }
                }

                if (!found)
                {
                    _aplGameTypeRepo.Delete(s);
                }
            }

            _UnitOfWorkAPL.Commit();
            _UnitOfWorkFHG.Commit();
        }
Esempio n. 10
0
        public void SyncGame()
        {
            ProgressUpdateArgs e = new ProgressUpdateArgs();
            e.StatusString = "Syncing Games - Reading data";
            this.ProgressUpdate(e);

            _UnitOfWorkAPL = new UnitOfWork(_sessionHelper.GetSessionFactory("APL"));
            _UnitOfWorkFHG = new UnitOfWork(_sessionHelper.GetSessionFactory("FHG"));

            // Customer/Memeber Table
            Repository<int, EvtEvent> _fhgEventRepo = new Repository<int, EvtEvent>(_UnitOfWorkFHG.Session);
            Repository<Guid, EvtGame> _fhgEvtGameRepo = new Repository<Guid, EvtGame>(_UnitOfWorkFHG.Session);
            Repository<Guid, Game> _aplGameRepo = new Repository<Guid, Game>(_UnitOfWorkAPL.Session);
            Repository<Guid, Venue> _aplVenueRepo = new Repository<Guid, Venue>(_UnitOfWorkAPL.Session);
            Repository<Guid, GameType> _aplGameTypeRepo = new Repository<Guid, GameType>(_UnitOfWorkAPL.Session);

            IList<object[]> fhgEvents = _UnitOfWorkFHG.Session.QueryOver<EvtEvent>()
                .Select(x => x.Eventid,
                x => x.Updateversion).Where(x => x.Eventdate >= DateTime.Today.AddDays(-7)).List<object[]>();

            IList<object[]> aplGames = _UnitOfWorkAPL.Session.QueryOver<Game>()
                .Select(c => c.Id,
                c => c.FHGEventId,
                c => c.FHGUpdateVersion).List<object[]>();

            Dictionary<int, object> aplGameList = new Dictionary<int, object>();
            foreach (object[] o in aplGames)
            {
                aplGameList.Add(int.Parse(o[1].ToString()), o);
            }

            int itemCount = 1;

            foreach (object[] fhgEventObject in fhgEvents)
            {
                try
                {
                    e.TotalWorkItems = fhgEvents.Count();
                    e.CurrentWorkItem = itemCount;
                    e.StatusString = "Syncing Games - (" + itemCount.ToString() + "/" + e.TotalWorkItems.ToString() + ")";
                    this.ProgressUpdate(e);

                    int fhgEventId = int.Parse(fhgEventObject[0].ToString());
                    Guid fhgUpdateVersion = Guid.Parse(fhgEventObject[1].ToString());

                    if (!aplGameList.ContainsKey(fhgEventId))
                    {

                        EvtEvent curEvent = _fhgEventRepo.FindBy(fhgEventId);

                        // Skip events which don't have a venue assigned.  Why??
                        if (!curEvent.Orgentityid.HasValue)
                        {
                            continue;
                        }

                        EvtGame curEventGame = curEvent.EvtGame[0];

                        Venue gameVenue = _aplVenueRepo.FilterBy(x => x.FHGVenueId == curEvent.Orgentityid).FirstOrDefault();
                        GameType gameType = _aplGameTypeRepo.FilterBy(x => x.FhgDivisionId == curEventGame.Divisionid).FirstOrDefault();

                        Game newGame = new Game();
                        newGame.FHGEventId = fhgEventId;
                        newGame.FHGUpdateVersion = curEvent.Updateversion;
                        newGame.Description = (!string.IsNullOrEmpty(curEventGame.Gamedescription)) ? curEventGame.Gamedescription : curEvent.Eventdescription;
                        newGame.GameDate = curEvent.Eventdate;
                        newGame.Name = curEvent.Eventname;
                        newGame.RegoTime = DateTime.Parse(curEvent.Eventdate.Value.ToShortDateString() + " " + curEvent.Registrationtime);
                        newGame.StartTime = DateTime.Parse(curEvent.Eventdate.Value.ToShortDateString() + " " + curEvent.Starttime);
                        newGame.Venue = gameVenue;
                        newGame.GameType = gameType;
                        newGame.Active = !curEvent.Archived.HasValue ? false : !(bool)curEvent.Archived;
                        newGame.BuyIn = curEventGame.Playerentryfee != null ? (float)curEventGame.Playerentryfee : 0;

                        _aplGameRepo.Add(newGame);

                    }
                    else
                    {
                        object[] aplComparison = (object[])aplGameList[fhgEventId];
                        Guid aplGameId = Guid.Parse(aplComparison[0].ToString());
                        int aplfhgGameId = int.Parse(aplComparison[1].ToString());
                        Guid aplfhgGameUpdateVersion = Guid.Parse(aplComparison[2].ToString());
                        // Check for updates.
                        if (fhgUpdateVersion != aplfhgGameUpdateVersion)
                        {
                            Game aplGame = _aplGameRepo.FindBy(aplGameId);
                            EvtEvent curEvent = _fhgEventRepo.FindBy(fhgEventId);
                            EvtGame curEventGame = curEvent.EvtGame[0];
                            Venue gameVenue = _aplVenueRepo.FilterBy(x => x.FHGVenueId == curEvent.Orgentityid).FirstOrDefault();
                            GameType gameType = _aplGameTypeRepo.FilterBy(x => x.FhgDivisionId == curEventGame.Divisionid).FirstOrDefault();
                            aplGame.FHGEventId = fhgEventId;
                            aplGame.FHGUpdateVersion = curEvent.Updateversion;
                            aplGame.Description = (!string.IsNullOrEmpty(curEventGame.Gamedescription)) ? curEventGame.Gamedescription : curEvent.Eventdescription;
                            aplGame.GameDate = curEvent.Eventdate;
                            aplGame.Name = curEvent.Eventname;
                            aplGame.RegoTime = DateTime.Parse(curEvent.Eventdate.Value.ToShortDateString() + " " + curEvent.Registrationtime);
                            aplGame.StartTime = DateTime.Parse(curEvent.Eventdate.Value.ToShortDateString() + " " + curEvent.Starttime);
                            aplGame.Venue = gameVenue;
                            aplGame.GameType = gameType;
                            aplGame.Active = !curEvent.Archived.HasValue ? false : !(bool)curEvent.Archived;
                            aplGame.BuyIn = curEventGame.Playerentryfee != null ? (float)curEventGame.Playerentryfee : 0;

                            _aplGameRepo.Update(aplGame);

                        }
                    }
                }
                catch (Exception mException)
                {
                    int x = 1;
                }
                finally
                {
                    itemCount++;
                }
            }
        }
Esempio n. 11
0
 private void PopulateForm(Guid _venueId)
 {
     _venue = new Venue();
     _unitOfWork = new UnitOfWork(_sessionHelper.GetSessionFactory("APL"));
     _venueRepo = new Repository<Guid, Venue>(_unitOfWork.Session);
     if (_venueId != Guid.Empty)
     {
         _venue = _venueRepo.FindBy(_venueId);
         if (_venue != null && _venue.Id != Guid.Empty)
         {
             SetGeolocation(true);
             btnGeoLocate.Enabled = true;
             tbxAddr1.Text = _venue.Address1;
             tbxAddr2.Text = _venue.Address2;
             tbxDesc.Text = _venue.Description;
             tbxEmail.Text = _venue.EmailAddress;
             tbxId.Text = _venue.Id.ToString();
             tbxLat.Text = _venue.Lattitude.ToString();
             tbxLong.Text = _venue.Longitude.ToString();
             tbxPcode.Text = (_venue.Postcode == 0 ? "" : _venue.Postcode.ToString());
             tbxPhone.Text = _venue.Phone;
             tbxSuburb.Text = _venue.Suburb;
             tbxURL.Text = _venue.Website;
             tbxVenueName.Text = _venue.Name;
             if (_venue.Region != null)
             {
                 cbxRegion.SelectedIndex = cbxRegion.FindStringExact(_venue.Region.Name);
             }
             btnGeoLocate.Enabled = true;
             btnSave.Enabled = true;
         } else
         {
             ClearForm();
         }
     } else
     {
         ClearForm();
     }
 }
Esempio n. 12
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;
        }
Esempio n. 13
0
        //public int SyncCustomer()
        public void SyncCustomer()
        {
            ProgressUpdateArgs e = new ProgressUpdateArgs();
            e.StatusString = "Syncing Customers - Reading data";
            this.ProgressUpdate(e);

            _UnitOfWorkAPL = new UnitOfWork(_sessionHelper.GetSessionFactory("APL"));
            _UnitOfWorkFHG = new UnitOfWork(_sessionHelper.GetSessionFactory("FHG"));

            //// Game Table
            DataLayer.Repository<Guid, CusCustomer> _fhgCustomerRepo = new Repository<Guid, CusCustomer>(_UnitOfWorkFHG.Session);
            DataLayer.Repository<Guid, MemMembership> _fhgMembershipRepo = new Repository<Guid, MemMembership>(_UnitOfWorkFHG.Session);
            Repository<Guid, User> _aplUserRepo = new Repository<Guid, User>(_UnitOfWorkFHG.Session);

            IList<object[]> fhgCustomers = _sessionHelper.GetStatelessSession("FHG").QueryOver<CusCustomer>()
                .Select(c => c.Customerguid,
                c => c.Updateversion).List<object[]>();

            IList<object[]> aplCustomerResult = _sessionHelper.GetStatelessSession("APL").QueryOver<User>()
                .Select(c => c.Id,
                c => c.FHGID,
                c => c.FHGUpdateID).List<object[]>();

            Dictionary<Guid, object> aplCustomers = new Dictionary<Guid, object>();
            foreach (object[] o in aplCustomerResult)
            {
                aplCustomers.Add(Guid.Parse(o[1].ToString()), o);
            }

            // Add Missing data
            int itemCount = 1;
            foreach (object[] fhgCustomerObject in fhgCustomers)
            {
                Guid fhgCustomerGuid = Guid.Parse(fhgCustomerObject[0].ToString());
                Guid fhgCustomerUpdateVersion = Guid.Parse(fhgCustomerObject[1].ToString());
                e.TotalWorkItems = fhgCustomers.Count();
                e.CurrentWorkItem = itemCount;
                e.StatusString = "Syncing Customers - (" + itemCount.ToString() + "/" + e.TotalWorkItems.ToString() + ")";

                this.ProgressUpdate(e);
                if (!aplCustomers.ContainsKey(fhgCustomerGuid))
                {
                    CusCustomer c = _fhgCustomerRepo.FindBy(fhgCustomerGuid);
                    User u = new User();
                    u.ContactEmail = c.Emailaddress;
                    u.ContactMobile = CleanPhoneNumber(c.Phonemobile);
                    u.ContactPhone = CleanPhoneNumber(c.Phonenumber);
                    if (c.Membership != null)
                        u.APLNumber = c.Membership.Membershipnumber;
                    u.Enabled = true;
                    u.FHGID = c.Id;
                    u.Surname = c.Lastname;
                    u.FirstName = c.Firstname;
                    u.Username = c.Username;
                    u.FHGUpdateID = c.Updateversion;

                    _aplUserRepo.Add(u);
                }
                else
                {
                    object[] aplComparison = (object[])aplCustomers[fhgCustomerGuid];
                    Guid aplUserId = Guid.Parse(aplComparison[0].ToString());
                    Guid aplfhgCustomerId = Guid.Parse(aplComparison[1].ToString());
                    Guid aplfhgCustomerUpdateVersion = Guid.Parse(aplComparison[2].ToString());
                    // Check for updates.
                    if (fhgCustomerUpdateVersion != aplfhgCustomerUpdateVersion)
                    {
                        CusCustomer c = _fhgCustomerRepo.FindBy(fhgCustomerGuid);
                        User u = _aplUserRepo.FindBy(aplUserId);
                        u.ContactEmail = c.Emailaddress;
                        u.ContactMobile = CleanPhoneNumber(c.Phonemobile);
                        u.ContactPhone = CleanPhoneNumber(c.Phonenumber);
                        u.Enabled = true;
                        u.FHGID = c.Id;
                        u.Surname = c.Lastname;
                        u.FirstName = c.Firstname;
                        u.Username = c.Username;
                        u.FHGUpdateID = c.Updateversion;
                        _aplUserRepo.Update(u);
                    }
                }

                itemCount++;
            }
            _UnitOfWorkAPL.Commit();
            _UnitOfWorkFHG.Commit();
        }
Esempio n. 14
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
            {

            }
        }
Esempio n. 15
0
        public void SyncRegion()
        {
            ProgressUpdateArgs e = new ProgressUpdateArgs();
            // Region Table
            //
            // Select data from FHGLocal
            // Select data from Local DB
            // Compare and update/insert.

            _UnitOfWorkAPL = new UnitOfWork(_sessionHelper.GetSessionFactory("APL"));
            _UnitOfWorkFHG = new UnitOfWork(_sessionHelper.GetSessionFactory("FHG"));

            DataLayer.Repository<int, CusRegion> _fhgRegionRepo = new Repository<int, CusRegion>(_UnitOfWorkFHG.Session);
            Repository<Guid, Region> _aplRegionRepo = new Repository<Guid, Region>(_UnitOfWorkAPL.Session);
            Repository<Guid, State> _aplStateRepo = new Repository<Guid, State>(_UnitOfWorkAPL.Session);
            Repository<Guid, Brand> _aplBrandRepo = new Repository<Guid, Brand>(_UnitOfWorkAPL.Session);

            var regionAPLDB = _aplRegionRepo.All().ToList();
            var regionFHG = _fhgRegionRepo.All().ToList();
            int itemCount = 1;
            // Add Missing data
            foreach (CusRegion c in regionFHG)
            {
                e.TotalWorkItems = regionFHG.Count();
                e.CurrentWorkItem = itemCount;
                e.StatusString = "Syncing Regions - (" + itemCount.ToString() + "/" + e.TotalWorkItems.ToString() + ")";
                this.ProgressUpdate(e);

                bool found = false;
                foreach (Region s in regionAPLDB)
                {
                    if (s.Name == c.Regionname)
                    {
                        found = true;
                        break;
                    }
                }
                if (!found)
                {
                    Region r = new Region();
                    r.Name = c.Regionname;
                    r.Active = !c.Archived.HasValue ? false : !(bool)c.Archived;
                    r.State = _aplStateRepo.FilterBy(s => s.Name == c.CusState.Fullname).FirstOrDefault();
                    r.Brand = _aplBrandRepo.FilterBy(x => x.FhgBrandId == c.Brandid).FirstOrDefault();
                    _aplRegionRepo.Add(r);
                }
                itemCount++;
            }

            // Remove extra data.
            foreach (Region r in regionAPLDB)
            {
                bool found = false;
                foreach (CusRegion cr in regionFHG)
                {
                    if (r.Name == cr.Regionname)
                    {
                        found = true;
                        break;
                    }
                }

                if (!found)
                {
                    _aplRegionRepo.Delete(r);
                }
            }

            _UnitOfWorkAPL.Commit();
            _UnitOfWorkFHG.Commit();
        }
Esempio n. 16
0
        public void SyncVenue()
        {
            ProgressUpdateArgs e = new ProgressUpdateArgs();
            // Venue Table

            _UnitOfWorkAPL = new UnitOfWork(_sessionHelper.GetSessionFactory("APL"));
            _UnitOfWorkFHG = new UnitOfWork(_sessionHelper.GetSessionFactory("FHG"));

            Repository<int, CusOrgentity> _fhgVenueRepo = new Repository<int, CusOrgentity>(_UnitOfWorkFHG.Session);
            Repository<Guid, Venue> _aplVenueRepo = new Repository<Guid, Venue>(_UnitOfWorkAPL.Session);
            Repository<Guid, Region> _aplRegionRepo = new Repository<Guid, Region>(_UnitOfWorkAPL.Session);

            //IList<object[]> fhgVenue = _sessionHelper.GetStatelessSession("FHG").QueryOver<CusOrgentity>()
            //                            .Select(c => c.Orgentityid,
            //                            c => c.Active,
            //                            c => c.Name).List<object[]>();

            //IList<object[]> aplVenueResult = _sessionHelper.GetStatelessSession("APL").QueryOver<Venue>()
            //    .Select(c => c.Id,
            //    c => c.FHGVenueId,
            //    c => c.Active,
            //    c => c.Name).List<object[]>();

            var fhgVenue = _fhgVenueRepo.All().ToList();
            var aplVenueResult = _aplVenueRepo.All().ToList();

            Dictionary<int, object> aplVenues = new Dictionary<int, object>();
            foreach (Venue o in aplVenueResult)
            {
                aplVenues.Add(o.FHGVenueId, o);
            }

            // Add Missing data
            int itemCount = 1;
            foreach (CusOrgentity fhgCustOrgEntity in fhgVenue)
            {
                try
                {
                     e.TotalWorkItems = fhgVenue.Count();
                    e.CurrentWorkItem = itemCount;
                    e.StatusString = "Syncing Venues - (" + itemCount.ToString() + "/" + e.TotalWorkItems.ToString() + ")";
                    this.ProgressUpdate(e);

                    if (!aplVenues.ContainsKey(fhgCustOrgEntity.Id))
                    {
                        CusOrgentity c = fhgCustOrgEntity;
                        Venue v = new Venue();
                        v.Name = c.Name;
                        v.Active = (c.Active != null) ? (bool)c.Active : true;
                        v.FHGVenueId = c.Id;
                        if (c.Region.Count > 0)
                        {
                            v.Region = _aplRegionRepo.FilterBy(x => x.Name == c.Region[0].Regionname).FirstOrDefault();
                        }
                        _aplVenueRepo.Add(v);
                    }
                    else
                    {
                        Venue aplVenue = (Venue)aplVenues[fhgCustOrgEntity.Id];

                        if (aplVenue.Active != fhgCustOrgEntity.Active || aplVenue.Name != fhgCustOrgEntity.Name)
                        {
                            aplVenue.Name = fhgCustOrgEntity.Name;
                            aplVenue.Active = (bool)(fhgCustOrgEntity.Active.HasValue ? false : fhgCustOrgEntity.Active);
                            _aplVenueRepo.Update(aplVenue);
                        }
                    }
                    itemCount++;
                }
                catch (Exception mException)
                {
                    int x = 1;
                    continue;
                }
            }

            _UnitOfWorkAPL.Commit();
            _UnitOfWorkFHG.Commit();
        }
Esempio n. 17
0
        public void SyncState()
        {
            ProgressUpdateArgs e = new ProgressUpdateArgs();
            // Sync required data from FHGLocal to DB

            _UnitOfWorkAPL = new UnitOfWork(_sessionHelper.GetSessionFactory("APL"));
            _UnitOfWorkFHG = new UnitOfWork(_sessionHelper.GetSessionFactory("FHG"));

            // State Table

            Repository<int, CusState> _fhgStateRep = new Repository<int, CusState>(_UnitOfWorkFHG.Session);
            Repository<Guid, State> _aplStateRepo = new Repository<Guid, State>(_UnitOfWorkAPL.Session);

            var stateAPLDB = _aplStateRepo.All().ToList();
            var stateFHG = _fhgStateRep.All().ToList();

            int itemCount = 1;
            // Add Missing data
            foreach (CusState c in stateFHG)
            {
                e.TotalWorkItems = stateFHG.Count();
                e.CurrentWorkItem = itemCount;
                e.StatusString = "Syncing States - (" + itemCount.ToString() + "/" + e.TotalWorkItems.ToString() + ")";
                this.ProgressUpdate(e);

                bool found = false;
                foreach (State s in stateAPLDB)
                {
                    if (s.Shortname == c.Shortname)
                    {
                        found = true;
                        break;
                    }
                }
                if (!found)
                {
                    State s = new State();
                    s.Shortname = c.Shortname;
                    s.Name = c.Fullname;
                    _aplStateRepo.Add(s);
                }

                itemCount++;
            }

            // Remove extra data.
            foreach (State s in stateAPLDB)
            {
                bool found = false;
                foreach (CusState c in stateFHG)
                {
                    if (s.Shortname == c.Shortname)
                    {
                        found = true;
                        break;
                    }
                }

                if (!found)
                {
                    _aplStateRepo.Delete(s);
                }
            }

            _UnitOfWorkAPL.Commit();
            _UnitOfWorkFHG.Commit();
        }
Esempio n. 18
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";
        }
Esempio n. 19
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;
        }