I am trying this code for creating new campaign using MailChimp API in ASP.NET
public string CreateCampaignAndSend(string apiKey, string listID)
{
Int32 TemplateID = 100;
string campaignID = string.Empty;
MailChimpManager mc = new MailChimpManager("sampleAPIKeyXXXXXXXXXXXXXX-us12");
// compaign Create Options
campaignCreateOptions campaignCreateOpt = new campaignCreateOptions();
campaignCreateOpt.list_id = listID;
campaignCreateOpt.subject = "subject";
campaignCreateOpt.from_email = "wisdomthnkrs#gmail.com";
campaignCreateOpt.from_name = "abc";
campaignCreateOpt.template_id = TemplateID;
campaignCreateOpt.authenticate = true;
campaignCreateOpt.auto_footer = false;
campaignCreateOpt.tracking.opens = true;
campaignCreateOpt.tracking.html_clicks = true;
campaignCreateOpt.tracking.text_clicks = true;
// Content
Dictionary<string, string> content = new Dictionary<string, string>();
content.Add("html_ArticleTitle1", "ArticleTitle1");
content.Add("html_ArticleTitle2", "ArticleTitle2");
content.Add("html_ArticleTitle3", "ArticleTitle3");
content.Add("html_Article1", "Article1");
content.Add("html_Article2", "Article2");
//Conditions
List<campaignSegmentCondition> csCondition = new List<campaignSegmentCondition>();
campaignSegmentCondition csC = new campaignSegmentCondition();
csC.field = "interests-" + 123; // where 123 is the Grouping Id from listInterestGroupings()
csC.op = "all";
csC.value = "";
csCondition.Add(csC);
// Options
campaignSegmentOptions csOptions = new campaignSegmentOptions();
csOptions.match = "all";
// Type Options
Dictionary<string, string> typeOptions = new Dictionary<string, string>();
typeOptions.Add("offset-units", "days");
typeOptions.Add("offset-time", "0");
typeOptions.Add("offset-dir", "after");
// Create Campaigns
campaignCreateParms campaignCreateParms = new campaignCreateParms(mc.APIKey, EnumValues.campaign_type.regular, campaignCreateOpt, content, csOptions, typeOptions);
campaignCreateInput campCreateInput = new campaignCreateInput(campaignCreateParms);
campaignCreate campaignCreate = new campaignCreate(campCreateInput);
//xyz();
//string abc = xxxxxxxxxxxxxxxxx;
campaignCreateOutput ccOutput = campaignCreate.Execute(campCreateInput);
List<Api_Error> error = ccOutput.api_ErrorMessages; // Catching API Errors
string s = "null";
if (error.Count <= 0)
{
campaignID = ccOutput.result;
}
else
{
foreach (Api_Error ae in error)
{
Console.WriteLine("\n ERROR Creating Campaign : ERRORCODE\t:" + ae.code + "\t ERROR\t:" + ae.error);
s = s + ae.code;
s = s + ae.error;
}
}
return s;
}
but it shows an error while I am giving the right key.
here is the error,
null104Invalid MailChimp "Invalid MailChimp API key:
6ea29f158xxxxxxxxxxxx"
Related
I have some data in activity which I want to get it in RoutingSlipCompleted consume method. I know we can send data with CompletedWithVariables from a activity to b activity. But I was wondering how it is possible to get data from activity in RoutingSlipCompleted. so this is my activity:
public class CheckInventoryActivity : IActivity<ICheckInventoryRequest, CheckInventoryRequestCompensate>
{
private readonly IInventoryService _inventoryService;
private readonly IEndpointNameFormatter _formatter;
public CheckInventoryActivity(IInventoryService inventoryService, IEndpointNameFormatter formatter)
{
_inventoryService = inventoryService;
_formatter = formatter;
}
public async Task<ExecutionResult> Execute(ExecuteContext<ICheckInventoryRequest> context)
{
CheckInventoryRequest model = new CheckInventoryRequest()
{
PartCode = context.Arguments.PartCode
};
var response = await _inventoryService.CheckInventory(model);
var checkInventoryResponse = new CheckInventoryResponse()
{
PartCode = response.Data.PartCode ?? model.PartCode,
Id = response.Data.Id ?? 0,
InventoryCount = response.Data.InventoryCount ?? 0
};
var checkInventoryCustomActionResult = new CustomActionResult<CheckInventoryResponse>()
{
Data = checkInventoryResponse,
IsSuccess = true,
ResponseDesc = "success",
ResponseType = 0
};
var result = response.IsSuccess;
if (!result)
return context.CompletedWithVariables<CheckInventoryRequestCompensate>(
new
{
Result = result,
LogDate = DateTime.Now,
MethodName = "CheckInventoryActivity",
}, new
{
Result = result,
LogDate = DateTime.Now,
MethodName = "CheckInventoryActivity",
CheckInventoryCustomActionResult = checkInventoryCustomActionResult
});
var queueName = _formatter.ExecuteActivity<CallSuccessActivity, ISuccessRequest>();
var uri = new Uri($"queue:{queueName}");
return context.ReviseItinerary(x => x.AddActivity("CallSuccessActivity", uri, new
{
LogDate = DateTime.Now,
MethodName = "CheckInventoryActivity",
CheckInventoryCustomActionResult = checkInventoryCustomActionResult
}));
}
so by the following line of codes I can get data in CallSuccessActivity:
return context.ReviseItinerary(x => x.AddActivity("CallSuccessActivity", uri, new
{
LogDate = DateTime.Now,
MethodName = "CheckInventoryActivity",
CheckInventoryCustomActionResult = checkInventoryCustomActionResult
}));
}
so I can get this data here:
public class CallSuccessActivity : IExecuteActivity<ISuccessRequest>
{
private readonly IRequestClient<ISuccessRequest> _requestClient;
public CallSuccessActivity(IRequestClient<ISuccessRequest> requestClient)
{
_requestClient = requestClient;
}
public async Task<ExecutionResult> Execute(ExecuteContext<ISuccessRequest> context)
{
var iModel = context.Arguments;
var model = new SuccessRequest()
{
LogDate = iModel.LogDate,
MethodName = iModel.MethodName,
CheckInventoryCustomActionResult = iModel.CheckInventoryCustomActionResult
};
//CustomActionResult< CheckInventoryResponse > CheckInventoryResponse = new ();
var rabbitResult = await _requestClient.GetResponse<CustomActionResult<SuccessResponse>>(model);
return context.Completed();
}
}
I want to get this iModel.CheckInventoryCustomActionResult in RoutingSlipCompleted :
public async Task Consume(ConsumeContext<RoutingSlipCompleted> context)
{
var requestId =
context.Message.GetVariable<Guid?>(nameof(ConsumeContext.RequestId));
var checkInventoryResponseModel = context.Message.Variables["CheckInventoryResponse"];
var responseAddress =
context.Message.GetVariable<Uri>(nameof(ConsumeContext.ResponseAddress));
var request =
context.Message.GetVariable< ICheckInventoryRequest > ("Model");
throw new NotImplementedException();
}
Instead of putting the value into the activity arguments, add it as a variable:
return context.ReviseItinerary(x =>
{
x.AddActivity("CallSuccessActivity", uri, new
{
LogDate = DateTime.Now,
MethodName = "CheckInventoryActivity"
});
x.AddVariable("CheckInventoryCustomActionResult", checkInventoryCustomActionResult);
});
How Can I call the Request Get (Api) from server side.
Here is the Server side
public string GetAllBook()
{
bookAssembly bookassembleur = new bookAssembly();
bookList = bookassembleur.GetBooks();
}
And here is the Api Request
public List<Book> Get()
{
BookAssembly searchallbook = new BookAssembly();
return searchallbook.GetBooks();
bookAssembly bookassembleur = new bookAssembly();
bookList = bookassembleur.GetBooks();
DataTable dt = new DataTable();
if (dt.Columns.Count == 0)
{
dt.Columns.Add("ID");
dt.Columns.Add("Title");
dt.Columns.Add("Price");
dt.Columns.Add("Author");
dt.Columns.Add("Qauntite");
dt.Columns.Add("Categorie");
}
foreach (Book book in bookList)
{
DataRow NewRow = dt.NewRow();
NewRow[0] = book.ID;
NewRow[1] = book.Title;
NewRow[2] = book.Price;
NewRow[3] = book.Author;
NewRow[4] = book.Qauntite;
NewRow[5] = book.Categorie.Name;
dt.Rows.Add(NewRow);
}
gvBook.DataSource = dt;
gvBook.DataBind();
return "";
}
i want remove bookList = bookassembleur.GetBooks() ana call api
You have to access it using HttpClient.
e.g.
using (var client = new HttpClient())
{
client.BaseAddress = new Uri("<your_api_path>");
var response= client.GetAsync("GetAllBook");
response.Wait();
BookAssembly searchallbook = response.Result;
}
P.S. this is not running code, just an idea.
public string GetAllBook()
{
DataTable dt = new DataTable();
using (var client = new HttpClient())
{
client.BaseAddress = new Uri("http://localhost:6735/api/book");
//HTTP GET
var responseTask = client.GetAsync("Book");
responseTask.Wait();
var result = responseTask.Result;
if (result.IsSuccessStatusCode)
{
var readTask = result.Content.ReadAsAsync<Book[]>();
readTask.Wait();
var Books = readTask.Result;
if (dt.Columns.Count == 0)
{
dt.Columns.Add("ID");
dt.Columns.Add("Title");
dt.Columns.Add("Price");
dt.Columns.Add("Author");
dt.Columns.Add("Qauntite");
dt.Columns.Add("Categorie");
}
foreach (Book book in Books)
{
DataRow NewRow = dt.NewRow();
NewRow[0] = book.ID;
NewRow[1] = book.Title;
NewRow[2] = book.Price;
NewRow[3] = book.Author;
NewRow[4] = book.Qauntite;
NewRow[5] = book.Categorie.Name;
dt.Rows.Add(NewRow);
}
}
}
gvBook.DataSource = dt;
gvBook.DataBind();
return "";
}
Hi there i would like to let customers type a category name and get some search results. Currently when you type a category name it says no results.
public ActionResult AdvanceSearch(SearchModel model, CatalogPagingFilteringModel command)
{
//'Continue shopping' URL
_genericAttributeService.SaveAttribute(_workContext.CurrentCustomer,
SystemCustomerAttributeNames.LastContinueShoppingPage,
_webHelper.GetThisPageUrl(false),
_storeContext.CurrentStore.Id);
if (model == null)
model = new SearchModel();
var searchTerms = model.q;
if (searchTerms == null)
searchTerms = "";
searchTerms = searchTerms.Trim();
//sorting
PrepareSortingOptions(model.PagingFilteringContext, command);
//view mode
PrepareViewModes(model.PagingFilteringContext, command);
//page size
PreparePageSizeOptions(model.PagingFilteringContext, command,
_catalogSettings.SearchPageAllowCustomersToSelectPageSize,
_catalogSettings.SearchPagePageSizeOptions,
_catalogSettings.SearchPageProductsPerPage);
string cacheKey = string.Format(ModelCacheEventConsumer.SEARCH_CATEGORIES_MODEL_KEY,
_workContext.WorkingLanguage.Id,
string.Join(",", _workContext.CurrentCustomer.GetCustomerRoleIds()),
_storeContext.CurrentStore.Id);
var categories = _cacheManager.Get(cacheKey, () =>
{
var categoriesModel = new List<SearchModel.CategoryModel>();
//all categories
var allCategories = _categoryService.GetAllCategories(storeId: _storeContext.CurrentStore.Id);
foreach (var c in allCategories)
{
//generate full category name (breadcrumb)
string categoryBreadcrumb = "";
var breadcrumb = c.GetCategoryBreadCrumb(allCategories, _aclService, _storeMappingService);
for (int i = 0; i <= breadcrumb.Count - 1; i++)
{
categoryBreadcrumb += breadcrumb[i].GetLocalized(x => x.Name);
if (i != breadcrumb.Count - 1)
categoryBreadcrumb += " >> ";
}
categoriesModel.Add(new SearchModel.CategoryModel
{
Id = c.Id,
Breadcrumb = categoryBreadcrumb
});
}
return categoriesModel;
});
if (categories.Any())
{
//first empty entry
model.AvailableCategories.Add(new SelectListItem
{
Value = "0",
Text = _localizationService.GetResource("Common.All")
});
//all other categories
foreach (var c in categories)
{
model.AvailableCategories.Add(new SelectListItem
{
Value = c.Id.ToString(),
Text = c.Breadcrumb,
Selected = model.cid == c.Id
});
}
}
IPagedList<Product> products = new PagedList<Product>(new List<Product>(), 0, 1);
// only search if query string search keyword is set (used to avoid searching or displaying search term min length error message on /search page load)
if (Request.Params["q"] != null)
{
if (searchTerms.Length < _catalogSettings.ProductSearchTermMinimumLength)
{
model.Warning = string.Format(_localizationService.GetResource("Search.SearchTermMinimumLengthIsNCharacters"), _catalogSettings.ProductSearchTermMinimumLength);
}
else
{
var categoryIds = new List<int>();
int manufacturerId = 0;
decimal? minPriceConverted = null;
decimal? maxPriceConverted = null;
bool searchInDescriptions = false;
int vendorId = 0;
if (model.adv)
{
//advanced search
var categoryId = model.cid;
if (categoryId > 0)
{
categoryIds.Add(categoryId);
if (model.isc)
{
//include subcategories
categoryIds.AddRange(GetChildCategoryIds(categoryId));
}
}
manufacturerId = model.mid;
//min price
if (!string.IsNullOrEmpty(model.pf))
{
decimal minPrice;
if (decimal.TryParse(model.pf, out minPrice))
minPriceConverted = _currencyService.ConvertToPrimaryStoreCurrency(minPrice, _workContext.WorkingCurrency);
}
//max price
if (!string.IsNullOrEmpty(model.pt))
{
decimal maxPrice;
if (decimal.TryParse(model.pt, out maxPrice))
maxPriceConverted = _currencyService.ConvertToPrimaryStoreCurrency(maxPrice, _workContext.WorkingCurrency);
}
if (model.asv)
vendorId = model.vid;
searchInDescriptions = model.sid;
}
//var searchInProductTags = false;
var searchInProductTags = searchInDescriptions;
//products
products = _productService.SearchProducts(
categoryIds: categoryIds,
manufacturerId: manufacturerId,
storeId: _storeContext.CurrentStore.Id,
visibleIndividuallyOnly: true,
priceMin: minPriceConverted,
priceMax: maxPriceConverted,
keywords: searchTerms,
//searchDescriptions: searchInDescriptions,
searchProductTags: searchInProductTags,
searchSku: true,
languageId: _workContext.WorkingLanguage.Id,
orderBy: (ProductSortingEnum)command.OrderBy,
pageIndex: command.PageNumber - 1,
pageSize: command.PageSize,
vendorId: vendorId);
model.Products = PrepareProductOverviewModels(products).ToList();
model.NoResults = !model.Products.Any();
//search term statistics
if (!String.IsNullOrEmpty(searchTerms))
{
var searchTerm = _searchTermService.GetSearchTermByKeyword(searchTerms, _storeContext.CurrentStore.Id);
if (searchTerm != null)
{
searchTerm.Count++;
_searchTermService.UpdateSearchTerm(searchTerm);
}
else
{
searchTerm = new SearchTerm
{
Keyword = searchTerms,
StoreId = _storeContext.CurrentStore.Id,
Count = 1
};
_searchTermService.InsertSearchTerm(searchTerm);
}
}
//event
_eventPublisher.Publish(new ProductSearchEvent
{
SearchTerm = searchTerms,
SearchInDescriptions = searchInDescriptions,
CategoryIds = categoryIds,
ManufacturerId = manufacturerId,
WorkingLanguageId = _workContext.WorkingLanguage.Id,
VendorId = vendorId
});
}
}
model.PagingFilteringContext.LoadPagedList(products);
return View(model);
}
A public action method 'AdvanceSearch' was not found on controller 'Nop.Web.Controllers.CatalogController'.
my sample project at registered at developer.facebook version 2.4 and requested permissions are *
email,birthday,gender
*
default.aspx
string code = Request.QueryString["code"];
if (!string.IsNullOrEmpty(code))
{
// dynamic info = fb.Get("me?birthday");
string data = FaceBookConnect.Fetch(code, "me");
FaceBookUser faceBookUser = new JavaScriptSerializer().Deserialize<FaceBookUser>(data);
faceBookUser.PictureUrl = string.Format("https://graph.facebook.com/{0}/picture", faceBookUser.Id);
pnlFaceBookUser.Visible = true;
lblId.Text = faceBookUser.Id;
lblUserName.Text = faceBookUser.UserName;
lblName.Text = faceBookUser.Name;
lblEmail.Text = faceBookUser.Email;
lblbirthday.Text = faceBookUser.birthday;
lblf_name.Text =faceBookUser.first_name;
lblgender.Text = faceBookUser.gender;
ProfileImage.ImageUrl = faceBookUser.PictureUrl;
btnLogin.Enabled = false;
}
Here is my struct definition, function and the portion calling the function.
public struct NewSigningRequest
{
public string SerialNumber;
//public string Requestor;
public string Sponsor;
public string Approver;
public string BusinessJustification;
public byte[] DebugFile;
public string DebugFileName;
public string FirmwareVersion;
public string FirmwareDescription;
public byte[] SmokeTestResult;
public string ProductName;
public string SigningType;
}
static public bool CreateSigningRequest(NewSigningRequest Request)
{
Request = new NewSigningRequest();
bool succeeded = false;
string sqlcmdString = sqlQueryNewSigningRequest;
SqlConnection con = new SqlConnection(connection);
SqlCommand Insertcmd = new SqlCommand(sqlcmdString, con);
SqlParameter SerialNumber = new SqlParameter("#SerialNumber", SqlDbType.NVarChar, 50);
SerialNumber.Value = Request.SerialNumber;
Insertcmd.Parameters.Add(SerialNumber);
SqlParameter Requestor = new SqlParameter("#Requestor", SqlDbType.NVarChar, 20);
Requestor.Value = GetRequestor.GetRequestorAlias();
Insertcmd.Parameters.Add(Requestor);
SqlParameter Sponsor = new SqlParameter("#Sponsor", SqlDbType.NVarChar, 20);
Sponsor.Value = Request.Sponsor;
Insertcmd.Parameters.Add(Sponsor);
SqlParameter BusinessJustification = new SqlParameter("#BusinessJustification", SqlDbType.NVarChar, 2000);
BusinessJustification.Value = Request.BusinessJustification;
Insertcmd.Parameters.Add(BusinessJustification);
SqlParameter DebugFile = new SqlParameter("#DebugFile", SqlDbType.VarBinary, 8000);
DebugFile.Value = Request.DebugFile;
Insertcmd.Parameters.Add(DebugFile);
SqlParameter DebugFileName = new SqlParameter("#DebugFileName", SqlDbType.NVarChar, 100);
DebugFileName.Value = Request.DebugFileName;
Insertcmd.Parameters.Add(DebugFileName);
SqlParameter ProductName = new SqlParameter("#ProductName", SqlDbType.NVarChar, 20);
ProductName.Value = Request.ProductName;
Insertcmd.Parameters.Add(ProductName);
SqlParameter SigningType = new SqlParameter("#SigningType", SqlDbType.NVarChar, 10);
SigningType.Value = Request.SigningType;
Insertcmd.Parameters.Add(SigningType);
SqlParameter FirmwareVersion = new SqlParameter("#FirmwareVersion", SqlDbType.NVarChar, 50);
FirmwareVersion.Value = Request.FirmwareVersion;
Insertcmd.Parameters.Add(FirmwareVersion);
SqlParameter FirmwareDescription = new SqlParameter("#FirmwareDescription", SqlDbType.NVarChar, 250);
FirmwareDescription.Value = Request.FirmwareDescription;
Insertcmd.Parameters.Add(FirmwareDescription);
SqlParameter SmokeTestResult = new SqlParameter("#SmokeTestResult", SqlDbType.VarBinary, 8000);
SmokeTestResult.Value = Request.SmokeTestResult;
Insertcmd.Parameters.Add(SmokeTestResult);
return succeeded;
}
this is how I am trying to call it
NewSigningRequest Request;
byte[] bin;
string FileName;
if (FileUpload.HasFile)
{
bin = new byte[FileUpload.PostedFile.ContentLength];
HttpPostedFile mybin = FileUpload.PostedFile;
FileName = mybin.FileName;
mybin.InputStream.Read(bin, 0, FileUpload.PostedFile.ContentLength);
}
else
{
bin = null;
FileName = "";
}
string NameAlias = #HttpContext.Current.User.Identity.Name;
int index = NameAlias.IndexOf("\\") + 1;
string sAlias = NameAlias.Substring(index);
byte[] SmokeTest;
if (FileUploadSTR.HasFile)
{
SmokeTest = new byte[FileUploadSTR.PostedFile.ContentLength];
HttpPostedFile mySmokeTest = FileUploadSTR.PostedFile;
mySmokeTest.InputStream.Read(SmokeTest, 0, FileUploadSTR.PostedFile.ContentLength);
}
else
{
SmokeTest = null;
}
Request.SerialNumber = TextBoxSerialNumber.Text;
Request.Sponsor = TextBoxSponsor.Text;
Request.BusinessJustification = TextBoxBJ.Text;
if (bin == null)
{
Request.DebugFile = new byte[0];
}
else
{
Request.DebugFile = bin;
}
Request.DebugFileName = FileName;
Request.FirmwareVersion = TextBoxFV.Text;
Request.FirmwareDescription = TextBoxFD.Text;
if (TextBoxSigningType.Text == string.Empty)
{
Request.SigningType = drp2.SelectedValue.ToString();
}
else
{
Request.SigningType = TextBoxSigningType.Text.ToUpper();
}
if (SmokeTest == null)
{
Request.SmokeTestResult = new byte[0];
}
else
{
Request.SmokeTestResult = SmokeTest;
}
SurfaceSignDBAccess.CreateSigningRequest(Request);
upon calling this function, gives error saying that "use of unassigned local variable 'Request'."
What should be the right way to call this function?
NewSigningRequest Request; - is never initialized in the method, before calling
SurfaceSignDBAccess.CreateSigningRequest(Request);
try this:
var request = new NewSigningRequest();// in the first line of code of the second code snippet.
And in the static method, remove the following code.
Request = new NewSigningRequest();