Esempio n. 1
0
        private bool LogReferral(long affiliateId, string referrerUrl)
        {
            Contacts.Affiliate aff = Affiliates.Find(affiliateId);
            if (aff == null)
            {
                return(false);
            }
            if (!aff.Enabled)
            {
                return(false);
            }

            AffiliateReferral r = new AffiliateReferral();

            r.AffiliateId = aff.Id;
            r.ReferrerUrl = referrerUrl;
            return(AffiliateReferrals.Create(r));
        }
        // Create or Update
        public override string PostAction(string parameters, System.Collections.Specialized.NameValueCollection querystring, string postdata)
        {
            string data = string.Empty;
            string ids = FirstParameter(parameters);
            long id = 0;
            long.TryParse(ids, out id);
            string isReferrals = GetParameterByIndex(1, parameters);

            if (isReferrals.Trim().ToLowerInvariant() == "referrals")
            {
                // Create Referral
                ApiResponse<AffiliateReferralDTO> responseA = new ApiResponse<AffiliateReferralDTO>();
                AffiliateReferralDTO postedItemA = null;
                try
                {
                    postedItemA = MerchantTribe.Web.Json.ObjectFromJson<AffiliateReferralDTO>(postdata);
                }
                catch (Exception ex)
                {
                    responseA.Errors.Add(new ApiError("EXCEPTION", ex.Message));
                    return MerchantTribe.Web.Json.ObjectToJson(responseA);
                }
                AffiliateReferral itemA = new AffiliateReferral();
                itemA.FromDto(postedItemA);
                MTApp.ContactServices.AffiliateReferrals.Create2(itemA, true);
                responseA.Content = itemA.ToDto();
                data = MerchantTribe.Web.Json.ObjectToJson(responseA);
            }
            else
            {
                // Create/Update Affiliate
                ApiResponse<AffiliateDTO> responseB = new ApiResponse<AffiliateDTO>();
                AffiliateDTO postedItem = null;
                try
                {
                    postedItem = MerchantTribe.Web.Json.ObjectFromJson<AffiliateDTO>(postdata);
                }
                catch (Exception ex)
                {
                    responseB.Errors.Add(new ApiError("EXCEPTION", ex.Message));
                    return MerchantTribe.Web.Json.ObjectToJson(responseB);
                }

                Affiliate item = new Affiliate();
                item.FromDto(postedItem);

                if (id < 1)
                {
                    Affiliate existing = MTApp.ContactServices.Affiliates.FindByReferralId(item.ReferralId);
                    if (existing == null || existing.Id < 1)
                    {

                        // Create
                        bool result = MTApp.ContactServices.Affiliates.Create(item);
                        responseB.Content = item.ToDto();
                        id = item.Id;                       
                    }
                    else
                    {
                        responseB.Content = existing.ToDto();
                        id = existing.Id;
                    }
                }
                else
                {
                    MTApp.ContactServices.Affiliates.Update(item);
                    id = item.Id;
                    responseB.Content = item.ToDto();                    
                }
                data = MerchantTribe.Web.Json.ObjectToJson(responseB);  
            }
                      
            return data;
        }
Esempio n. 3
0
        private bool LogReferral(long affiliateId, string referrerUrl)
        {

            Contacts.Affiliate aff = Affiliates.Find(affiliateId);
            if (aff == null) return false;
            if (!aff.Enabled) return false;

            AffiliateReferral r = new AffiliateReferral();
            r.AffiliateId = aff.Id;
            r.ReferrerUrl = referrerUrl;
            return AffiliateReferrals.Create(r);                        
        }