So I'm trying to create discount coupons for a Kentico 7 site, and I'm not sure if I'm completely misunderstanding how the DiscountCouponInfoProvider works, or if I'm barking up the wrong tree entirely.
The code I'm currently using is:
var newCoupon = new DiscountCouponInfo {
//Fill in data fields here
};
DiscountCouponInfoProvider.SetDiscountCouponInfo(newCoupon);
This doesn't throw an error, but the coupon never shows up in the database. A few lines down I use
var result = DiscountCouponInfoProvider.GetDiscountCouponinfo();
passing in the same ID I used when creating the coupon, and it stores all of the correct information in result.
I noticed that there is an insert method for the DiscountCouponInfo class
newCoupon.Insert();
which may be closer to what I'm looking for, but haven't tried yet.
Any help would be appreciated. Or a link to the Kentico 7 api reference. Every time I go looking for it I keep finding the Kentico 8.1 api reference.
Thanks.
You can create coupons within the Kentico UI by going to CMS Desk > Ecommerce > Discount Coupons. However, if you are needing to create them outside the UI for some reason, then you were pretty close. You will want to use an Info object along with the InfoProvider object, like this:
// Instantiate an info object
DiscountCouponInfo dci = new DiscountCouponInfo();
// Set your properties
dci.DiscountCouponDisplayName = "Some text";
dci.DiscountCouponValue = 10;
//Update the DB with an InfoProvider object
DiscountCouponInfoProvider.SetDiscountCouponInfo(dci);
The Info object is just a simple data container that you can instantiate, populate with data, then pass it as an argument to an InfoProvider object.
The InfoProvider then has methods for update/creating records, etc.
You could also populate an Info object with data from the Kentico DB like this:
DiscountCouponInfo dci = new DiscountCouponInfoProvider.GetDiscountCouponInfo(DiscountCouponID);
I actually JUST wrote a blog post about this. Feel free to check it out or read Kentico's docs for more info.
Related
I'm at a loss with the KTA SDK. My intention is to pass a scanned document in PDF format with a few headers to KTA's jobs queue. As I'm still going through the documentation, my best guess right now is to use the Document class as a DTO then I need to call a method to pass that Document as a parameter:
...
[HttpPost]
public HttpResponseMessage Upload()
{
var httpRequest = System.Web.HttpContext.Current.Request;
var DocType = httpRequest.Headers["X-DocType"];
var Pages = httpRequest.Headers["X-DocPages"];
var Title = httpRequest.Headers["X-DocTitle"];
Agility.Sdk.Model.Capture.Document doc = new Agility.Sdk.Model.Capture.Document();
// doc.DocumentType = DocType; // Type DocumentTypeSummary
doc.NumberOfPages = Convert.ToInt32(Pages);
doc.FileName = Title;
...
I'm just wondering if I'm on the right track in doing this?
My other question is where can we store data from a custom header? In this example, I need to store custom header called Comments and AccountNumber.
Lastly, what service needs to be called to send this document to KTA jobs queue? Would CaptureDocumentService be the right one?
I'd greatly appreciate any help on this.
Start with the details laid out in the Sample App example. It shows what to add to your app.config, but what it doesn’t call out explicitly enough is that you should change the SdkServicesLocation value for your environment. You will simply call the functions in the services within the TotalAgility.Sdk namespaces and it will handle the webservice calls.
The CaptureDocumentService might be part of what you need, and there is a set of samples dedicated to the functions on that service. It refers to the Sample Processes folder, which by default is here:
C:\Program Files\Kofax\TotalAgility\Sample Processes\Capture SDK Sample Package
However what you will definitely need are the functions on the JobService. There are different functions with different options, but CreateJobWithDocuments is probably what you want to start with. You can see that this is creating document(s) and a job together in one step.
There is similarity with the parameters on CaptureDocumentService.CreateDocument3, so you might cross-reference with that to best understand the parameters. The difference is that CreateDocument3 just creates a document in the abstract: you want to actually use it as an input to create a job, so use the combined function.
Finally, to pass fields in, you will be setting RuntimeField objects as part of the RuntimeDocument objects going into your CreateJobWithDocuments call.
Stripe Transfer JSON
I'm trying to get all charge IDs associated with a transfer.
var json = new StreamReader(context.Request.InputStream).ReadToEnd();
var stripeEvent = StripeEventUtility.ParseEvent(json);
StripeTransfer stripeTransfer;
switch (stripeEvent.Type)
{
case "transfer.created":
stripeTransfer = Stripe.Mapper<StripeTransfer>.MapFromJson(stripeEvent.Data.Object.ToString());
var transferId = stripeTransfer.Id;
stripeTransfer = _stripeManager.GetTransfer(transferId);
foreach (var charge in stripeEvent.Data.Object["transactions"])
{
}
_stripeManager.ProcessTransfer(stripeTransfer);
break;
In visual studio's immediate window, stripeEvent.Data.Object["transactions"] shows the data I want so I know that the json is getting sucked in properly. Those transactions are a collection of charges, they match my .net StripeCharge object. I'm having trouble figuring out how to iterate through the transactions...all I really need is the ID for each. Would like to see "transactions" as a C# IEnumerable object.
(the json in question is linked at the top of this post) let me know if more info is needed.
I've found the specific item is under ["transactions"]["data"][0]["id"] but there may be more than one so, still working on how to get them out and cast them...think I'm close but it seems like there should be a more elegant way of doing it.
EDIT,
Thanks Andrew, so even though I have all of the charge data, it is incoming data. So what I'll be doing is using the event to just get the id and then make the call to get the charge object from my own end to prevent any event spoofs. So that means I don't have to worry about casting at this point. Here is my solution, feel free to advise if there is a better way to do it
for (int i = 0; i < Int32.Parse(stripeEvent.Data.Object["transactions"]["total_count"].ToString()); i++)
{
string chargeId = stripeEvent.Data.Object["transactions"]["data"][i]["id"].ToString();
// do stuff with it
}
just for completeness:
Data under transactions looks like an array so should be able to index into them..
If you need to access to any other fields in the future you could construct c# objects but given the webhook 3rd party dance you are already doing probably not worth it as you only need id.
I'm searching for a way to access the calendar and email inbox of another user (I can access my own calendar/email without any problems). Currently I can access the other inbox/calendar via lotus notes (I have enough rights). But I couldn't manage it to access the data programmatically.
I already listed all my views, but there was nothing appropriated.
private Domino.NotesDatabase db;
Object[] docColl = this.db.Views as Object[];
foreach (Object objView in docColl)
{
NotesView view = objView as NotesView;
this.WriteToLog(view.Name);
}
Any ideas, if this is possible and how?
Every Notes user's mail box is in a separate database.
So, first you have to get the database with
Domino.NotesDatabase db =
session.GetDatabase("yourServer", "UserMail.nsf", false);
and there you can access the calendar and email folders.
#Knut's answer gives you the basic information that you need, but I'd like to clarify it a bit: it has to be the hisServer (or herServer), not yourServer. Also, it will usually be "mail\hisShortname.nsf"), but that's not always the case. The point is that if you are trying to write generalized code, you have to look these things up in the Domino Directory.
If you're using a recent version of the Notes APIs, the best way to proceed is by using session.getDirectory(myServer) to get a NotesDirectory object. (It doesn't matter what server you use in this case, as long as the users are in the same Notes domain.) Here's the doc for the getDirectory method.
Once you have a handle to the Domino Directory, you need to look up information for the Person whose mail file you want to access. The formal documentation for the NotesDirectory class seems to be frustratingly hard to find online every time I search for it, so I can't link to that. The second example in the first section of this wiki page shows a call to the LookupNames method to retrieve information for a Person object, which is what you need to do. The two items that you want to retrieve are "MailServer" and "MailFile".
I am updating an entity in a form, for simplicity, lets call it CompanyCar. My objective is to check and see if its assigned owner has changed, and if so, send an email to the old and new owner.
public Car SaveExistingCar(Car car)
{
var original = _CarRepository.LoadCarById(Car.Id);
var carReturn = _CarRepository.SaveOrUpdateCar(Car) //Error here
//pseudo: if carReturn.Owner != original.Owner
// Send Email
return carReturn;
}
Unfortunately it gets mighty angry about this.
a different object with the same identifier value was already associated with the session
I can understand whats making that happen... sure, okay its confused about the real object. However, that doesn't do much to help me solve it. Is there something I can do to tell it that the 'original' is bogus?
ISession.Evict will remove the original car from the session and 1st level cache and you should be able to save the new car.
Some background: I'm writing a custom workflow activity for CRM 2011 in C# and I am using early bound classes generated by CrmSvcUtil.exe. My plugin takes an opportunity as its only input and is supposed to check its related activities, then set a field on the opportunity to denote whether the opportunity needs more follow-up. My problem currently is that whenever I attempt to retrieve the related activities, the result is null. Here's the relevant part of my code:
Opportunity currentOpportunity = (Opportunity) service.Retrieve(context.PrimaryEntityName, context.PrimaryEntityId, new ColumnSet(true));
currentOpportunity.Opportunity_ActivityPointers
I was under the impression that since there is a one-to-many relationship between Opportunity and Activity that this would grab all the relevant activities, but it doesn't seem to be doing that.
I'm still new to CRM and C#, so any insight as to what I'm doing wrong is appreciated!
if you are using early bound classes, first create data context (in my case it is XrmServiceContext). You can retrieve all ActivityPointers where Regarding object is your opportunity.
OrganizationServiceProxy orgserv;
using(var xrm = new XrmServiceContext(orgserv))
{
//Opportunity currentOpportunity = ...
IQueryable<ActivityPointer> activityPointers = xrm.ActivityPointerSet.Where(a =>
a.RegardingObjectId == currentOpportunity.ToEntityReference());
}
ActivityPointer contains ActivityId and ActivityTypeCode if you need some specific activity from this set. More details here.
Hope it helps :)