private void RenderSingleItem(StringBuilder sb, Affiliate a) { string destinationLink = "Affiliates_edit.aspx?id=" + a.Id + "&page=" + currentPage + "&keyword=" + System.Web.HttpUtility.UrlEncode(keyword); string deleteLink = destinationLink.Replace("_edit", "_delete"); sb.Append("<tr><td><a href=\"" + destinationLink + "\">" + a.DisplayName + "</a></td>"); sb.Append("<td><a href=\"" + destinationLink + "\">" + a.ReferralId + "</a></td>"); sb.Append("<td><a href=\"" + destinationLink + "\">" + (a.Enabled ? "YES":"NO") + "</a></td>"); sb.Append("<td><a onclick=\"return window.confirm('Delete this item?');\" href=\"" + deleteLink + "\" class=\"btn\"><b>Delete</b></a></td>"); sb.Append("<td><a href=\"" + destinationLink + "\" class=\"btn\"><b>Edit</b></a></td></tr>"); }
// 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; }
private bool Save() { bool result = false; Affiliate a = null; if (CurrentId < 1) { a = new Affiliate(); } else { a = MTApp.ContactServices.Affiliates.Find(CurrentId); } a.Enabled = this.chkEnabled.Checked; a.DisplayName = this.DisplayNameField.Text.Trim(); a.ReferralId = this.ReferralIdField.Text.Trim(); int typeSelection = int.Parse(this.lstCommissionType.SelectedValue); a.CommissionType = (AffiliateCommissionType)typeSelection; a.CommissionAmount = decimal.Parse(this.CommissionAmountField.Text, System.Globalization.NumberStyles.Currency); a.ReferralDays = int.Parse(this.ReferralDaysField.Text); a.TaxId = this.TaxIdField.Text.Trim(); a.DriversLicenseNumber = this.DriversLicenseField.Text.Trim(); a.WebSiteUrl = this.WebsiteUrlField.Text.Trim(); a.Address = this.AddressEditor1.GetAsAddress(); a.Notes = this.NotesTextBox.Text; if (CurrentId < 1) { result = MTApp.ContactServices.Affiliates.Create(a); if (result) { CurrentId = a.Id; } } else { result = MTApp.ContactServices.Affiliates.Update(a); } if (result == false) { this.lblError.Text = "Unable to save affiliate. Uknown error."; } return result; }