public CustomerForeignNetworkConnectionDb(CustomerForeignNetworkConnection c, bool PartitionWithForeignKey)
        {
            if (PartitionWithForeignKey) // search by Type+ID
            {
                this.PartitionKey = c.Type.ToString() + "+" + c.UserID;
                this.RowKey = "Cust"+c.CustomerID.ToString();
            }
            else // search by CustomerID
            {
                this.PartitionKey = "Cust" + c.CustomerID.ToString();
                this.RowKey = c.Type.ToString() + "+" + c.UserID;
            }

            this.Type = c.Type;
            this.UserID = c.UserID;
            this.AccessToken = c.AccessToken;
            this.AccessSecret = c.AccessSecret;
            this.CustomerID = c.CustomerID;
        }
        public void AddForeignNetworkForCustomer(long ID, string ForeignID, Customer.ForeignUserTypes type)
        {
            CustomerForeignNetworkConnection f = new CustomerForeignNetworkConnection { CustomerID = ID, UserID = ForeignID, Type = (int)type };

            // store it for both kinds of lookup:
            //      * by foreign ID
            //      * by customer ID
            //
            CustomerForeignNetworkConnectionDb fDB1 = new CustomerForeignNetworkConnectionDb(f, true);
            CustomerForeignNetworkConnectionDb fDB2 = new CustomerForeignNetworkConnectionDb(f, false);

            context.AttachTo(TableName, fDB1, null);
            context.AttachTo(TableName, fDB2, null);

            context.UpdateObject(fDB1);
            context.UpdateObject(fDB2);

            context.SaveChangesWithRetries();

            context.Detach(fDB1);
            context.Detach(fDB2);
        }
        public void RemoveForeignNetworkForCustomer(long ID, string ForeignID, Customer.ForeignUserTypes type)
        {
            CustomerForeignNetworkConnection f = new CustomerForeignNetworkConnection { CustomerID = ID, UserID = ForeignID.ToLower(), Type = (int)type };

            CustomerForeignNetworkConnectionDb fDB1 = new CustomerForeignNetworkConnectionDb(f, true);
            CustomerForeignNetworkConnectionDb fDB2 = new CustomerForeignNetworkConnectionDb(f, false);

            context.AttachTo(TableName, fDB1);
            context.AttachTo(TableName, fDB2);

            context.DeleteObject(fDB1);
            context.SaveChangesWithRetries();

            context.DeleteObject(fDB2);
            context.SaveChangesWithRetries();
        }
        public void ForeignNetwork(CustomerForeignNetworkConnection d)
        {
            long curCustID = ((DareyaIdentity)HttpContext.Current.User.Identity).CustomerID;
            if (d.CustomerID != curCustID)
                throw new HttpResponseException(System.Net.HttpStatusCode.Forbidden);

            OnboardManager mgr=new OnboardManager();

            try
            {
                bool res = mgr.LinkForeignUserToCustomer(Repo.GetWithID(curCustID), d.UserID, (Customer.ForeignUserTypes)d.Type);
                if (!res)
                    throw new HttpResponseException(System.Net.HttpStatusCode.Forbidden);
            }
            catch (Exception e)
            {
                throw new HttpResponseException(System.Net.HttpStatusCode.InternalServerError);
            }
        }