Value cannot be null. Parameter name: key (Xero api .NET lib) - xero-api

I am getting the error "Value cannot be null. Parameter name: key" at the line xapi.Items.Create(item1) , while creating an inventory item using Github Xero c# lib. What could be wrong?
Here is the c# code:
string xeroAPIUrl = "https://api.xero.com";
PrivateAuthenticator pAuth = new PrivateAuthenticator(#"..\publickey.cer");
Consumer consumer = new Consumer("............", ".................");
XeroCoreApi xapi = new XeroCoreApi(xeroAPIUrl, pAuth, consumer, null, new DefaultMapper(), new DefaultMapper());
Item item1 = new Item();
item1.Id = Guid.NewGuid();
item1.Code = "BTC";
item1.Name = "BITCOIN";
item1.Description = "Bitcoin Entry";
item1.PurchaseDescription = "Bitcoin Purchase";
item1.PurchaseDetails = new PurchaseDetails() { UnitPrice = 100.00m,
AccountCode = "200" };
item1.SalesDetails = new SalesDetails() { UnitPrice = 110.00m, AccountCode = "300" };
item1 = xapi.Items.Create(item1);
Regards,
Murali

Related

How to Increase performance of API call

I am using 5 Hotels APIs and trying to combine and pick min price hotel with unique hotels from all APIs. I am following these STEPS
Call All 5 APIsand wait for response.
get all static data from database or if avail my server caching(all 5 APIs like hotels name, images, desc, etc)
Combine into one custom class
get GIATA map codes from caching or database.
Apply GIATA into API result and group all hotels with unique GIATA id.
Pick min price .
Bind UI and show to customer.
string sessionid = sqf;
DS.Models.BL.Common.HotelSearchDetails details = new DS.Models.BL.Common.HotelSearchDetails();
details = (.Models.BL.Common.HotelSearchDetails)Session["Details_" + sessionid];
List<DS.BL.Common.HotelDetails> DOTWhdlist = new List<DS.BL.Common.HotelDetails>();
List<DS.BL.Common.HotelDetails> GTAhdlist = new List<DS.BL.Common.HotelDetails>();
List<DS.BL.Common.HotelDetails> HPhdlist = new List<DS.BL.Common.HotelDetails>();
List<DS.BL.Common.HotelDetails> HBhdlist = new List<DS.BL.Common.HotelDetails>();
List<DS.BL.Common.HotelDetails> TSGhdlist = new List<DS.BL.Common.HotelDetails>();
//GTA City Cache
DS.Models.BL.GTA_Model.Methods.HotelInfo hinfo = new Models.BL.GTA_Model.Methods.HotelInfo();
List<GTA.API.HotelSearch.GTAHotels> hlist = new List<GTA.API.HotelSearch.GTAHotels>();
hlist = hinfo.GethotellistCityWise(details.GTACityCode);
//
/*************************************************
* DOTW cache
*
*************************************************/
DS.BL.DOTW.Method.HotelInfo objhoteldetails = new DS.BL.DOTW.Method.HotelInfo();
Dictionary<string, int> dictionary = objhoteldetails.Gethotelratings();
List<DOTW.Method.searchhotels.DotwHotels> objhotellist = new List<DOTW.Method.searchhotels.DotwHotels>();
objhotellist = objhoteldetails.GethotellistCityWise(details.DOTWCityCode);
//-------------------------------------------------------------------------------------------------------
//------Hotel pro cache city
DS.BL.HotelsPro.Method.GetHotelDetails objhoteldetails_hp = new BL.HotelsPro.Method.GetHotelDetails();
List<HotelsPro.Method.Avail.HotelsProHotels> objhotellist_hp = new List<HotelsPro.Method.Avail.HotelsProHotels>();
objhotellist_hp = objhoteldetails_hp.GethotellistCityWise(details.HotelsProCityCode);
/***************************************************
* Hotelbeds city cache
*
*/
DS.Models.BL.HotelBeds.Methods.HotelInfoController objhotelbeds = new DS.Models.BL.HotelBeds.Methods.HotelInfoController();
List<HotelBeds.Method.SearchHotel.HotelBedsHotels> HBhotellist = new List<HotelBeds.Method.SearchHotel.HotelBedsHotels>();
HBhotellist = objhotelbeds.GethotellistCityWise(details.HBCityCode);
/**************************************************
*
* TSG city cache
*
*/
DS.Models.BL.TSG.Methods.HotelInfo objtsg_hotel = new Models.BL.TSG.Methods.HotelInfo();
List<TSG.API.HotelAvail.TSGHotels> TSGhlist = new List<TSG.API.HotelAvail.TSGHotels>();
TSGhlist = objtsg_hotel.GethotellistCityWise(details.City);
//---------------------------------------------------------------------------------------------------------------------
var dotw = Task<List<DS.BL.Common.HotelDetails>>.Factory.StartNew(() => Dotw(sqf, details, dictionary, objhotellist));
var gta = Task<List<DS.BL.Common.HotelDetails>>.Factory.StartNew(() => GTA(sqf, details, hlist));
var hotelpro = Task<List<DS.BL.Common.HotelDetails>>.Factory.StartNew(() => Hp(sqf, details, objhotellist_hp));
var hotelbeds = Task<List<DS.BL.Common.HotelDetails>>.Factory.StartNew(() => HB(sqf, details, HBhotellist));
var tsg = Task<List<DS.BL.Common.HotelDetails>>.Factory.StartNew(() => TSG(sqf, details, TSGhlist));
DOTWhdlist = dotw.Result;
TSGhdlist = tsg.Result;
GTAhdlist = gta.Result;
HPhdlist = hotelpro.Result;
HBhdlist = hotelbeds.Result;
ViewBag.sessionId = sessionid;
DOTWhdlist.AddRange(GTAhdlist);
DOTWhdlist.AddRange(HPhdlist);
DOTWhdlist.AddRange(HBhdlist);
DOTWhdlist.AddRange(TSGhdlist);
string[] c = details.CityName.Split(',');
string cityname = c[0];
List<DS.BL.Common.HotelDetails> filterdata = GiataApply(DOTWhdlist, cityname, details.GiataCityid);
List<DS.BL.Common.HotelDetails> tsgdata = filterdata.Where(x => x.giataref == "exclusivelyhotels").ToList();
List<DS.BL.Common.HotelDetails> gtadata = filterdata.Where(x => x.giataref == "gta").ToList();
List<DS.BL.Common.HotelDetails> dotwdata = filterdata.Where(x => x.giataref == "DOTW").ToList();
List<DS.BL.Common.HotelDetails> hpdata = filterdata.Where(x => x.giataref == "metglobal").ToList();
List<DS.BL.Common.HotelDetails> hbdata = filterdata.Where(x => x.giataref == "hotelbeds").ToList();
allSup.dotw = dotwdata;
GIATA APPLY
List<DS.BL.Common.HotelDetails> GiataApply(List<DS.BL.Common.HotelDetails> hlist, string city, int Cityid)
{
DS.Models.BL.Common.GIATA.giataCodes giataCodes = new Models.BL.Common.GIATA.giataCodes();
List<GiataProperty> gcode = new List<GiataProperty>();
gcode = giataCodes.GiataCodes(city, Cityid);
var query = from h in hlist
join g in gcode on new { hotelcode = h.HotelId, supcode = h.giataref }
equals new { hotelcode = g.Hcode, supcode = g.ProviderCode }
select new DS.BL.Common.HotelDetails
{
HotelName = h.HotelName,
HCode = h.HCode,
HotelId = h.HotelId,
Address = h.Address,
image = h.image,
location = h.location,
Currency = h.Currency,
searchId = h.searchId,
Price = h.Price,
rating = h.rating,
hoteldescription = h.hoteldescription,
Latitude = h.Latitude,
Longitude = h.Longitude,
imagelist = h.imagelist,
Source = h.Source,
giataref = h.giataref,
HFullResponse = h.HFullResponse,
AvailableRoomList = h.AvailableRoomList,
HotelRooms = h.HotelRooms,
facilities = h.facilities,
faDetails = h.faDetails,
giata = g.giataId.Value,
hotelservices = h.hotelservices,
gtaIDref = h.gtaIDref
};
var filter = from x in query
group x by x.giata into hotels
select new DS.BL.Common.HotelDetails
{
HotelName = hotels.FirstOrDefault().HotelName,
HCode = hotels.FirstOrDefault().HCode,
HotelId = hotels.FirstOrDefault().HotelId,
Address = hotels.FirstOrDefault().Address,
image = hotels.FirstOrDefault().image,
location = hotels.FirstOrDefault().location,
Currency = hotels.FirstOrDefault().Currency,
searchId = hotels.FirstOrDefault().searchId,
imagelist = hotels.FirstOrDefault().imagelist,
Price = hotels.Min(p => p.Price),
rating = hotels.FirstOrDefault().rating,
hoteldescription = hotels.FirstOrDefault().hoteldescription,
Latitude = hotels.FirstOrDefault().Latitude,
Longitude = hotels.FirstOrDefault().Longitude,
Source = hotels.FirstOrDefault().Source,
giataref = hotels.FirstOrDefault().giataref,
HFullResponse = hotels.FirstOrDefault().HFullResponse,
AvailableRoomList = hotels.FirstOrDefault().AvailableRoomList,
HotelRooms = hotels.FirstOrDefault().HotelRooms,
facilities = hotels.FirstOrDefault().facilities,
faDetails = hotels.FirstOrDefault().faDetails,
giata = hotels.FirstOrDefault().giata,
hotelservices = hotels.FirstOrDefault().hotelservices,
gtaIDref = hotels.FirstOrDefault().gtaIDref
};
return filter.ToList();
//return query.ToList();
}
No this process taking 30-45 sec . i want to reduce i dont know how i do but in API calling i need to reduce time and GIATA apply .
give me idea guys thanks
Find async version of your API calls and use them. That should solve your problem. If no async version is available then you will have to do it in your code of C#. I am not a C# expert so I cannot help you there.

Getting "Received unknown parameter: amounts" for bank Account "Verify" function for jaymedavis/stripe.net code.?

I am implementing WCF service to implement online Net banking using github jaymedavis/stripe.net code (https://github.com/jaymedavis/stripe.net#charges).
here is my code for creating customer, Bank Account and Bank Account service for verifying Bank account and Creating charges.
Code:
//1. Create Customer
var myCustomer = new StripeCustomerCreateOptions();
myCustomer.Email = "pork#email.com";
myCustomer.Description = "Johnny Tenderloin (pork#email.com)";
//myCustomer.SourceToken = *token*;
//myCustomer.PlanId = *planId*; // only if you have a plan
//myCustomer.TaxPercent = 20; // only if you are passing a plan, this tax percent will be added to the price.
//myCustomer.Coupon = *couponId*; // only if you have a coupon
//myCustomer.TrialEnd = DateTime.UtcNow.AddMonths(1); // when the customers trial ends (overrides the plan if applicable)
//myCustomer.Quantity = 1; // optional, defaults to 1
//2. Create Customer Service
var customerService = new StripeCustomerService(StripeApiKey);
StripeCustomer stripeCustomer = customerService.Create(myCustomer);
//3. Create bankAccount
var myBankAccount = new BankAccountCreateOptions
{
SourceBankAccount = new SourceBankAccount()
{
AccountNumber = "000123456789", //,
Country = "US",
Currency = "usd",
AccountHolderName = "Frank", //"Johnny Tenderloin",
AccountHolderType = BankAccountHolderType.Individual,
RoutingNumber = "110000000", //"021000021",
Metadata = new Dictionary<string, string>
{
{ "Name", "Ray Barone" },
{ "OftenSays", "Thatttttt's right" }
}
}
};
//4. Create bankAccount Service
var bankAccountService = new BankAccountService(StripeApiKey);
CustomerBankAccount bankAccount = bankAccountService.Create(stripeCustomer.Id, myBankAccount);
BankAccountVerifyOptions bankAccountVerifyOpt = new BankAccountVerifyOptions();
bankAccountVerifyOpt.AmountOne = 32;
bankAccountVerifyOpt.AmountTwo = 45;
//
//5. Verify bankAccount or service
bankAccount = bankAccountService.Verify(stripeCustomer.Id, bankAccount.Id, bankAccountVerifyOpt );
//6. Create Charge
var myChargeBank = new StripeChargeCreateOptions();
// amount = Returnamount.amount;
myChargeBank.Amount = int.Parse("250") * 100;
myChargeBank.Currency = "usd";
myChargeBank.CustomerId = stripeCustomer.Id;
myChargeBank.Capture = true;
StripeCharge stripeCharge = null;
stripeCharge = new StripeCharge();
var chargeService = new StripeChargeService(StripeApiKey);
stripeCharge = chargeService.Create(myChargeBank);
if (stripeCharge.Status.ToLower() == "succeeded" & stripeCharge.Paid == true) {
} else {
}
In this code, I am getting:
Stripe Exception for Verify method (bankAccountService.Verify(stripeCustomer.Id, bankAccount.Id, bankAccountVerifyOpt );)
Exception is Received unknown parameter: amounts.
on "https://github.com/jaymedavis/stripe.net#charges" implementation for 'Verify a bank account' is missing so Please help me to solve this problem so that bank account get verify successfully.
I had the same issue and I did 2 things:
1) On stripe.com, I went to my account API settings and updated them to use the lasted API.
2) I updated the Stripe.net Nuget package
After that everything worked perfectly.

Dhtmlx scheduler in mvc 4

I am using dhtmlx scheduler in my MVC project. My problem is i need to block the previous days in the scheduler. For example today is Monday means the previous day before monday should be blocked. Can anyone please help me?
Thanks in advance..
I added my code below.
public ActionResult CalendarView( int id , tblUser user )
{
string val = System.Configuration.ConfigurationManager.AppSettings["UserTypeId"];
int code = Convert.ToInt32(val);
Session["Butype"] = val;
var cal = (from s
in db.tblUsers
where s.UserTypeId == code && s.UserID == id
select new Appt
{
BusinessName = s.tblBusinessCategory.BusinessName,
StartTime = s.WorkingHour.StartTime
}).FirstOrDefault();
Session["BUName"] = cal.BusinessName.ToString();
var scheduler = new DHXScheduler(this);
scheduler.Skin = DHXScheduler.Skins.Flat;
scheduler.Data.Loader.PreventCache();
scheduler.EnableDynamicLoading(SchedulerDataLoader.DynamicalLoadingMode.Week);
scheduler.Extensions.Add(SchedulerExtensions.Extension.Recurring);
//scheduler.Extensions.Add(SchedulerExtensions.Extension.ActiveLinks);
//scheduler.Extensions.Add(SchedulerExtensions.Extension.Collision);
//scheduler.Extensions.Add(SchedulerExtensions.Extension.Limit);
scheduler.LoadData = true;
scheduler.EnableDataprocessor = true;
scheduler.Config.show_loading = true;
// scheduler.BeforeInit.Add("schedulerClient.init()");
Session["BUId"] = id;
var parameter = new SqlParameter[1];
parameter[0] = new SqlParameter { ParameterName = "UserId", Value = id };
List<Appt> cm = new List<Appt>();
using (SYTEntities context = new SYTEntities())
{
cm = context.Database.SqlQuery<Appt>("exec spHoliday #UserId", parameter).ToList();
}
int iyear = 2015;
int imonth = 8;
int iday = 09;
foreach (var cp in cm)
{
iyear = cp.HolidayDate.Year;
imonth = cp.HolidayDate.Month;
iday = cp.HolidayDate.Day;
scheduler.TimeSpans.Add(new DHXMarkTime()
{
StartDate = new DateTime(iyear, imonth, iday), //new DateTime(2015, 8, 06), //hl.HolidayDate ?? default(DateTime),
EndDate = new DateTime(iyear, imonth, iday + 1),
// Day = DayOfWeek.Friday,
CssClass = "red_section",
HTML = "hos",
SpanType = DHXTimeSpan.Type.BlockEvents
});
}
scheduler.BeforeInit.Add("schedulerClient.init()");
return View(scheduler);
}

How to get Rates from UPS Rate API?

I am using nopcommerce 3.5. I have added plugin of UPS of TransitInTime and Rate API. I want to get rates by calling UPS Rate API. I want all Rates in dropdown on page load.
So for the first I am using test application using webservices of RateWebReference and in which I get only one Rate but I want Rates for all shipping option.
Here is my code of RateWSClient.cs
RateService rate = new RateService();
RateRequest rateRequest = new RateRequest();
UPSSecurity upss = new UPSSecurity();
UPSSecurityServiceAccessToken upssSvcAccessToken = new UPSSecurityServiceAccessToken();
upssSvcAccessToken.AccessLicenseNumber = "CC....";
upss.ServiceAccessToken = upssSvcAccessToken;
UPSSecurityUsernameToken upssUsrNameToken = new UPSSecurityUsernameToken();
upssUsrNameToken.Username = "gi..";
upssUsrNameToken.Password = "Ch..";
upss.UsernameToken = upssUsrNameToken;
rate.UPSSecurityValue = upss;
RequestType request = new RequestType();
String[] requestOption = { "Rate" };
request.RequestOption = requestOption;
rateRequest.Request = request;
ShipmentType shipment = new ShipmentType();
ShipperType shipper = new ShipperType();
shipper.ShipperNumber = "A65V88";
RateWSSample.RateWebReference1.AddressType shipperAddress = new RateWSSample.RateWebReference1.AddressType();
String[] addressLine = { "", "", "" };
shipperAddress.AddressLine = addressLine;
shipperAddress.City = "";
shipperAddress.PostalCode = "30076";
shipperAddress.StateProvinceCode = "GA";
shipperAddress.CountryCode = "US";
shipperAddress.AddressLine = addressLine;
shipper.Address = shipperAddress;
shipment.Shipper = shipper;
ShipFromType shipFrom = new ShipFromType();
RateWSSample.RateWebReference1.AddressType shipFromAddress = new RateWSSample.RateWebReference1.AddressType();
shipFromAddress.AddressLine = addressLine;
shipFromAddress.City = "";
shipFromAddress.PostalCode = "30076";
shipFromAddress.StateProvinceCode = "GA";
shipFromAddress.CountryCode = "US";
shipFrom.Address = shipFromAddress;
shipment.ShipFrom = shipFrom;
ShipToType shipTo = new ShipToType();
ShipToAddressType shipToAddress = new ShipToAddressType();
String[] addressLine1 = { "", "", "" };
shipToAddress.AddressLine = addressLine1;
shipToAddress.City = "";
shipToAddress.PostalCode = "92262";
shipToAddress.StateProvinceCode = "";
shipToAddress.CountryCode = "US";
shipTo.Address = shipToAddress;
shipment.ShipTo = shipTo;
CodeDescriptionType service = new CodeDescriptionType();
//Below code uses dummy date for reference. Please udpate as required.
service.Code = "02";
shipment.Service = service;
PackageType package = new PackageType();
PackageWeightType packageWeight = new PackageWeightType();
packageWeight.Weight = "125";
CodeDescriptionType uom = new CodeDescriptionType();
uom.Code = "LBS";
uom.Description = "pounds";
packageWeight.UnitOfMeasurement = uom;
package.PackageWeight = packageWeight;
CodeDescriptionType packType = new CodeDescriptionType();
packType.Code = "02";
package.PackagingType = packType;
PackageType[] pkgArray = { package };
shipment.Package = pkgArray;
//Shipping Rate Chart
// ShipmentRatingOptionsType SRO = new ShipmentRatingOptionsType();
//SRO.RateChartIndicator = "";
//shipment.ShipmentRatingOptions= SRO;
//rateRequest.Shipment = shipment;
ShipmentRatingOptionsType SRO = new ShipmentRatingOptionsType();
SRO.NegotiatedRatesIndicator = "";
shipment.ShipmentRatingOptions = SRO;
rateRequest.Shipment = shipment;
System.Net.ServicePointManager.CertificatePolicy = new TrustAllCertificatePolicy();
Console.WriteLine(rateRequest);
RateResponse rateResponse = rate.ProcessRate(rateRequest);
Console.WriteLine("The transaction was a " + rateResponse.Response.ResponseStatus.Description);
Console.WriteLine("Total Shipment Charges " + rateResponse.RatedShipment[0].TotalCharges.MonetaryValue + rateResponse.RatedShipment[0].TotalCharges.CurrencyCode);
Console.ReadKey();
I have resolved this questions. So If you face this kind of problem don't forget to use
String[] requestOption = { "Shop" };
in place of
String[] requestOption = { "Rate" };
Then you will get rates for all shipping options.

LINQ how to generate csv file section

I got the problem generating csv file based on the section. I currently using LinqToCsv dll to generate the file. How do I generate the file by section. Please help. Thanks.
Currenly I have 3 section
Header Section
Detail Section
Footer Section
Here my codes.
TTMSEntities DB = new TTMSEntities();
CsvFileDescription outputFileDescription = new CsvFileDescription();
outputFileDescription.NoSeparatorChar = false;
outputFileDescription.FirstLineHasColumnNames = true;
outputFileDescription.FileCultureName = "en-US";
List<HeaderRec> list1 = new List<HeaderRec>();
HeaderRec header = new HeaderRec();
header.RecordType = "";
header.RetailerID = "";
header.FileDate = "";
header.FileSequence = "";
header.LastTransRef = "";
list1.Add(header);
var Data = (from p in DB.TT_TNG_KFC_TRANSACTION_UPLOAD
select new DetailRec
{
RecordType = "D",
TransIDType ="AA"
});
List<FooterRec> list2 = new List<FooterRec>();
FooterRec footer = new FooterRec();
footer.RecordType = "T";
footer.TotalAmount = "100";
list2.Add(footer);
CsvContext cc = new CsvContext();
cc.Write(Data, "TestData.csv", outputFileDescription);
How to I concat the List ?