How can I give if else if statement inside a AsEnumerable select - asp.net-core

I am trying to give a conditional statement inside AsEnumerable select list. I have the following AsEnumerable select . Here I am trying to give the condition If IsRoleClocking = true then IsClockingEnabled should be true else the value of IsClockingEnabled must be depends the value of (Convert.ToInt32(row["IsClockingEnabled"]) . Please help to amend the existing code to consider IsRoleClocking also.
bool IsRoleClocking = true;
attendanceEntry.attendanceLogList = dt.AsEnumerable()
.Select(row =>
{
var p = new AttendanceLogModel
{
IsFlexibleDayOff = (Convert.ToInt32(row["IsFlexibleDayOff"]) == 1) ? true : false,
IsClockingEnabled = (Convert.ToInt32(row["IsClockingEnabled"]) == 1 ) ? true : false,
IsProtected = (Convert.ToInt32(row["IsProtected"]) == 1) ? true : false,
};
return p;
})
.ToList<AttendanceLogModel>();
return attendanceEntry;
}

I hope I got your question correctly :)
Does this help?
IsClockingEnabled = IsRoleClocking ? true :
(Convert.ToInt32(row["IsClockingEnabled"]) == 1 ) ? true : false;
update
Just noticed, it can be done much simpler:
IsClockingEnabled = IsRoleClocking || Convert.ToInt32(row["IsClockingEnabled"]) == 1;

Related

Vue.js - Filter multiple fields

I'm trying to filter a on a nested array inside an array of objects in an Vue.js. Here's a snippet of the component code:
filteredProducts: function() {
if (!this.filters.appointments.length && !this.filters.powers.length && !this.filters.materials.length && !this.filters.lamps.length) return this.products;
return this.products.filter(product => {
return product.filter(p => {
let filteredAppointments = this.filters.appointments ? _.difference(this.filters.appointments, p.appointment.split(',')).length === 0 : true,
filteredPowers = this.filters.powers ? this.filters.powers.includes(p.total_power_lamps) : true,
filteredMaterials = this.filters.materials ? this.filters.materials.includes(p.material) : true,
filteredLamps = this.filters.lamps ? this.filters.lamps.includes(p.count_lamps) : true,
filteredPrice = p.price >= this.rangePrice[0] && p.price <= this.rangePrice[1];
return filteredAppointments && filteredPowers && filteredMaterials && filteredLamps && filteredPrice;
}).length > 0;
});
}
How do I display only the filters that are used ? For example, if only one filter is selected, then no other filters are needed. Also, if several are selected, it should filter by both.
I think this is what you're looking for
filteredProducts () {
let results = this.products
if(this.filters.appointments.length) {
results = results.filter(logicFilterHere)
}
if(this.filters.powers.length) {
results = results.filter(logicFilterHere)
}
if(this.filters.materials.length) {
results = results.filter(logicFilterHere)
}
return results
}

How do you fix Fatal error: index out of range? Swift

I know I have to return some sort of value in my code so it does not keep crashing with this thread error, but I can't figure it out. Please help! Here is the code- `
#IBAction func decideBttn(_ sender: Any) {
// if there is data in more than one Label randomly pick 1 out of 2
if valueLbl1.text?.isEmpty == false && valueLbl2.text?.isEmpty == false
{
var topics = [valueLbl1.text!, valueLbl2.text!]
pickTopic = Int(arc4random_uniform(UInt32(topics.count)))
topics.remove(at: pickTopic)
resultLbl.text = "\(topics[pickTopic])" //Where fatal error occurs
valueLbl1.text = ""
valueLbl2.text = ""
valueLbl3.text = ""
return
}
// if all 3 Labels are used button will randomly pick 1 out of 3
else if valueLbl1.text?.isEmpty == false && valueLbl2.text?.isEmpty == false && valueLbl3.text?.isEmpty == false
{
var topics = [ valueLbl1.text!, valueLbl2.text!, valueLbl3.text!]
pickTopic = Int(arc4random_uniform(UInt32(topics.count)))
topics.remove(at: pickTopic)
resultLbl.text = "\(topics[pickTopic])"
// resetting variable value
valueLbl1.text = ""
valueLbl2.text = ""
valueLbl3.text = ""
return
}

Yadcf - Server side multi select

I used the function yadcf multi_select
When I make my search for two words, the function puts me a pipe between. I do not know how to remove it for that he understands the two words separately.
http://www.hostingpics.net/viewer.php?id=710742Capture.jpg
I found that the pipe would begin with this function :
function doFilterMultiSelect(arg, table_selector_jq_friendly, column_number, filter_match_mode) {
$.fn.dataTableExt.iApiIndex = oTablesIndex[table_selector_jq_friendly];
var oTable = oTables[table_selector_jq_friendly],
selected_values = $(arg).val(),
selected_values_trimmed = [],
i,
stringForSearch,
column_number_filter,
settingsDt = getSettingsObjFromTable(oTable);
column_number_filter = calcColumnNumberFilter(settingsDt, column_number, table_selector_jq_friendly);
$(document).data("#yadcf-filter-" + table_selector_jq_friendly + "-" + column_number + "_val", selected_values);
if (selected_values !== null) {
for (i = selected_values.length - 1; i >= 0; i--) {
if (selected_values[i] === "-1") {
selected_values.splice(i, 1);
break;
}
}
for (i = 0; i < selected_values.length; i++) {
selected_values_trimmed.push($.trim(selected_values[i]));
}
if (selected_values_trimmed.length !== 0) {
stringForSearch = selected_values_trimmed.join('narutouzomaki');
stringForSearch = stringForSearch.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1");
stringForSearch = stringForSearch.split('narutouzomaki').join('|');
if (filter_match_mode === "contains") {
oTable.fnFilter(stringForSearch, column_number_filter, true, false, true);
} else if (filter_match_mode === "exact") {
oTable.fnFilter("^(" + stringForSearch + ")$", column_number_filter, true, false, true);
} else if (filter_match_mode === "startsWith") {
oTable.fnFilter("^(" + stringForSearch + ")", column_number_filter, true, false, true);
} else if (filter_match_mode === "regex") {
oTable.fnFilter(stringForSearch, column_number_filter, true, false, true);
}
} else {
oTable.fnFilter("", column_number_filter);
}
} else {
oTable.fnFilter("", column_number_filter);
}
resetIApiIndex();
}
I can not seem to solve the problem to operate the multi_select.
Thank you for the help
Since you are using a multi select filter on some column yadcf sends strings with | (OR) to your server.
On your server side you have to do the split of the string into array/list of string and construct a proper sql query.
Split in Java
Split in PHP(see code sample in bottom
p.s I'm the author of yadcf

Add restriction based on method parameter

I have a method
List<MyType> DoQuery(bool FilterWeek) {
var result = session.QueryOver<MyType>()
.Where (r => r.isValid == 1
&& r.value1 == 2
&& r.name == "XYZ"
&& [...etc, more columns are used...]
)
// how do I go on from this point?
}
if the FilterWeek parameter is true, I want to add an extra "&& r.xyz == 1" clause to the Where criteria. If FilterWeek is false, the query is done.
How do I do that?
if (FilterWeek)
result = result.Where(r => r.xyz ==1);
//...whenever you're done, execute the query using List() or SingleOrDefault()
this:
List<MyType> DoQuery(bool FilterWeek) {
var result = session.QueryOver<MyType>()
.Where (r => r.isValid == 1
&& r.value1 == 2
&& r.name == "XYZ"
&& [...etc, more columns are used...]
);
if(FilterWeek)
result.Where(x => x.Whatever == 1)
//the query won't get executed until here
result.List();
}

CodeIgniter - Changing normal SQL into CI's own language

Can someone show me how to change the following SQL into CI's active stuff.
$query = $this->db->query('UPDATE pollanswers SET pollAnswerPoints = pollAnswerPoints + 1 WHERE pollAnswerID = '.$pollanswerid.'');
return true;
Also, how would i add an if statement to that to see if it completed properly return true, if not return false?
Cheers,
try this
$this->db->set('pollAnswerPoints', 'pollAnswerPoints + 1', FALSE);
$this->db->where('pollAnswerID', $pollanswerid);
$this->db->update('pollanswers');
Edit:
if($this->db->affected_rows() > 0)
{
return true;
} else
{
return false;
}