public List<Evidence> Get(long id, long CustomerID)
 {
     ChallengeStatus s = new ChallengeStatus();
     s.CustomerID = CustomerID;
     s.ChallengeID = id;
     return EvidenceRepo.GetAllForChallengeStatus(s);
 }
 public ChallengeStatus Get(long id, string key)
 {
     ChallengeStatusDb s = (from e in context.CreateQuery<ChallengeStatusDb>(TableName) where e.PartitionKey == "Chal"+id.ToString() && e.RowKey == key select e).FirstOrDefault();
     ChallengeStatus outS = new ChallengeStatus(s);
     context.Detach(s);
     return outS;
 }
        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);
        }
        public void Update(ChallengeStatus value)
        {
            if (value.UniqueID == null || value.UniqueID.Equals(""))
                throw new InvalidOperationException("UniqueID is a required parameter");

            CoreAddOrUpdate(value);

            // update all three partitions using the rowkey
        }
        public List<Evidence> GetAllForChallengeStatus(ChallengeStatus status)
        {
            CloudTableQuery<EvidenceDb> b = (from e in context.CreateQuery<EvidenceDb>(TableName) where e.PartitionKey == status.ChallengeID+"_"+status.UniqueID select e).AsTableServiceQuery<EvidenceDb>();
            List<Evidence> items = new List<Evidence>();

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

            return items;
        }
        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("You can't accept a claim on a challenge you don't have a stake in.", System.Net.HttpStatusCode.Forbidden);

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

            VoteRepo.Add(vote);

            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;
                ChalRepo.Update(chal);

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

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

                // challenge completed! award the money! DO IT DO IT!

                // 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'.

            }
        }
Beispiel #7
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;
        }
        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);
        }
 public void Add(ChallengeStatus value)
 {
     CoreAddOrUpdate(value, true);
 }
 // 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;
 }
        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;
        }
        private void CoreAddOrUpdate(ChallengeStatus value, bool Add=false)
        {
            ChallengeStatusDb sourceCust = new ChallengeStatusDb(value);
            ChallengeStatusDb targetCust = new ChallengeStatusDb(value);
            ChallengeStatusDb chal = new ChallengeStatusDb(value);

            targetCust.PartitionKey = "Cust" + value.CustomerID;
            sourceCust.PartitionKey = "SourceCust" + value.ChallengeOriginatorCustomerID;
            chal.PartitionKey = "Chal" + value.ChallengeID;

            if (Add)
                context.AddObject(TableName, sourceCust);
            else
            {
                context.AttachTo(TableName, sourceCust, null);
                context.UpdateObject(sourceCust);
            }

            if (Add)
                context.AddObject(TableName, targetCust);
            else
            {
                context.AttachTo(TableName, targetCust, null);
                context.UpdateObject(targetCust);
            }

            if (Add)
                context.AddObject(TableName, chal);
            else
            {
                context.AttachTo(TableName, chal, null);
                context.UpdateObject(chal);
            }

            context.SaveChangesWithRetries();

            context.Detach(sourceCust);
            context.Detach(targetCust);
            context.Detach(chal);
        }
 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 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("You can't deny a claim on a challenge you don't have a stake in.", System.Net.HttpStatusCode.Forbidden);

            // 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;

            VoteRepo.Add(vote);

            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.Privacy != (int)Challenge.ChallengePrivacy.SinglePerson || c.TargetCustomerID != ((DareyaIdentity)HttpContext.Current.User.Identity).CustomerID)
                throw new HttpResponseException(System.Net.HttpStatusCode.NotImplemented);

            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;
            ChalRepo.Update(c);

            CustomerNotifier.NotifyChallengeRejected(c.CustomerID, c.TargetCustomerID, c.ID);
        }
        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("This challenge status doesn't belong to the current user.", 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);
        }
 public int GetYesVotes(ChallengeStatus status)
 {
     IEnumerable<ChallengeStatusVoteDb> votes = (from e in context.CreateQuery<ChallengeStatusVoteDb>(TableName) where e.PartitionKey == status.ChallengeID + "_" + status.UniqueID select e).AsEnumerable<ChallengeStatusVoteDb>();
     return votes.Count(v => v.Accepted == true);
 }
 public int GetCount(ChallengeStatus status)
 {
     int count=(from e in context.CreateQuery<ChallengeStatusVoteDb>(TableName) where e.PartitionKey==status.ChallengeID+"_"+status.UniqueID select e).Count();
     return count;
 }
 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;
 }
Beispiel #20
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;
        }
Beispiel #21
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 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 DaremetoResponseException("The requested Challenge resource doesn't exist.", System.Net.HttpStatusCode.NotFound);

            if (!Security.CanManipulateContent(c))
                throw new DaremetoResponseException("This Challenge can't be taken by this customer.", 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 DaremetoResponseException("This Challenge originated from the current user; you can't take your own dare", 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);
            }

            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)Activity.ActivityType.ActivityTakeDare, CustomerID = s.CustomerID };
            RepoFactory.GetActivityRepo().Add(activity);

            return s;
        }