コード例 #1
0
 /// <summary>
 /// Method that saves userhunt data in the 'userhunts' table.
 /// </summary>
 /// <param name="userHunt"></param>
 public void SaveUserHunt(userhunt userHunt)
 {
     using (var context = new TreasureHuntEntities())
     {
         context.userhunts.AddObject(userHunt);
         context.SaveChanges();
         context.ObjectStateManager.ChangeObjectState(userHunt, System.Data.EntityState.Added);
     }
 }
コード例 #2
0
        //Change this to private and use reflection for testing
        public void ExecuteSaveHuntNameCommand()
        {
            if (!DoesHuntAlreadyExist(HuntName))
            {
                hunt newHunt = new hunt();
                newHunt.HuntName        = this.huntName;
                newHunt.Password        = this.Password;
                newHunt.HuntDescription = this.Description;
                long huntId = this.serviceClient.SaveNewHunt(newHunt);

                userrole newUserRole = this.serviceClient.GetUserRole(this.currentUser);

                userhunt newUserHunt = new userhunt();
                newUserHunt.HuntId     = huntId;
                newUserHunt.UserId     = this.currentUser.UserId;
                newUserHunt.UserRoleId = newUserRole.UserRoleId;

                this.serviceClient.SaveUserHunt(newUserHunt);

                //Grabs the correct hunt's ID and passes it into the view hunt view.
                //Ensures that the hunt has been saved to the database before it goes and grab's it
                hunt huntToView = serviceClient.GetHuntBasedOnName(newHunt.HuntName);

                Messenger.Default.Send <UpdateViewMessage>(new UpdateViewMessage()
                {
                    UpdateViewTo = "ViewHuntViewModel"
                });
                Messenger.Default.Send <SelectedHuntMessage>(new SelectedHuntMessage()
                {
                    CurrentHunt = huntToView
                });
                Messenger.Default.Send <ViewUpdatedMessage>(new ViewUpdatedMessage()
                {
                    UpdatedView = true
                });

                HuntName        = null;
                Password        = null;
                RetypedPassword = null;
                Description     = null;
            }
            else
            {
                String           messageBoxText = "This hunt already exists in the database.";
                String           caption        = "Hunt Already Exists";
                MessageBoxResult box            = MessageBox.Show(messageBoxText, caption);
                HuntName = null;
            }
        }
コード例 #3
0
        /// <Summary> Method that saves a new hunt to the database. </Summary>
        private async void SaveNewHunt()
        {
            hunt newHunt = new hunt();

            newHunt.HuntName        = this.huntName;
            newHunt.HuntDescription = this.Description;
            newHunt.EndDate         = EndDate;

            //Create it and save it to the database.
            long huntId = await this.serviceClient.SaveNewHuntAsync(newHunt);

            userhunt newUserHunt = new userhunt();

            newUserHunt.HuntId = huntId;
            newUserHunt.UserId = this.currentUser.UserId;

            await this.serviceClient.SaveUserHuntAsync(newUserHunt);

            //Grab the correct hunt's ID and pass it into the view hunt view.
            hunt huntToView = await serviceClient.GetHuntBasedOnNameAsync(newHunt.HuntName, currentUser.UserId);

            PopupDisplayed = false;

            Messenger.Default.Send <UpdateViewMessage>(new UpdateViewMessage()
            {
                UpdateViewTo = "ViewHuntViewModel"
            });
            Messenger.Default.Send <SelectedHuntMessage>(new SelectedHuntMessage()
            {
                CurrentHunt = huntToView
            });
            Messenger.Default.Send <ViewUpdatedMessage>(new ViewUpdatedMessage()
            {
                UpdatedView = true
            });

            HuntName    = null;
            Description = null;
            EndDate     = DateTime.Today;
        }
コード例 #4
0
        //Change this to private and use reflection for testing
        public void ExecuteSaveHuntNameCommand()
        {
            if (!DoesHuntAlreadyExist(HuntName))
            {
                hunt newHunt = new hunt();
                newHunt.HuntName = this.huntName;
                newHunt.Password = this.Password;
                newHunt.HuntDescription = this.Description;
                long huntId = this.serviceClient.SaveNewHunt(newHunt);

                userrole newUserRole = this.serviceClient.GetUserRole(this.currentUser);

                userhunt newUserHunt = new userhunt();
                newUserHunt.HuntId = huntId;
                newUserHunt.UserId = this.currentUser.UserId;
                newUserHunt.UserRoleId = newUserRole.UserRoleId;

                this.serviceClient.SaveUserHunt(newUserHunt);
                
                //Grabs the correct hunt's ID and passes it into the view hunt view.
                //Ensures that the hunt has been saved to the database before it goes and grab's it
                hunt huntToView = serviceClient.GetHuntBasedOnName(newHunt.HuntName);

                Messenger.Default.Send<UpdateViewMessage>(new UpdateViewMessage() { UpdateViewTo = "ViewHuntViewModel" });
                Messenger.Default.Send<SelectedHuntMessage>(new SelectedHuntMessage() { CurrentHunt = huntToView });
                Messenger.Default.Send<ViewUpdatedMessage>(new ViewUpdatedMessage() { UpdatedView = true });

                HuntName = null;
                Password = null;
                RetypedPassword = null;
                Description = null;
            }
            else 
            {
                String messageBoxText = "This hunt already exists in the database.";
                String caption = "Hunt Already Exists";
                MessageBoxResult box = MessageBox.Show(messageBoxText, caption);
                HuntName = null;
            }
        }
コード例 #5
0
        /// <Summary> Method that saves a new hunt to the database. </Summary>
        private async void SaveNewHunt()
        { 
            hunt newHunt = new hunt();
            newHunt.HuntName = this.huntName;
            newHunt.HuntDescription = this.Description;
            newHunt.EndDate = EndDate;

            //Create it and save it to the database.
            long huntId = await this.serviceClient.SaveNewHuntAsync(newHunt);

            userhunt newUserHunt = new userhunt();
            newUserHunt.HuntId = huntId;
            newUserHunt.UserId = this.currentUser.UserId;

            await this.serviceClient.SaveUserHuntAsync(newUserHunt);

            //Grab the correct hunt's ID and pass it into the view hunt view.
            hunt huntToView = await serviceClient.GetHuntBasedOnNameAsync(newHunt.HuntName, currentUser.UserId);

            PopupDisplayed = false;

            Messenger.Default.Send<UpdateViewMessage>(new UpdateViewMessage() { UpdateViewTo = "ViewHuntViewModel" });
            Messenger.Default.Send<SelectedHuntMessage>(new SelectedHuntMessage() { CurrentHunt = huntToView });
            Messenger.Default.Send<ViewUpdatedMessage>(new ViewUpdatedMessage() { UpdatedView = true });

            HuntName = null;
            Description = null;
            EndDate = DateTime.Today;
        }