示例#1
0
        /// <summary>
        /// Create a new hunt object.
        /// </summary>
        /// <param name="huntId">Initial value of the HuntId property.</param>
        /// <param name="huntName">Initial value of the HuntName property.</param>
        /// <param name="password">Initial value of the Password property.</param>
        /// <param name="huntDescription">Initial value of the HuntDescription property.</param>
        public static hunt Createhunt(global::System.Int64 huntId, global::System.String huntName, global::System.String password, global::System.String huntDescription)
        {
            hunt hunt = new hunt();

            hunt.HuntId          = huntId;
            hunt.HuntName        = huntName;
            hunt.Password        = password;
            hunt.HuntDescription = huntDescription;
            return(hunt);
        }
 public List<long> GetHuntQuestions(hunt hunt)
 { 
     using (var context = new TreasureHuntEntities())
     {
         if (hunt == null) return null;
         var returnedquestionIds = context.huntquestions.Where(c => c.HuntId == hunt.HuntId).Select(s => s.QuestionId).ToList();
         returnedquestionIds.ForEach(e => context.ObjectStateManager.ChangeObjectState(e, System.Data.EntityState.Detached));
         return returnedquestionIds;
     }
 }
示例#3
0
 /// <summary>
 /// Deprecated Method for adding a new object to the hunts EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddTohunts(hunt hunt)
 {
     base.AddObject("hunts", hunt);
 }
 /// <summary>
 /// Create a new hunt object.
 /// </summary>
 /// <param name="huntId">Initial value of the HuntId property.</param>
 /// <param name="huntName">Initial value of the HuntName property.</param>
 /// <param name="huntDescription">Initial value of the HuntDescription property.</param>
 public static hunt Createhunt(global::System.Int64 huntId, global::System.String huntName, global::System.String huntDescription)
 {
     hunt hunt = new hunt();
     hunt.HuntId = huntId;
     hunt.HuntName = huntName;
     hunt.HuntDescription = huntDescription;
     return hunt;
 }
 /// <summary>
 /// Deprecated Method for adding a new object to the hunts EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddTohunts(hunt hunt)
 {
     base.AddObject("hunts", hunt);
 }
 //-http://stackoverflow.com/questions/15576282/sorting-a-c-sharp-list-by-multiple-columns
 //-http://stackoverflow.com/questions/18525253/wpf-listt-sort
 /// <summary>
 /// Method that returns all the huntparticipant data for a given treasure hunt. 
 /// </summary>
 /// <param name="currentTreasureHunt"></param>
 /// <returns></returns>
 public List<huntparticipant> GetHuntParticipants(hunt currentTreasureHunt)
 {
     using (var context = new TreasureHuntEntities())
     {
         if (currentTreasureHunt == null) return null;
         var returnedHuntParticipants = context.huntparticipants.Where(c => c.HuntId == currentTreasureHunt.HuntId).OrderByDescending(s => s.Tally).ThenBy(s => s.ElapsedTime).ToList();
         returnedHuntParticipants.ForEach(e => context.ObjectStateManager.ChangeObjectState(e, System.Data.EntityState.Detached));
         return returnedHuntParticipants;
     }
 }
 /// <summary>
 /// Method that saves new hunt data into the 'hunts' table. 
 /// </summary>
 /// <param name="newHunt"></param>
 /// <returns></returns>
 public long SaveNewHunt(hunt newHunt)
 {
     using (var context = new TreasureHuntEntities())
     {
         context.hunts.AddObject(newHunt);
         context.SaveChanges();
         context.ObjectStateManager.ChangeObjectState(newHunt, System.Data.EntityState.Added);
         return newHunt.HuntId;
     }
 }
        /// <summary>
        /// Method that returns a list of questions for a given hunt. 
        /// </summary>
        /// <param name="hunt"></param>
        /// <returns></returns>
        public IEnumerable<question> GetHuntQuestions(hunt hunt)
        {
            using (var context = new TreasureHuntEntities())
            {
                if (hunt == null) return null;
                //Grab all of the question ids associated with a given hunt.
                var returnedquestionIds = context.huntquestions.Where(c => c.HuntId == hunt.HuntId).Select(s => s.QuestionId).ToList();
                returnedquestionIds.ForEach(e => context.ObjectStateManager.ChangeObjectState(e, System.Data.EntityState.Detached));

                List<question> returnedListOfQuestions = new List<question>();

                //For each one of these ids
                foreach (var questionId in returnedquestionIds)
                {
                    //Add to the list the question associated with this id.
                    var question = context.questions.Where(c => c.QuestionId == questionId).Single();
                    context.ObjectStateManager.ChangeObjectState(question, System.Data.EntityState.Detached);
                    returnedListOfQuestions.Add(question);
                }

                return returnedListOfQuestions;
            }
        }