Insert multiple rows of data into the database wp8 - c#

I know how to insert data into a database one by one but I want to insert multiple pieces of data into database and I don't know how to do this.
Here is my code for a "one-time" insert of data:
Bloggers BlogerToaddData = new Blogger
{
Interest = txtIntrest.Text.ToString(),
Name = txtname.Text.ToString(),
Totalposts = Convert.ToInt32(txtPost.Text)
};
bloggerDB.bloggers.InsertOnSubmit(BlogerToaddData);
bloggerDB.SubmitChanges();
but how to insert multiple rows of data?
Bloggers BlogerToaddData = new Bloggers
{Interest = "wy",Name = "opwm",Totalposts =1},
{Interest = "wy",Name = "opwm",Totalposts =1},
{Interest = "wy",Name = "opwm",Totalposts =1},
This is not working

Well you need to create multiple objects. You can either add them one at a time to the list of pending changes:
var bloggs = bloggerDB.bloggers;
bloggers.InsertOnSubmit(new Bloggers { Interest = "wy", Name = "opwn", TotalPosts = 1 });
bloggers.InsertOnSubmit(new Bloggers { Interest = "ab", Name = "abcd", TotalPosts = 2 });
bloggers.InsertOnSubmit(new Bloggers { Interest = "cd", Name = "1234", TotalPosts = 3 });
bloggerDB.SubmitChanges();
Or use InsertAllOnSubmit:
bloggerDB.bloggers.InsertAllOnSubmit(new[] {
new Bloggers { Interest = "wy", Name = "opwn", TotalPosts = 1 },
new Bloggers { Interest = "ab", Name = "abcd", TotalPosts = 2 },
new Bloggers { Interest = "cd", Name = "1234", TotalPosts = 3 }
});
bloggerDB.SubmitChanges();

Related

Stripe - how add product on the connected account?

I try add payment method to my project where customer can buy product from other user. But i have problem because when i use it:
LineItems = new List<SessionLineItemOptions>
{
new SessionLineItemOptions
{
Price = "{{PRICE_ID}}",
Quantity = 1,
},
},
Mode = "payment",
SuccessUrl = "https://example.com/success",
CancelUrl = "https://example.com/cancel",
PaymentIntentData = new SessionPaymentIntentDataOptions
{
ApplicationFeeAmount = 123,
},
};
var requestOptions = new RequestOptions
{
StripeAccount = "{{CONNECTED_ACCOUNT_ID}}",
};
var service = new SessionService();
Session session = service.Create(options, requestOptions);
PRICE_ID can't be price's on my main stripe account and i must create product and price on the connected account.
In the case of creating a product on the main account, I do it like this:
var options = new ProductCreateOptions
{
Id = ProductId.ToString(),
Name = "Product_name",
DefaultPriceData = new ProductDefaultPriceDataOptions
{
UnitAmount = price,
Currency = "pln"
},
Expand = new List<string> { "default_price" },
};
_productService.Create(options);
How create product and price on the connected account with my api?
The Stripe API has a Stripe-Account header where you can pass in the ID of one of your connected accounts to make the call as that account. In C# that would look like this:
{
Id = ProductId.ToString(),
Name = "Product_name",
DefaultPriceData = new ProductDefaultPriceDataOptions
{
UnitAmount = price,
Currency = "pln"
},
Expand = new List<string> { "default_price" },
StripeAccount = "acct_123456789",
};
_productService.Create(options);

How can I store multiple dynamic products in stripe checkout webforms (ASP.NET C#) I tried a lot but static it's worked but dynamic not?

here is the code:-
static I used its worked fine.. how can I store product dynamically in using asp.net c#
LineItems = new List<SessionLineItemOptions>
{
for (int i = 0; i < dtOrder.Rows.Count; i++){
new SessionLineItemOptions
{
Name=dtOrder.Rows[i]["ProductName"].toString(),
Currency="cad",
Amount =Convert.toInt64(dtOrder>Rows[i]["Price"])*100,
Quantity = 1,
},
}
},
Extending the snippet shown in the API reference here, we can replace Price = 'price_123' with PriceData (API ref) like so:
var options = new SessionCreateOptions
{
SuccessUrl = "https://example.com/success",
CancelUrl = "https://example.com/cancel",
PaymentMethodTypes = new List<string>
{
"card",
},
LineItems = new List<SessionLineItemOptions>
{
new SessionLineItemOptions
{
PriceData = new SessionLineItemPriceDataOptions
{
Currency = "usd",
UnitAmount = 50000,
ProductData = new SessionLineItemPriceDataProductDataOptions
{
Name = "some product name",
}
},
Quantity = 2,
},
},
Mode = "payment",
};
var service = new SessionService();
service.Create(options);
You can find all the type definitions in the source code.
I integrated Mulitple Account Payment of stripe and fixed the issue like this
and its working for me now , you can also use simple checkout method like this fetching dynamically product from db
List lineItemsOptions = new List();
string cmdText = "select * from tableorder where sessionid='"+ sessionid + "'";
DataSet ds = dbm.getDs(cmdText);
foreach (DataRow row in ds.Tables[0].Rows)
{
var currentLineItem = new SessionLineItemOptions
{
Name = row["ProductName"].ToString(),
Amount = 100,//Convert.ToInt32( row["variationPrice"].ToString()),
Currency = "usd",
Quantity = Convert.ToInt32(row["Quantity"].ToString()),
};
lineItemsOptions.Add(currentLineItem);
}
StripeConfiguration.ApiKey = ".......................................";
var options = new SessionCreateOptions();
options = new SessionCreateOptions
{
PaymentMethodTypes = new List<string>
{
"card",
},
LineItems = lineItemsOptions,
PaymentIntentData = new SessionPaymentIntentDataOptions
{
ApplicationFeeAmount = 1,
},
Mode = "payment",
SuccessUrl = "https://www.......com/success.aspx",
CancelUrl = "https://example.com/cancel",
};
var requestOptions = new RequestOptions
{
StripeAccount = ".............",
};
var service = new SessionService();
Session session = service.Create(options, requestOptions);

C# Add lists to Oracle user defined type

I have two Oracle user defined type object
T_CODE_LIST_TABLE
T_CODE_LIST
I can add new T_CODE_LIST to T_CODE_LIST_TABLE
As below
T_CODE_LIST_TABLE t_code_list_tab = new T_CODE_LIST_TABLE();
t_code_list_tab.Value = new T_CODE_LIST[] {
new T_CODE_LIST() { TEAMID = "1", GROUPTYPE = "1", GROUPLOGIC = "1", GROUPVALUE = val1.ToString()},
new T_CODE_LIST() { TEAMID = "2", GROUPTYPE = "2", GROUPLOGIC = "2", GROUPVALUE = val2.ToString()},
new T_CODE_LIST() { TEAMID = "3", GROUPTYPE = "3", GROUPLOGIC = "3”,GROUPVALUE = val3.ToString()}
};
But I want it to be able to add as many T_CODE_LIST() as a user needs during run time like below, how can I do that?
t_code_list_tab.Value = new T_CODE_LIST[] {
new T_CODE_LIST() { TEAMID = "1", GROUPTYPE = "1", GROUPLOGIC = "1", GROUPVALUE = val1.ToString()},
new T_CODE_LIST() { TEAMID = "2", GROUPTYPE = "2", GROUPLOGIC = "2", GROUPVALUE = val2.ToString()},
new T_CODE_LIST() { TEAMID = "3", GROUPTYPE = "3", GROUPLOGIC = "3”,GROUPVALUE = val3.ToString()},
.
.
.
N times
.
.
.
};
You can solve this by many approaches. Adding value in array dynamically is not straightforward.
One of the better solution can be create list then add objects. Whenever needed convert it to array using .ToArray() function.
You code can be as below
List<T_CODE_LIST> tcodes =new List<T_CODE_LIST>();
tcodes.Add(new T_CODE_LIST() { TEAMID = "1", GROUPTYPE = "1", GROUPLOGIC = "1", GROUPVALUE = val1.ToString()});
.
.
....N times ...whenever needed
T_CODE_LIST_TABLE t_code_list_tab = new T_CODE_LIST_TABLE();
t_code_list_tab.Value = tcodes.ToArray();
Another solution to this is resize array size whenever needed, depending on items to be added in array.
You can check this example of MSDN Resize Array
I hope this helps.

delete multiple entities in disconnected mode

I am working on an application (EF6 Code First approach) that is interacting with a entity/table FloorPlan and has 10 records. I want to delete first 6 records as those are obsolete with new business requirements. Here's how the table currently looks:
To delete this in the Code First approach, I tried following code in disconnected state:
using (var newdbContext = new HomItUpContext())
{
var floorPlansOld = new List<FloorPlan>
{
new FloorPlan { Name = "Unitech Uniworld Gardens 2", MainImageUrl = "//cdn.homitup.com/resources/featured-ideas/floor-plans/unitech_uniworld_gardens_2/profile.jpg", IsActive = true, FloorPlanIdeas = new List<FloorPlanIdea>() },
new FloorPlan { Name = "Vatika Seven Lamps", MainImageUrl = "//cdn.homitup.com/resources/featured-ideas/floor-plans/vatika_seven_lamps/profile.jpg", IsActive = true, FloorPlanIdeas = new List<FloorPlanIdea>() },
new FloorPlan { Name = "Bestech Park View Spa", MainImageUrl = "//cdn.homitup.com/resources/featured-ideas/floor-plans/bestech_park_view_spa/profile.jpg", IsActive = true, FloorPlanIdeas = new List<FloorPlanIdea>() },
new FloorPlan { Name = "Imperia Esfera", MainImageUrl = "//cdn.homitup.com/resources/featured-ideas/floor-plans/imperia_esfera/profile.jpg", IsActive = true, FloorPlanIdeas = new List<FloorPlanIdea>() },
new FloorPlan { Name = "Raheja Vedas", MainImageUrl = "//cdn.homitup.com/resources/featured-ideas/floor-plans/raheja_vedas/profile.jpg", IsActive = true, FloorPlanIdeas = new List<FloorPlanIdea>() },
new FloorPlan { Name = "Tulip Violet Grandeur", MainImageUrl = "//cdn.homitup.com/resources/featured-ideas/floor-plans/tulip_violet_grandeur/profile.jpg", IsActive = true, FloorPlanIdeas = new List<FloorPlanIdea>() }
};
floorPlansOld.ForEach(a => newdbContext.FloorPlan.Remove(a));
floorPlansOld.ForEach(a => newdbContext.Entry(a).State = System.Data.Entity.EntityState.Deleted);
newdbContext.SaveChanges();
};
When I run update-database command via package manager console, I get following error:
The object cannot be deleted because it was not found in the ObjectStateManager.
I have also tried without changing the state of the entities but to no avail. I only want to do it in disconnected mode. Can you guys throws some pointers around this problem?
If you want to delete those records the only you need to do is create your entity instances with their existing Ids.
using (var newdbContext = new HomItUpContext())
{
var floorPlansOld = new List<FloorPlan>
{ //Put here the record's Ids you want to delete
new FloorPlan { Id=1 },
new FloorPlan { Id=2 },
new FloorPlan { Id=3 },
new FloorPlan { Id=4 },
new FloorPlan { Id=5 },
new FloorPlan { Id=6 }
};
newdbContext.RemoveRange(floorPlansOld);// You can use RemoveRange method instead a foreach to call Remove method.
newdbContext.SaveChanges();
};
Update
Well, in that case I suggest you make a query first seeking all the entities you want to delete by their names, and after that you can delete them using the RemoveRange method:
var names=new List<string>(){ "Unitech Uniworld Gardens 2", "Vatika Seven Lamps",...};
var entitiesToDelete=newdbContext.FloorPlan.Where(fp=>names.Contains(fp.Name));
newdbContext.RemoveRange(entitiesToDelete);
newdbContext.SaveChanges();
You are removing object from newdbContext.FloorPlan, buy you take them from floorPlansOld.
It looks completely wrong to me.
Try this
var a = newdbContext.FloorPlan.First();
newdbContext.FloorPlan.Remove(a);

Create a SuiteTalk transaction search that gets all sales order with a certain status

In NetSuite SuiteTalk (Web Services), I am trying to create a search that will find all sales orders that have the status "Pending Approval". I think I have everything structured correctly and I think the problem is the status is not actually called "Pending Approval, but something else. I have tried other variants like "_pendingApproval", but my search never returns any results. If I comment out the status part, the search works correctly and returns every sales order for this particular customer.
Any thoughts on what the problem is?
C#
TransactionSearchBasic tsb = new TransactionSearchBasic() {
mainLine = new SearchBooleanField() {
searchValue = true,
searchValueSpecified = true,
},
type = new SearchEnumMultiSelectField() {
#operator = SearchEnumMultiSelectFieldOperator.anyOf,
operatorSpecified = true,
searchValue = new string[] { "_salesOrder" },
},
entity = new SearchMultiSelectField() {
#operator = SearchMultiSelectFieldOperator.anyOf,
operatorSpecified = true,
searchValue = new RecordRef[] {
new RecordRef() {
type = RecordType.customer,
internalId = "231"
}
}
},
status = new SearchEnumMultiSelectField() {
#operator = SearchEnumMultiSelectFieldOperator.anyOf,
operatorSpecified = true,
searchValue = new string[] {
"Pending Approval",
"_pendingApproval",
"pendingApproval",
"pendingapproval",
"pending approval",
"0"
}
}
};
SearchResult results = _nss.search(tsb);
It looks like the type of transaction needs to be prefixed to the status. For example:
status = new SearchEnumMultiSelectField() {
#operator = SearchEnumMultiSelectFieldOperator.anyOf,
operatorSpecified = true,
searchValue = new string[] {
"_salesOrderPendingApproval"
}
}
Try using :
"pendingApproval"
instead of
"_pendingApproval" & "Pending Approval"

Categories

Resources