I am sending a string to my controller containing seat numbers: A1, A2 etc. And a string containing an ID.
I want to select each db row from the seats table where the column: seatnum equals each of the seat numbers in the seatss string and update a related column called status from 0 to the ID string.
I have used the below code to select the row where the seatnum = seatss string and return the matching row as a json object. This works if there is one seat number in the string but not if there are multiple. I'm assuming I would need to implement an array of some sort but have no idea how to do so. The seat numbers are posted as this: A1, A2, A3. So I'd like to separated/explode them on the , and then match them to the database rows.
//
// POST: /seats/
public JsonResult Checkout(string seatss, string ID)
{
var seats = from b in db.seats
select b;
seats = seats.Where(b => b.seatnum.Equals(seatss)); // Selects the db row where .seatnum = string seatss.
//Update seatnum to the value of seatss
return Json(seats, JsonRequestBehavior.AllowGet); // returns the selected seats as a json object.
}
So in summary I need a way to match each seat number in the string to the corresponding seatnum in the database and update the status to the integer contained in the ID string.
My database table(seats) has two columns called seatnum and status. The seatnum column contains rows: A1 etc and the status is 0 by default.
You could either change the way that you are passing your seat numbers, so instead of a string parameter named seats your action could expect an array or a generic list of string values, or you could just cast your current string parameter to an array and then modify you LINQ query to use a contains function. The sample provided is of the latter implementation since the former is a little more involved, of course this is untested:
public JsonResult Checkout(string seatss, string ID)
{
var seats = from b in db.seats
select b;
seats = seats.Where(b => seatss.Contains(b.seatnum));
foreach(var seat in seats)
{
... Perform status update on seat
}
return Json(seats, JsonRequestBehavior.AllowGet); // returns the selected seats as a json object.
}
Related
I have an array of thousands of rows with an element of "Order Number." I want to filter that array where that Order Number does not exist in a Dataverse table column.
I've tried a number of things, always starting with a List Rows action on the Dataverse table. From there, I feel like the thing to do is to do a Select action where I map OrderNumber to OrderNumber from the List Rows. I believe that creates an array of the order numbers.
I'm not sure if I'm on the right track, but how can I efficiently filter the original array where the Order Number does not exist in the Dataverse table?
Edit: Here's a sample item in the output of my current filter array:
This might help if you are able to use javascript.
// where output equals your data
const records = JSON.parse( output );
// we will create new array of filtered data
let newData = [];
// loop array searching for matching criteria
for (let n = 0; n < records.length; n++; ) {
// replace 123456 with search criteria
if(records[n]["Order Number"] != "123456") {
newData.push(records[n]);
}
// once you reach the end
if(n == records.length-1) {
// stringify object (may not be required)
let fileteredData = JSON.stringify(newData);
/* open filteredData with program */
}
}
Need to store the text field data and store and then sumI am creating multiples sub category Just like to-do on button click it creates a field where user can put his/her input.
The Input is product Price Now I wanna store this all data in similar list As it's subcategories for some product and wanna display their total sum along side all values.
Consider using fold function
arrayName.fold(0, (result, eachItem) => result+eachItem)
it will add current item to result(which is 0 initially) and return it
eg: given your data of List< String > items
here is your a function that will parse the items to int and return the sum
int getTotal()=> items.fold(0,(total, item) {
int? price = int.tryParse(item);
if(price!=null) return total+price;
else return total;
});
Although according to your existing code you have on bug, which is the price is not being updated form the text field
Therefore you must add onChanged to your text field
onChanged:(value) => items[index]=value,
Then you can display it like this
Text("Total price: ${getTotal()}"),
According to the Dapper documentation, you can get a dynamic list back from dapper using below code :
var rows = connection.Query("select 1 A, 2 B union all select 3, 4");
((int)rows[0].A)
.IsEqualTo(1);
((int)rows[0].B)
.IsEqualTo(2);
((int)rows[1].A)
.IsEqualTo(3);
((int)rows[1].B)
.IsEqualTo(4);
What is however the use of dynamic if you have to know the field names and datatypes of the fields.
If I have :
var result = Db.Query("Select * from Data.Tables");
I want to be able to do the following :
Get a list of the field names and data types returned.
Iterate over it using the field names and get back data in the following ways :
result.Fields
["Id", "Description"]
result[0].values
[1, "This is the description"]
This would allow me to get
result[0].["Id"].Value
which will give results 1 and be of type e.g. Int 32
result[0].["Id"].Type --- what datattype is the value returned
result[0].["Description"]
which will give results "This is the description" and will be of type string.
I see there is a results[0].table which has a dapperrow object with an array of the fieldnames and there is also a result.values which is an object[2] with the values in it, but it can not be accessed. If I add a watch to the drilled down column name, I can get the id. The automatically created watch is :
(new System.Collections.Generic.Mscorlib_CollectionDebugView<Dapper.SqlMapper.DapperRow>(result as System.Collections.Generic.List<Dapper.SqlMapper.DapperRow>)).Items[0].table.FieldNames[0] "Id" string
So I should be able to get result[0].Items[0].table.FieldNames[0] and get "Id" back.
You can cast each row to an IDictionary<string, object>, which should provide access to the names and the values. We don't explicitly track the types currently - we simply don't have a need to. If that isn't enough, consider using the dapper method that returns an IDataReader - this will provide access to the raw data, while still allowing convenient call / parameterization syntax.
For example:
var rows = ...
foreach(IDictionary<string, object> row in rows) {
Console.WriteLine("row:");
foreach(var pair in row) {
Console.WriteLine(" {0} = {1}", pair.Key, pair.Value);
}
}
I have a Map of type Sobject as a key and Integer as a value. The Sobject has field of type Text, other field of type date and another field of type Number(16,2). When I put data into the map and then debug it, the map returns data in a sorted way. The map sorts it by the Number field present in the Key i.e the number data field of the object. Can I get the map sorted by the date field of the object which is its key? Below is the rough structure of my Map and the key object fields.
Map<Effort_Allocation__c, Double> cellContent;
Effort_Allocation__c.Allocated_Effort_Hours__c; //The Number field by which the map gets sorted
Effort_Allocation__c.Assignment_Date__c; // The date field by which I want the map to get sorted
It's a bad idea to use an object as a key for a map. You should, instead, use the object's ID as the key. The reasons for this are discussed in detail here. Short version - the object's values may change which changes the object's hash value and wrecks your map.
Although maps cannot be sorted directly, lists can be sorted, so they can be used to access map elements in sorted order. You'll need a wrapper class for your object that implements the "Comparable" interface. There's an example of that here. Note that the example sorts by date.
The class is declared with "comparable"
global class AccountHistoryWrapper implements Comparable{
and has the following CompareTo method
global Integer compareTo(Object compareTo) {
// Cast argument to AccountHistoryWrapper
AccountHistoryWrapper aHW = (AccountHistoryWrapper)compareTo;
// The return value of 0 indicates that both elements are equal.
Integer returnValue = 0;
if ( aHW.account.CreatedDate > aHW.account.CreatedDate) {
// Set return value to a positive value.
returnValue = 1;
} else if ( aHW.account.CreatedDate < aHW.account.CreatedDate) {
// Set return value to a negative value.
returnValue = -1;
}
return returnValue;
}
I have an array, lets call it _persons.
I am populating this array with Value Objects, lets call this object PersonVO
Each PersonVO has a name and a score property.
What I am trying to do is search the array &
//PSEUDO CODE
1 Find any VO's with same name (there should only be at most 2)
2 Do a comparison of the score propertys
3 Keep ONLY the VO with the higher score, and delete remove the other from the _persons array.
I'm having trouble with the code implementation. Any AS3 wizards able to help?
You'd better use a Dictionary for this task, since you have a designated unique property to query. A dictionary approach is viable in case you only have one key property, in your case name, and you need to have only one object to have this property at any given time. An example:
var highscores:Dictionary;
// load it somehow
function addHighscore(name:String,score:Number):Boolean {
// returns true if this score is bigger than what was stored, aka personal best
var prevScore:Number=highscores[name];
if (isNaN(prevScore) || (prevScore<score)) {
// either no score, or less score - write a new value
highscores[name]=score;
return true;
}
// else don't write, the new score is less than what's stored
return false;
}
The dictionary in this example uses passed strings as name property, that is the "primary key" here, thus all records should have unique name part, passed into the function. The score is the value part of stored record. You can store more than one property in the dictionary as value, you'll need to wrap then into an Object in this case.
you want to loop though the array and check if there are any two people with the same name.
I have another solution that may help, if not please do say.
childrenOnStage = this.numChildren;
var aPerson:array = new array;
for (var c:int = 0; c < childrenOnStage; c++)
{
if (getChildAt(c).name == "person1")
{
aPerson:array =(getChildAt(c);
}
}
Then trace the array,