public bool CanManipulateContent(Challenge c)
        {
            if (!HttpContext.Current.User.Identity.IsAuthenticated)
                return false;

            if (c.Privacy == (int)Challenge.ChallengePrivacy.SinglePerson)
            {
                if (c.TargetCustomerID == ((Models.DareyaIdentity)HttpContext.Current.User.Identity).CustomerID)
                    return true;
                else
                    return false;
            }

            Audience a = CoreDetermineAudience(((Models.DareyaIdentity)HttpContext.Current.User.Identity).CustomerID);
            switch (a)
            {
                case Audience.Users:
                    //if (c.Privacy == (int)Challenge.ChallengePrivacy.FriendsOnly)
                    //    return false;

                    return true;

                case Audience.Owner:
                    return true;

                case Audience.Friends:
                    return true;

                case Audience.Anybody:
                default:
                    return false;
            }
        }
 public void AddBidToChallenge(Challenge item, long lCustomerID, decimal dBidAmount, decimal dComputedFees)
 {
     using (SqlConnection db = new SqlConnection(connStr))
     {
         db.Open();
         db.Execute("AddBidToChallenge", new { ChallengeID = item.ID, BidAmount = dBidAmount, CustomerID = lCustomerID, FeesAmount = dComputedFees }, commandType: CommandType.StoredProcedure);
     }
 }
 public Challenge CheckForDuplicate(Challenge item)
 {
     using (SqlConnection db = new SqlConnection(connStr))
     {
         db.Open();
         var chal = db.Query<Challenge>("spChallengeFindExisting", new { Description=item.Description, CustomerID=item.CustomerID, Privacy=item.Privacy, Date=item.Created }, commandType: CommandType.StoredProcedure);
         return chal.FirstOrDefault<Challenge>();
     }
 }
 public long Add(Challenge item)
 {
     using (SqlConnection conn = new SqlConnection(connStr))
     {
         conn.Open();
         DynamicParameters p = ChalToDynParm(item);
         p.Add("@InsertID", dbType: DbType.Int64, direction: ParameterDirection.Output);
         conn.Execute("spChallengeAdd", p, commandType: CommandType.StoredProcedure);
         return p.Get<long>("InsertID");
     }
 }
 public Audience DetermineVisibility(Challenge c)
 {
     return Audience.Users;
 }
        public Disposition DetermineDisposition(Challenge c)
        {
            if (!HttpContext.Current.User.Identity.IsAuthenticated)
                return Disposition.None;

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

            if(c.CustomerID==curCustID)
                return Disposition.Originator;

            if(c.TargetCustomerID==curCustID)
                return Disposition.Taker;

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

            if (RepoFactory.GetChallengeStatusRepo().CustomerTookChallenge(curCustID, c.ID))
                return Disposition.Taker;

            return Disposition.None;
        }
 public Audience DetermineAudience(Challenge c)
 {
     return CoreDetermineAudience(c.CustomerID);
 }
        private DynamicParameters ChalToDynParm(Challenge c, bool inclID = false)
        {
            var p = new DynamicParameters();

            p.Add("@Description", c.Description, DbType.String, ParameterDirection.Input);
            p.Add("@Privacy", c.Privacy, DbType.Int32, ParameterDirection.Input);
            p.Add("@Visibility", c.Visibility, DbType.Int32, ParameterDirection.Input);
            p.Add("@State", c.State, DbType.Int32, ParameterDirection.Input);
            p.Add("@Anonymous", c.Anonymous, DbType.Int32, ParameterDirection.Input);
            p.Add("@CustomerID", c.CustomerID, DbType.Int64, ParameterDirection.Input);
            p.Add("@TargetCustomerID", c.TargetCustomerID, DbType.Int64, ParameterDirection.Input);
            if (inclID)
                p.Add("@ID", c.ID, DbType.Int64, ParameterDirection.Input);

            return p;
        }
 public bool Update(Challenge item)
 {
     using (SqlConnection conn = new SqlConnection(connStr))
     {
         conn.Open();
         DynamicParameters p = ChalToDynParm(item, true);
         return (conn.Execute("spChallengeUpdate", p, commandType: CommandType.StoredProcedure) != 0);
     }
 }
        private Challenge PrepOutboundChallenge(Challenge c)
        {
            if (c == null) return null;

            c.Customer = CustRepo.GetBasicWithID(c.CustomerID);

            if (c.TargetCustomerID > 0)
            {
                c.TargetCustomer = CustRepo.GetBasicWithID(c.TargetCustomerID);
            }

            c.Disposition = (int)Security.DetermineDisposition(c);

            try
            {
                if (c.Disposition == (int)Security.Disposition.Taker)
                    c.Status = StatusRepo.Get(((DareyaIdentity)HttpContext.Current.User.Identity).CustomerID, c.ID);
                else if (c.Disposition == (int)Security.Disposition.Backer || c.Disposition==(int)Security.Disposition.Originator)
                    c.Bid = BidRepo.CustomerDidBidOnChallenge(((DareyaIdentity)HttpContext.Current.User.Identity).CustomerID, c.ID);
            }
            catch (Exception e)
            {
            }

            c.NumberOfBidders = BidRepo.GetBidCountForChallenge(c.ID);
            c.NumberOfTakers = StatusRepo.GetActiveStatusesForChallenge(c.ID).Count;

            c.Activity = RepoFactory.GetActivityRepo().GetMostRecentForChallenge(c.ID);

            if (c.Activity != null && c.Activity.CustomerID != 0)
                c.Activity.Customer = CustRepo.GetBasicWithID(c.Activity.CustomerID);

            return c;
        }