public List<Evidence> Get(long id, long CustomerID)
 {
     ChallengeStatus s = new ChallengeStatus();
     s.CustomerID = CustomerID;
     s.ChallengeID = id;
     return EvidenceRepo.GetAllForChallengeStatus(s);
 }
        public List<Evidence> GetAllForChallengeStatus(ChallengeStatus status)
        {
            CloudTableQuery<EvidenceDb> b = (from e in context.CreateQuery<EvidenceDb>(TableName) where e.PartitionKey == DbPartKey(status.ChallengeID, status.CustomerID) select e).AsTableServiceQuery<EvidenceDb>();
            List<Evidence> items = new List<Evidence>();

            foreach (EvidenceDb item in b)
            {
                items.Add(DbEvidenceToEvidence(item));
                context.Detach(item);
            }

            return items;
        }
Ejemplo n.º 3
0
        public ChallengeStatus Take(long ChallengeID, long CustomerID)
        {
            Challenge c = RepoFactory.GetChallengeRepo().Get(ChallengeID);

            if (c == null)
                throw new Exception("Challenge not found");

            ChallengeStatus s = new ChallengeStatus();
            s.ChallengeID = c.ID;
            s.ChallengeOriginatorCustomerID = c.CustomerID;
            s.CustomerID = ((DareyaIdentity)HttpContext.Current.User.Identity).CustomerID;
            s.Status = (int)ChallengeStatus.StatusCodes.Accepted;

            //Trace.WriteLine("Adding 'taking this dare' status for customer " + ((DareyaIdentity)HttpContext.Current.User.Identity).CustomerID.ToString() + " and challenge " + id.ToString(), "ChallengeController::Take");
            RepoFactory.GetChallengeStatusRepo().Add(s);

            CustomerNotifier.NotifyChallengeAccepted(s.ChallengeOriginatorCustomerID, s.CustomerID, c.ID);

            return s;
        }
        public void Accept(ChallengeStatus status)
        {
            Challenge c = ChalRepo.Get(status.ChallengeID);
            //ChallengeStatus s = StatusRepo.Get(((DareyaIdentity)HttpContext.Current.User.Identity).CustomerID, status.ChallengeID);

            if (status.CustomerID != c.TargetCustomerID)
                throw new HttpResponseException(System.Net.HttpStatusCode.NotFound);

            if (!Security.CanManipulateContent(c))
                throw new HttpResponseException(System.Net.HttpStatusCode.Forbidden);

            ChallengeStatus newStatus = new ChallengeStatus();
            newStatus.ChallengeID = c.ID;
            newStatus.ChallengeOriginatorCustomerID = c.CustomerID;
            newStatus.CustomerID = ((DareyaIdentity)HttpContext.Current.User.Identity).CustomerID;
            newStatus.Status = (int)ChallengeStatus.StatusCodes.Accepted;

            // add a friendship between these folk if one doesn't exist.
            if (!FriendRepo.CustomersAreFriends(c.CustomerID, ((DareyaIdentity)HttpContext.Current.User.Identity).CustomerID))
                FriendRepo.Add(c.CustomerID, ((DareyaIdentity)HttpContext.Current.User.Identity).CustomerID);

            c.State = (int)Challenge.ChallengeState.Accepted;
            ChalRepo.Update(c);

            CustomerNotifier.NotifyChallengeAccepted(c.CustomerID, c.TargetCustomerID, c.ID);

            try
            {
                Activity activity = new Activity(c.ID, DateTime.UtcNow) { Type = (int)ActivityType.ActivityTakeDare, CustomerID = newStatus.CustomerID };
                RepoFactory.GetActivityRepo().Add(activity);
            }
            catch (Exception e)
            {
                System.Diagnostics.Trace.WriteLine("Activity Exception: " + e.ToString());
            }
        }
 public void Add(ChallengeStatus value)
 {
     CoreAddOrUpdate(value, true);
 }
        private void CoreAddOrUpdate(ChallengeStatus value, bool Add=false)
        {
            ChallengeStatusDb targetCust = new ChallengeStatusDb(value);
            ChallengeStatusDb chal = new ChallengeStatusDb(value);

            string targetCustKey = DbCustKey(value.CustomerID);
            string chalKey = DbChalKey(value.ChallengeID);

            targetCust.PartitionKey = targetCustKey;
            targetCust.RowKey=chalKey;

            chal.PartitionKey = chalKey;
            chal.RowKey = targetCustKey;

            context.AttachTo(TableName, chal, null);
            context.UpdateObject(chal);

            context.AttachTo(TableName, targetCust, null);
            context.UpdateObject(targetCust);

            context.SaveChangesWithRetries();

            context.Detach(targetCust);
            context.Detach(chal);
        }
 // TODO: We should just start a partition ClaimedChalXXXX instead of doing this search,
 //       it could get costly.
 public ChallengeStatus GetNextVotePendingStatusForChallenge(long ChallengeID)
 {
     ChallengeStatusDb d = (from e in context.CreateQuery<ChallengeStatusDb>(TableName) where e.PartitionKey == DbChalKey(ChallengeID) && e.Status == (int)ChallengeStatus.StatusCodes.ClaimSubmitted select e).FirstOrDefault<ChallengeStatusDb>();
     if (d == null) return null;
     ChallengeStatus s = new ChallengeStatus(d);
     context.Detach(d);
     return s;
 }
Ejemplo n.º 8
0
        public ChallengeStatusDb(ChallengeStatus s)
        {
            //this.PartitionKey = "Chal" + s.ChallengeID;

               // if (s.UniqueID == null || s.UniqueID.Equals(""))
               //     s.UniqueID = System.Guid.NewGuid().ToString();

               // this.RowKey = s.UniqueID;
            this.ChallengeID = s.ChallengeID;
            this.ChallengeOriginatorCustomerID = s.ChallengeOriginatorCustomerID;
            this.Status = s.Status;
            this.CustomerID = s.CustomerID;
        }
 public int GetYesVotes(ChallengeStatus status)
 {
     IEnumerable<ChallengeStatusVoteDb> votes = (from e in context.CreateQuery<ChallengeStatusVoteDb>(TableName) where e.PartitionKey == DbPartitionForTaker(status.ChallengeID, status.CustomerID) select e).AsEnumerable<ChallengeStatusVoteDb>();
     return votes.Count(v => v.Accepted == true);
 }
        public void AcceptClaim(ChallengeStatus status)
        {
            ChallengeStatus s = StatusRepo.Get(status.CustomerID, status.ChallengeID);

            ChallengeBid bid = BidRepo.CustomerDidBidOnChallenge(((DareyaIdentity)HttpContext.Current.User.Identity).CustomerID, s.ChallengeID);
            if (bid == null)
                throw new HttpResponseException(System.Net.HttpStatusCode.Forbidden);

            try
            {
                if (VoteRepo.BidderDidVote(s.ChallengeID, s.CustomerID, bid.CustomerID) != null)
                    return; // you already voted, dawg.
            }
            catch (Exception e)
            {
                System.Diagnostics.Trace.WriteLine("Vote Repo Exception: " + e.ToString());
                throw new HttpResponseException(System.Net.HttpStatusCode.InternalServerError);
            }

            ChallengeStatusVote vote = new ChallengeStatusVote();
            vote.ChallengeID = s.ChallengeID;
            vote.CustomerID = s.CustomerID;
            vote.BidderCustomerID = ((DareyaIdentity)HttpContext.Current.User.Identity).CustomerID;
            vote.Accepted = true;

            try
            {
                if (!VoteRepo.Add(vote))
                {
                    // if this returns false, they probably already voted.
                    return; // HACK.
                }
            }
            catch (Exception e)
            {
                System.Diagnostics.Trace.WriteLine("Vote Repo Exception: " + e.ToString());
                throw new HttpResponseException(System.Net.HttpStatusCode.InternalServerError);
            }

            try
            {
                Activity activity = new Activity(s.ChallengeID, DateTime.UtcNow) { Type = (int)ActivityType.ActivityVoteYes, TakerCustomerID = vote.CustomerID, CustomerID = vote.BidderCustomerID };
                RepoFactory.GetActivityRepo().Add(activity);
            }
            catch (Exception e)
            {
                System.Diagnostics.Trace.WriteLine("Activity Exception: " + e.ToString());
            }

            int yesVotes = VoteRepo.GetYesVotes(s);
            if (yesVotes > (BidRepo.GetBidCountForChallenge(status.ChallengeID) * 0.33))
            {
                Challenge chal = ChalRepo.Get(s.ChallengeID);
                chal.State = (int)Challenge.ChallengeState.Completed;
                chal.TargetCustomerID = status.CustomerID;

                try
                {
                    ChalRepo.Update(chal);

                    BidRepo.UpdateStatusForBidsOnChallenge(s.ChallengeID, ChallengeBid.BidStatusCodes.Accepted);

                    s.Status = (int)ChallengeStatus.StatusCodes.Completed;
                    StatusRepo.Update(s);
                }
                catch (Exception e)
                {
                    System.Diagnostics.Trace.WriteLine("Challenge Status Exception: " + e.ToString());
                    throw new HttpResponseException(System.Net.HttpStatusCode.InternalServerError);
                }

                // challenge completed! award the money! DO IT DO IT!
                try
                {
                    Activity activity = new Activity(s.ChallengeID, DateTime.UtcNow) { Type = (int)ActivityType.ActivityComplete, CustomerID = status.CustomerID };
                    RepoFactory.GetActivityRepo().Add(activity);
                }
                catch (Exception e)
                {
                    System.Diagnostics.Trace.WriteLine("Activity Exception: " + e.ToString());
                }

                // queue the billing system to process this challenge status
                Dictionary<string, long> billingQueueItemData=new Dictionary<string,long>();
                billingQueueItemData.Add("ChalID", s.ChallengeID);
                billingQueueItemData.Add("CustID", s.CustomerID);
                RepoFactory.GetProcessingQueue().PutQueueMessage(ProcessingQueue.MessageType.Billing, billingQueueItemData);

                // notify the customer
                CustomerNotifier.NotifyChallengeAwardedToYou(s.CustomerID, s.ChallengeID);
            }
            else
            {
                // keep waitin'.

            }
        }
        public void RejectClaim(ChallengeStatus status)
        {
            ChallengeStatus s = StatusRepo.Get(status.CustomerID, status.ChallengeID);

            ChallengeBid bid=BidRepo.CustomerDidBidOnChallenge(((DareyaIdentity)HttpContext.Current.User.Identity).CustomerID, s.ChallengeID);
            if (bid==null)
                throw new HttpResponseException(System.Net.HttpStatusCode.Forbidden);

            if (VoteRepo.BidderDidVote(s.ChallengeID, s.CustomerID, bid.CustomerID)!=null)
                return; // you already voted, dawg.

            // add the "no" vote
            ChallengeStatusVote vote = new ChallengeStatusVote();
            vote.ChallengeID = s.ChallengeID;
            vote.CustomerID = s.CustomerID;
            vote.BidderCustomerID = ((DareyaIdentity)HttpContext.Current.User.Identity).CustomerID;
            vote.Accepted = false;

            if (!VoteRepo.Add(vote))
                return; // HACK.

            try
            {
                Activity activity = new Activity(s.ChallengeID, DateTime.UtcNow) { Type = (int)ActivityType.ActivityVoteNo, TakerCustomerID=vote.CustomerID, CustomerID = vote.BidderCustomerID };
                RepoFactory.GetActivityRepo().Add(activity);
            }
            catch (Exception e)
            {
                System.Diagnostics.Trace.WriteLine("Activity Exception: " + e.ToString());
            }

            int noVotes=VoteRepo.GetNoVotes(s);
            if(noVotes > (BidRepo.GetBidCountForChallenge(status.ChallengeID)*0.66))
            {
                s.Status = (int)ChallengeStatus.StatusCodes.SourceRejected;
                StatusRepo.Update(s);

                // get the next homey who's working on this, if any.
                ChallengeStatus nextStatus = StatusRepo.GetNextVotePendingStatusForChallenge(s.ChallengeID);
                if (nextStatus != null)
                {
                    BidRepo.UpdateVotePendingCustomerIDForChallenge(s.ChallengeID, nextStatus.CustomerID);
                }
                else
                {
                    // reopen the bidding! NO WINNER NO WINNER

                }

                // you've failed this challenge my friend.
                //CustomerNotifier.NotifyChallengeRejected(s.CustomerID, s.ChallengeID);
            }
            else
            {

            }
        }
        public void Reject(ChallengeStatus status)
        {
            Challenge c = ChalRepo.Get((int)status.ChallengeID);

            if (c.TargetCustomerID != ((DareyaIdentity)HttpContext.Current.User.Identity).CustomerID)
                throw new HttpResponseException(System.Net.HttpStatusCode.Forbidden);

            if (!Security.CanManipulateContent(c))
                throw new HttpResponseException(System.Net.HttpStatusCode.Forbidden);

            // the recipient has rejected this challenge. it dies here.
            // the creator will have to make a new one to re-issue it.
            c.State = (int)Challenge.ChallengeState.Rejected;

            try
            {
                ChalRepo.Update(c);
            }
            catch (Exception e)
            {
                System.Diagnostics.Trace.WriteLine("Reject Challenge Exception: " + e.ToString() + " status: "+status.ToString());
                throw new HttpResponseException(System.Net.HttpStatusCode.InternalServerError);
            }

            CustomerNotifier.NotifyChallengeRejected(c.CustomerID, c.TargetCustomerID, c.ID);

            try
            {
                Activity activity = new Activity(c.ID, DateTime.UtcNow) { Type = (int)ActivityType.ActivityRejectDare, CustomerID = c.TargetCustomerID };
                RepoFactory.GetActivityRepo().Add(activity);
            }
            catch (Exception e)
            {
                System.Diagnostics.Trace.WriteLine("Activity Exception: " + e.ToString());
            }
        }
        public void Claim(ChallengeStatus status)
        {
            ChallengeStatus s = StatusRepo.Get(status.CustomerID, status.ChallengeID);
            //Challenge c = ChalRepo.Get(status.ChallengeID);

            if (s.CustomerID != ((DareyaIdentity)HttpContext.Current.User.Identity).CustomerID)
                throw new HttpResponseException(System.Net.HttpStatusCode.Forbidden);

            s.Status = (int)ChallengeStatus.StatusCodes.ClaimSubmitted;
            StatusRepo.Update(s);

            // close the bidding on this challenge until the claim can be verified.
            //c.State = (int)Challenge.ChallengeState.BidsClosed;
            //ChalRepo.Update(c);

            // set all of the bids for this challenge to "VotePending"
            // so the bidders can see what they need to vote on
            BidRepo.UpdateStatusForBidsOnChallenge(status.ChallengeID, ChallengeBid.BidStatusCodes.VotePending);

            CustomerNotifier.NotifyChallengeClaimed(s.ChallengeOriginatorCustomerID, s.CustomerID, s.ChallengeID);

            try
            {
                Activity activity = new Activity(s.ChallengeID, DateTime.UtcNow) { Type = (int)ActivityType.ActivityClaimDone, CustomerID = s.CustomerID };
                RepoFactory.GetActivityRepo().Add(activity);
            }
            catch (Exception e)
            {
                System.Diagnostics.Trace.WriteLine("Activity Exception: " + e.ToString());
            }
        }
        public ChallengeStatus Get(long CustomerID, long ChallengeID)
        {
            ChallengeStatusDb d = (from e in context.CreateQuery<ChallengeStatusDb>(TableName) where e.PartitionKey == DbCustKey(CustomerID) && e.RowKey == DbChalKey(ChallengeID) select e).FirstOrDefault<ChallengeStatusDb>();

            if (d == null) return null;
            ChallengeStatus s = new ChallengeStatus(d);
            context.Detach(d);
            return s;
        }
        public ChallengeStatus Take(long id)
        {
            Trace.WriteLine("Customer " + ((DareyaIdentity)HttpContext.Current.User.Identity).CustomerID.ToString() + " wants to take challenge "+id.ToString(), "ChallengeController::Take");

            Challenge c = ChalRepo.Get(id);

            if (c == null)
                throw new HttpResponseException(System.Net.HttpStatusCode.NotFound);

            if (!Security.CanManipulateContent(c))
                throw new HttpResponseException(System.Net.HttpStatusCode.Forbidden);

            /*
            if (c.TargetCustomerID == ((DareyaIdentity)HttpContext.Current.User.Identity).CustomerID)
                throw new DaremetoResponseException("This Challenge was sent to the current user; call /challengestatus/accept instead", System.Net.HttpStatusCode.Conflict);
            */

            if (c.CustomerID == ((DareyaIdentity)HttpContext.Current.User.Identity).CustomerID)
                throw new HttpResponseException(System.Net.HttpStatusCode.Conflict);

            if (c.TargetCustomerID == ((DareyaIdentity)HttpContext.Current.User.Identity).CustomerID)
            {
                // if this dare was sent directly to the customer,
                // we can go ahead and mark it Accepted since it's no
                // longer open for additional takers.
                c.State = (int)Challenge.ChallengeState.Accepted;
                ChalRepo.Update(c);
            }

            // already took it?
            if(StatusRepo.CustomerTookChallenge(((DareyaIdentity)HttpContext.Current.User.Identity).CustomerID, id))
                throw new HttpResponseException(System.Net.HttpStatusCode.Forbidden);

            ChallengeStatus s = new ChallengeStatus();
            s.ChallengeID = c.ID;
            s.ChallengeOriginatorCustomerID = c.CustomerID;
            s.CustomerID = ((DareyaIdentity)HttpContext.Current.User.Identity).CustomerID;
            s.Status = (int)ChallengeStatus.StatusCodes.Accepted;

            Trace.WriteLine("Adding 'taking this dare' status for customer " + ((DareyaIdentity)HttpContext.Current.User.Identity).CustomerID.ToString() + " and challenge " + id.ToString(), "ChallengeController::Take");
            StatusRepo.Add(s);

            CustomerNotifier.NotifyChallengeAccepted(s.ChallengeOriginatorCustomerID, s.CustomerID, c.ID);

            Activity activity = new Activity(s.ChallengeID, DateTime.UtcNow) { Type = (int)ActivityType.ActivityTakeDare, CustomerID = s.CustomerID };
            RepoFactory.GetActivityRepo().Add(activity);

            return s;
        }
Ejemplo n.º 16
0
        public Disposition DetermineDisposition(ChallengeStatus s)
        {
            if (!HttpContext.Current.User.Identity.IsAuthenticated)
                return Disposition.None;

            long curCustID=((Models.DareyaIdentity)HttpContext.Current.User.Identity).CustomerID;

            if (s.CustomerID == curCustID)
                return Disposition.Taker;

            if (s.ChallengeOriginatorCustomerID == curCustID)
                return Disposition.Originator;

            if (RepoFactory.GetChallengeBidRepo().CustomerDidBidOnChallenge(curCustID, s.ChallengeID)!=null)
                return Disposition.Backer;

            return Disposition.None;
        }
 public int GetCount(ChallengeStatus status)
 {
     int count=(from e in context.CreateQuery<ChallengeStatusVoteDb>(TableName) where e.PartitionKey==DbPartitionForTaker(status.ChallengeID, status.CustomerID) select e).Count();
     return count;
 }